[fpc-devel] Fwd: Re: An optimization suggestion for FPC

J. Gareth Moreton gareth at moreton-family.com
Sun Jun 28 12:31:55 CEST 2020


So someone reached out to me directly again asking for an FPC 
optimisation.  Now I want to see if this is possible to optimise and 
won't break something or be annoying specific.

Gareth aka. Kit

-------- Forwarded Message --------
Subject: 	Re: An optimization suggestion for FPC
Date: 	Sun, 28 Jun 2020 11:30:09 +0100
From: 	J. Gareth Moreton <gareth at moreton-family.com>
To: 	Okoba <okobapatino at protonmail.com>



Heh, I'm honoured you came to me directly.  I'll see if I can work 
anything out.  A lot of it is down to where the record is stored.  If 
it's on the stack, an optimisation shouldn't be difficult, but if it's 
on the heap somewhere, then it will be a bit more difficult.  Do you 
have your C++ example, and which C++ compiler did you use?

Gareth aka. Kit

On 28/06/2020 11:06, Okoba wrote:
> Hi,
> It seems you are interested in optimizing FPC and I have a trouble 
> with it and wanted to check it with you if I may.
> I like to have a way to pass the record variable and inc it without 
> losing speed. I wrote a sample and ran it with FPC trunk in Win64 and 
> the times are commented. I should say the times for Delphi for the 
> same target is the same. And tried a C++ version and all the times are 
> almost the same and near 250.
> I tried many ways including absolute, pointer, custom asm functions, 
> custom functions with const and var params and the are almost always 
> slower than the first loop.
> So is there anyway to have a custom Inc function that get he record 
> variable and inc it without losing speed in compare to the system inc?
>
> Regards.
>
>
>
> program Project1;
>
> uses
>   SysUtils;
>
> type
>   TTest = record
>     P: int64;
>   end;
>
>   procedure Test;
>   var
>     V: TTest;
>     P: int64;
>     T: UInt64;
>     i, C: integer;
>   begin
>     C := 1000 * 1000 * 1000;
>
>     T := GetTickCount64;
>     P := 1;
>     for i := 1 to C do
>       Inc(P);
>     WriteLn(GetTickCount64 - T); //266
>
>     T := GetTickCount64;
>     V.P := 1;
>     for i := 1 to C do
>       Inc(V.P);
>     WriteLn(GetTickCount64 - T); //1400
>
>     T := GetTickCount64;
>     V.P := 1;
>     P := V.P;
>     for i := 1 to C do
>       Inc(P);
>     P := V.P;
>     WriteLn(GetTickCount64 - T);  //250
>   end;
>
> begin
>   Test;
>   ReadLn;
> end.
>


-- 
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20200628/a34b6928/attachment.htm>


More information about the fpc-devel mailing list