小编Hin*_*rik的帖子

sqint of uint64_t vs. int64_t

我注意到计算平方根的整数部分uint64_t要复杂得多int64_t.请问有人对此有解释吗?为什么处理一个额外的位似乎要困难得多?

下列:

int64_t sqrt_int(int64_t a) {
    return sqrt(a);
}
Run Code Online (Sandbox Code Playgroud)

与铛5.0和编译-mfpmath=sse -msse3 -Wall -O3

sqrt_int(long):                           # @sqrt_int(long)
        cvtsi2sd        xmm0, rdi
        sqrtsd  xmm0, xmm0
        cvttsd2si       rax, xmm0
        ret
Run Code Online (Sandbox Code Playgroud)

但是以下内容:

uint64_t sqrt_int(uint64_t a) {
    return sqrt(a);
}
Run Code Online (Sandbox Code Playgroud)

编译为:

.LCPI0_0:
        .long   1127219200              # 0x43300000
        .long   1160773632              # 0x45300000
        .long   0                       # 0x0
        .long   0                       # 0x0
.LCPI0_1:
        .quad   4841369599423283200     # double 4503599627370496
        .quad   4985484787499139072     # double 1.9342813113834067E+25
.LCPI0_2:
        .quad   4890909195324358656     # double 9.2233720368547758E+18
sqrt_int(unsigned long):                           # @sqrt_int(unsigned long) …
Run Code Online (Sandbox Code Playgroud)

x86 assembly sse compilation square-root

8
推荐指数
1
解决办法
373
查看次数

标签 统计

assembly ×1

compilation ×1

square-root ×1

sse ×1

x86 ×1