assembly - faster trunc() function for MSVC - Stack Overflow

MSVC's trunc() function is really slow. I've implemented it somewhat simpler and got a speedu

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 ?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744864121a4597877.html

相关推荐

  • assembly - faster trunc() function for MSVC - Stack Overflow

    MSVC's trunc() function is really slow. I've implemented it somewhat simpler and got a speedu

    1天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信