admin管理员组

文章数量:1404923

MSVC's trunc() function is really slow. I've implemented it somewhat simpler and got a speedup of about 100% with a routine that uses my xtrunc instead of trunc():

double xtrunc( double value )
{
    double iValue = (double)(int64_t)value;
    return (bit_cast<uint64_t>( value ) & ~(1ull << 63)) <= (0x433ull << 52) ? iValue : value;
}

But this isn't optimal since there's a conditional jump inside that. In assembly I think I could ask the CPU-flags if the integer-conversion went right. I implemented it that way (MASM) but this doesn't work:

cvttsd2si rax, xmm0
setp dl
cvtsi2sd xmm1, rax
movq rax, xmm0
movq rcx, xmm1
test dl, dl
cmovz rax, rcx
movq xmm0, rax
ret

There are no FPU conditional moves, so I emulate that with integer-CMOV. How would my idea look correctly ?

本文标签: assemblyfaster trunc() function for MSVCStack Overflow