[fpc-devel] Broken frac functionin FPC3.1.1 / Windows x86_64

Sven Barth pascaldragon at googlemail.com
Wed May 2 07:55:52 CEST 2018


J. Gareth Moreton <gareth at moreton-family.com> schrieb am Di., 1. Mai 2018,
23:39:

> 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.
>
> ****
>
> function fpc_frac_real(d: ValReal): ValReal; compilerproc; assembler;
> nostackframe;
>   asm
>     movq      %xmm0,  %rax
>     movapd    %xmm0,  %xmm4
>     shr       $48,    %rax
>     and       $0x7ff0,%ax
>     cmp       $0x4330,%ax
>     jge       .L0
>     cvttsd2si %xmm0,  %rax
>     cvtsi2sd  %rax,   %xmm4
> .L0:
>     subsd     %xmm4,  %xmm0
>   end;
>
> ****
>
> 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.
>

Thank you for the work so far. Does it also work correctly when exceptions
are disabled?

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180502/caef16b9/attachment.html>


More information about the fpc-devel mailing list