[fpc-devel] LEA instruction speed

J. Gareth Moreton gareth at moreton-family.com
Sun Oct 8 16:35:29 CEST 2023


Did some checking of the test I copied the code from, and I forgot that 
Rika's original code only exited once a certain time period had elapsed 
(e.g. 0.5 seconds).  I had changed it to a standard iteration count 
since I was concerned about fairness and accuracy, but I only changed 
the loop condition and nothing else.

Kit

On 08/10/2023 11:06, Marģers . via fpc-devel wrote:
> 1. why you leave "time:=..." in benchmark loop? It does add 50% of 
> execution time per call.
> 2. Pascal version does not match assembler version. Had to fix it.
>       //Result := X + Counter + $87654321;
>       Result:=Result + X + $87654321;
>       Result:=Result xor y;
> 3. Assembler functions can be unified to work under win64,win32, linux 
> 64, linux 32
> function Checksum_LEA(const Input, X, Y: LongWord): LongWord; 
> assembler; nostackframe;
> asm
> @Loop2:
>   LEA Input, [Input + X + $87654321]
>   XOR Input, y
>   DEC y
>   JNZ @Loop2
>   MOV EAX, Input
> end;
>
> 4. My results. Ryzen 2700x
>
>    Pascal control case: 0.7 ns/call  0.0710
>  Using LEA instruction: 0.7 ns/call  0.0700
> Using ADD instructions: 0.7 ns/call  0.0710
>
> Even thou results are equal, i was able to add 4 independent ADD 
> instructions around LEA while results didn't chance, but only 2 around 
> ADD.
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


More information about the fpc-devel mailing list