[fpc-devel] Successful implementation of inlinesupportforpureassembler routines on x86

J. Gareth Moreton gareth at moreton-family.com
Sun Mar 17 23:51:19 CET 2019


 Just wrote some Pascal functions for ClampInt to test it:

 function ClampInt1(X: LongInt): LongInt; inline;
 begin
   if (X < 0) then
     Result := 0
   else
     Result := X;
 end;

 function ClampInt2(X: LongInt): LongInt; inline;
 begin
   Result := 0;
   if (X > 0) then Result := X;
 end;

 The first one produces relatively convoluted assembly language when
calling "I := ClampInt1(I);"

 0000000100001634 89f8                     mov   
%edi,%eax    To use the integer clamp function as an 
 example (if x < 0 then x := 0): 

 > { Microsoft x64 calling convention... X is in ECX } 
 > function ClampInt(X: LongInt): LongInt; 
 assembler; nostackframe; inline; 
 > asm 
 >   XOR EAX, EAX 
 >   TEST ECX, ECX 
 >   CMOVG EAX, ECX 
 > end; 

 try code: 
 y:=0; 
 if x < 0 then x:=y; 

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


More information about the fpc-devel mailing list