Recent

Author Topic: optimization switches not working?  (Read 8255 times)

Selfmade.exe

  • New Member
  • *
  • Posts: 36
optimization switches not working?
« on: June 14, 2018, 10:35:23 pm »
Hello,

Unless I miss something here is what happens:

If I put some opimization switches in project-> project options-> compiler options-> custom options  they work fine.

But because I dont want them there, if I remove them from there and put them in the main program as {$OPTIMIZATION some opimization switches} they don't work.

In both cases, in the project-> project options-> compiler options-> compilation and linking, the optimization level is set to zero (in order to choose exactly what optimizations I need.)

When I put them in the custom options, the progam runs significantly faster.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: optimization switches not working?
« Reply #1 on: June 14, 2018, 10:55:01 pm »
Switches in the source are local to the module (unit,program) they are in.

Switches in the project or to the commandline are global to all modules compiled with them active (IOW: force rebuild to have it take a global effect).

Selfmade.exe

  • New Member
  • *
  • Posts: 36
Re: optimization switches not working?
« Reply #2 on: June 14, 2018, 11:50:00 pm »
I use simple program (project -> new project-> simple pogram), and I put the switches in the very top of the single lpr file, before the program xxx; Is this still doesn't affect the whole program?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: optimization switches not working?
« Reply #3 on: June 14, 2018, 11:56:28 pm »
I use simple program (project -> new project-> simple pogram), and I put the switches in the very top of the single lpr file, before the program xxx; Is this still doesn't affect the whole program?

That still doesn't affect the whole program. Only the code in the .lpr. It has been that way since Turbo Pascal 4 in 1987 introduced units.

Selfmade.exe

  • New Member
  • *
  • Posts: 36
Re: optimization switches not working?
« Reply #4 on: June 15, 2018, 12:10:45 am »
Ok then, thank you very much! That pretty much explains everything!

Selfmade.exe

  • New Member
  • *
  • Posts: 36
Re: optimization switches not working?
« Reply #5 on: June 16, 2018, 03:26:15 pm »
One more thing,

according to this http://wiki.freepascal.org/Optimization , if I put all the switches (in compiler options-> custom options of course) that make the O1,O2,O3 and O4 altogether (REMOVEEMPTYPROCS + REGVAR + STACKFRAME .... and so on) then it will be equillavent in puting just the -O4. It seems that this isn't working  (with the exception of -OoUSELOADMODIFYSTORE which gives me compiler error, more like this switch does not exist).

dredd

  • Newbie
  • Posts: 5
Re: optimization switches not working?
« Reply #6 on: June 16, 2018, 10:06:18 pm »
even more :
switches in option boxes do only work for local project, they do not apply  for used packages or LCL/FCL linked parts.
SO you really need to go on"Additions and Override" and add custom settings stored in .lpi
OTHERWISE
1) conditional defines come out of scope
2) -CX -XX options do nothing but blowing gas into factory
3) parts of debug info may stay in your final release as dummy relinquish dumps

the only project REAL Global  options are in "Additions and Override ->Add custom options", all other settings are not.
Pretty strange behaviour that is not logical
« Last Edit: June 16, 2018, 10:22:23 pm by dredd »
burp!

dredd

  • Newbie
  • Posts: 5
Re: optimization switches not working?
« Reply #7 on: June 16, 2018, 10:16:12 pm »
for -Onnn optimizations, it goes same way. Better put the optimizations switches where I mentioned = Override, Add Custom ... in lpi
Otherwise used packages and FCL/LCL parts won't be optimized
« Last Edit: June 16, 2018, 10:21:22 pm by dredd »
burp!

Selfmade.exe

  • New Member
  • *
  • Posts: 36
Re: optimization switches not working?
« Reply #8 on: June 16, 2018, 11:23:07 pm »
I tried what you described, but still no effect. The bunch of -Ooxxx options do nothing as -O4. Even if I put -O4 it seems it does nothing.. Plus the whole program takes ages to compile whereas cust options was a matter of 1-2 seconds.

Selfmade.exe

  • New Member
  • *
  • Posts: 36
Re: optimization switches not working?
« Reply #9 on: June 16, 2018, 11:25:40 pm »
Also -CpCOREAVX2 gives error when used in overrides instead of custom options; I have to change it in -CpCOREAVX

dredd

  • Newbie
  • Posts: 5
Re: optimization switches not working?
« Reply #10 on: June 16, 2018, 11:35:25 pm »
it takes time to compile at 1st compile time, then it compiles again fast, and it is totally normal due to the recompilation of packages and parts with new switches

now for the AVX or AVX2, I have no clue, all works fine to me. maybe one of  your package have an allergy
burp!

dredd

  • Newbie
  • Posts: 5
Re: optimization switches not working?
« Reply #11 on: June 16, 2018, 11:44:19 pm »
sample :
defined global syms and opts upon compile modes (default, debug, release)

notes :
-CX -XX take effect HERE on packages (not in "Compilation and linking" box on project)
-g- -Xs -O3 apply ALSO to packages & LCL/FCL parts,takes more time on 1st compilation

in fact, custom options here apply both on project and used packages (GLOBAL) where other settings are project's units ONLY options
« Last Edit: June 17, 2018, 12:08:22 am by dredd »
burp!

Selfmade.exe

  • New Member
  • *
  • Posts: 36
Re: optimization switches not working?
« Reply #12 on: June 17, 2018, 01:53:30 pm »
Yes it must be an allergy in some package(s). But then again it this whole compile topic is a bit confusing.. I just need one place to put my switches (override clearly puts them in the WHOLE program, but I interested in optimizing the main project, i.e the main algorithm(s) and not the additional packages), and I want not to use packed switches like O4. Still I can't find the bunch of switches that are equillavent to O4...

Selfmade.exe

  • New Member
  • *
  • Posts: 36
Re: optimization switches not working?
« Reply #13 on: June 18, 2018, 11:24:14 pm »
Bump.. Anyone any thoughts?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: optimization switches not working?
« Reply #14 on: June 19, 2018, 11:31:02 am »
Compile everything, including fpc and lazarus with these switches.

FPC libraries (non visual libs) are not usually recompiled from within lazarus.

 

TinyPortal © 2005-2018