Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Inline Delphi assembly supports SSE instructions since a while. two overloaded versions are possible: for single and double. In addition two versions are possible: input as Parameter or as pointer. This version is particularly faster than the native Round()/Trunc() methods.</p> <p>To round you have:</p> <pre><code>Function RoundSSE(Value: Single): Integer; Overload; Asm // additional PUSH/POP pointer stack added automatically CVTSS2SI EAX, Value End; Function RoundSSE(Value: Double): Integer; Overload; Asm // additional PUSH/POP pointer stack added automatically MOVQ XMM0,Value CVTSD2SI EAX, XMM0 End; Function RoundMEM_SSE(Var Value: Single): Integer; Overload; Asm // as written, fatest version CVTSS2SI EAX, [Value] End; Function RoundMEM_SSE(Var Value: Double): Integer; Overload; Asm // as written, fatest version CVTSD2SI EAX, [Value] End; </code></pre> <p>To truncate you have the same with CVTTSS2SI / CVTTSD2SI:</p> <pre><code>Function TruncSSE(Value: Single): Integer; Overload; Asm // additional PUSH/POP pointer stack added automatically CVTTSS2SI EAX, Value End; Function TruncSSE(Value: Double): Integer; Overload; Asm // additional PUSH/POP pointer stack added automatically MOVQ XMM0,Value CVTTSD2SI EAX, XMM0 End; Function TruncMEM_SSE(Var Value: Single): Integer; Overload; Asm // as written, fatest version CVTTSS2SI EAX, [Value] End; Function TruncMEM_SSE(Var Value: Double): Integer; Overload; Asm // as written, fatest version CVTTSD2SI EAX, [Value] End; </code></pre> <p>To Floor, Ceil, use respectively *TruncMEM_SSE(value)* and <em>RoundSSE(value + 0.5)</em>. These functions will give you a 20% perf gain. It has been tested in loops and in a real program (with a memory cache filled/ an instruction cache filled, so it can be considered as a real-life test).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload