<HTML>
<style> BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }</style>Hi everyone,<br>
<br>
So I'm looking to improve some of the mathematical routines. However, not all of them are internal functions and are stored in the Math unit.. Some of them are written in assembly language but use the old floating-point stack, or use a slow hack when there's a good alternative available in SSE 4.1, for example, and I would like to see about rewriting some of these functions for x86_64. However, while I can safely assume the presence of SSE2 on this architecture, what's the best way to detect if "-iCOREAVX" etc are specified? Also, if "-iCOREAVX", does it automatically set "-fAVX" as well? I rather make sure I'm not making incorrect assumptions before I start writing assembly language routines.<br>
<br>
<div>As an example of a function that can benefit from a speed-up under x86_64... the floor() and floor64() functions:</div><div><br>
</div><div>function floor64(x: float): Int64;<br>
begin<br>
Result:=Trunc(x)-ord(Frac(x)<0);<br>
end;<br>
</div><div><br>
</div><div>For time-critical code, this is not ideal because, besides being a function itself, it calls Trunc, Frac, has a subtraction, and another implicit subtraction and assignment due to the condition. Under SSE4.1, this could be optimised to something like the following:<br>
<br>
{$ASMMODE ATT}<br>
<div>function floor64(x: float): Int64; assembler; nostackframe;<br>
asm<br>
roundsd %xmm0, %xmm0, $0b101 { Round towards negative infinity }<br>
cvttsd2si %xmm0, %rax { Convert to integer... equivalent to Trunc() }<br>
end;<br>
</div></div><div><br>
</div>And similarly with AVX. Even if we're stuck with just SSE2, assembler improvements can be made over the Pascal code just by removing the call to Trunc and replacing it with its single assembler command: "cvttsd2si %xmm0,%rax".<br>
<br>
Gareth aka.Kit<br>
</HTML>