为什么AsDouble1
比AsDouble0
更加简单明了?
// AsDouble0(unsigned long): # @AsDouble0(unsigned long)
// movq xmm1, rdi
// punpckldq xmm1, xmmword ptr [rip + .LCPI0_0] # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
// subpd xmm1, xmmword ptr [rip + .LCPI0_1]
// movapd xmm0, xmm1
// unpckhpd xmm0, xmm1 # xmm0 = xmm0[1],xmm1[1]
// addsd xmm0, xmm1
// addsd xmm0, xmm0
// ret
double AsDouble0(uint64_t x) { return x * 2.0; }
// AsDouble1(unsigned long): # @AsDouble1(unsigned long)
// shr rdi
// cvtsi2sd xmm0, rdi
// addsd xmm0, xmm0
// ret
double AsDouble1(uint64_t x) { return (x >> 1) * 2.0; }
可以在此处获取代码:https://godbolt.org/z/dKc6Pe6M1
main()
函数。此外,与此有些相关的是是否存在x87 FILD和SSE CVTSI2SD指令的无符号等效项?,但这是相反的方向。如何使用SSE / AVX高效执行double / int64转换?涵盖了打包转换。 - Peter Cordes(uint64_t)float
代码的专题。 - Peter Cordes