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
版权声明:本文标题:assembly - faster trunc() function for MSVC - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744864120a2629245.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论