<div dir="auto"><div><div class="gmail_quote"><div dir="ltr">J. Gareth Moreton <<a href="mailto:gareth@moreton-family.com">gareth@moreton-family.com</a>> schrieb am Di., 1. Mai 2018, 23:39:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It turns out I did over-engineer the solution somewhat - this version is far more efficient, honours NaNs and triggers SIGFPE if infinity is passed in (subsd triggers it), hence there are no regressions.<br>
<br>
****<br>
<br>
function fpc_frac_real(d: ValReal): ValReal; compilerproc; assembler; nostackframe;<br>
asm<br>
movq %xmm0, %rax<br>
movapd %xmm0, %xmm4<br>
shr $48, %rax<br>
and $0x7ff0,%ax<br>
cmp $0x4330,%ax<br>
jge .L0<br>
cvttsd2si %xmm0, %rax<br>
cvtsi2sd %rax, %xmm4<br>
.L0:<br>
subsd %xmm4, %xmm0<br>
end;<br>
<br>
****<br>
<br>
This is effectively "x - Int(x)" with some opcode reordering to take advantage of the multiple SSE ports present in a processor (hence the positioning of "movapd %xmm0,%xmm4" in between "movq %xmm0,%rax" and "shr $48,%rax") - it is generally equal in speed to my last routine and is faster when dealing with numbers that don't have fractional components. It is also only 38 bytes in size.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Thank you for the work so far. Does it also work correctly when exceptions are disabled? </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>