<HTML>
<div><style> BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }</style>I think one of the main issues with intrinsics is that you don't have much control over where results are stored. Unless you're chaining a load of intrinsics together in a mess of function calls in actual parameters, the result is going to have to be stored in a local variable, which even on good days will end up being stored on the stack, and problems can occur if the stack isn't aligned and you're using SSE or AVX instructions. After that, when you call the next intrinsic that uses the result, it will have to recall that data from memory.<br>
<br>
With care, especially if you only need a temporary value, you don't have to worry about the stack at all or worry in the back of your mind that the intrinsics aren't being as optimal as they could be. To use the integer clamp function as an example (if x < 0 then x := 0):<br>
<br>
{ Microsoft x64 calling convention... X is in ECX }<br>
function ClampInt(X: LongInt): LongInt; assembler; nostackframe; inline;<br>
asm<br>
XOR EAX, EAX<br>
</div><div> TEST ECX, ECX<br>
CMOVG EAX, ECX<br>
end;<br>
<br>
The instructions are arranged in order to reduce the chance of a pipeline stall, and ECX is written to the result (EAX) only if ECX is greater than zero, otherwise EAX is set to zero (by the XOR EAX, EAX instruction).<br>
<br>
True, optimiser improvements can improve a lot of the stall situations and unnecessary storage, but that in itself is a mammoth task.<br>
<br>
Gareth aka. Kit<br>
</div><br>
<br>
<br>
<span style="font-weight: bold;">On Sun 17/03/19 21:56 , Florian Klämpfl florian@freepascal.org sent:<br>
</span><blockquote style="BORDER-LEFT: #F5F5F5 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">Am 17.03.19 um 21:37 schrieb J. Gareth Moreton:
<br>
<span style="color: rgb(102, 102, 102);">> My take on the whole "inlined assembler routines" vs. "intrinsics"...
</span><br>
<span style="color: rgb(102, 102, 102);">> why not both?
</span><br>
<br>
Maintenance effort.
<br>
<br>
<span style="color: rgb(102, 102, 102);">>They both fill a different niche,
</span><br>
<br>
What niche do inline assembler routines fill, intrinsics dont't ? This
<br>
is imo the central question. What can be done by inline assembler
<br>
routines, intrinsics cannot?
<br>
_______________________________________________
<br>
fpc-devel maillist - <a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<br>
<a target="_blank" href="<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>"><span style="color: red;">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</span></a>
<br>
<br>
<br>
</blockquote></HTML>