Recent

Author Topic: Register variables and optimizations for x86_64  (Read 443 times)

440bx

  • Sr. Member
  • ****
  • Posts: 427
Register variables and optimizations for x86_64
« on: November 29, 2018, 05:38:24 pm »
Hello,

I'd like to tell FPC to place one or more variables in registers. Is this possible and if so how ?

The other question I have is, is it possible to tell the compiler to optimize for the x86_64 architecture ?... those CPUs/mode have more registers available that the compiler can use to optimize code. 

I tried -Or but, it didn't seem to have any effect  (maybe I missed something else though)

Basically, what's the "magic" switch sauce that will produce the best possible code (tight and fast) for Windows 64bit applications ?

Thank you for your help.

Nitorami

  • Sr. Member
  • ****
  • Posts: 346
Re: Register variables and optimizations for x86_64
« Reply #1 on: November 29, 2018, 06:10:28 pm »
I would expect that with -OoREGVAR set, fpc uses registers for optimizing function calls. This does make a noticeable difference to me when calling procedures in tight loops.
You may also tell the compiler to additionally use EBP and RBP, see here
http://wiki.freepascal.org/Optimization.
Regarding these, I did not notice any difference so far in my programs, but I guess any effects may be very code specific.

440bx

  • Sr. Member
  • ****
  • Posts: 427
Re: Register variables and optimizations for x86_64
« Reply #2 on: November 29, 2018, 06:33:06 pm »
I would expect that with -OoREGVAR set, fpc uses registers for optimizing function calls. This does make a noticeable difference to me when calling procedures in tight loops.

I'll give that -OoREGVAR a try.  Thank you for the suggestion.

I wish there was a way to tell the compiler to put a specific variable (or variables) in a register.  There are times when that would not only make the code faster but also, a good bit smaller.