最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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 ?

发布评论

评论列表(0)

  1. 暂无评论