I have seen many examples of optimization flags used by different engines, and was wondering what might be the best to use overall to
compile the fastest code.
Some examples I have seen include:
-fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
(Stockfish)
-09 -march-athlon -funroll-all-loops -fomit-frame-pointer -fno-gsce
-fstrict-aliasing -fssa
(GCP's site which benchmarks different flags)
It seems to me that the -march-athlon flag is a good one for my system since its a AMD chip, and the flag -fomit-frame-pointer seems to get alot
of use in different engines. -fssa is not useful for my system? and I think -fno-rtti is for c++ not c. I can optimize to -03 level, not above, so -04 etc.. I can't use.
Any ideas for a good (best) overall optimization for c code?
Optimize?
Moderator: Ras
-
bob
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: Optimize?
There is only one way to find out. Try each one and do a benchmark run. Each compiler version is different, there are different types of processors that cause optimizations to work differently, etc.outAtime wrote:I have seen many examples of optimization flags used by different engines, and was wondering what might be the best to use overall to
compile the fastest code.
Some examples I have seen include:
-fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
(Stockfish)
-09 -march-athlon -funroll-all-loops -fomit-frame-pointer -fno-gsce
-fstrict-aliasing -fssa
(GCP's site which benchmarks different flags)
It seems to me that the -march-athlon flag is a good one for my system since its a AMD chip, and the flag -fomit-frame-pointer seems to get alot
of use in different engines. -fssa is not useful for my system? and I think -fno-rtti is for c++ not c. I can optimize to -03 level, not above, so -04 etc.. I can't use.
Any ideas for a good (best) overall optimization for c code?
-
bhlangonijr
- Posts: 482
- Joined: Thu Oct 16, 2008 4:23 am
- Location: Milky Way
Re: Optimize?
In addition, you can try a PGO (Profile Guided Optimization) perhaps you can improve your engine's performance a bit. I don't know, maybe the experts here can tell you about the overall results using PGO in their tests.bob wrote:There is only one way to find out. Try each one and do a benchmark run. Each compiler version is different, there are different types of processors that cause optimizations to work differently, etc.outAtime wrote:I have seen many examples of optimization flags used by different engines, and was wondering what might be the best to use overall to
compile the fastest code.
Some examples I have seen include:
-fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
(Stockfish)
-09 -march-athlon -funroll-all-loops -fomit-frame-pointer -fno-gsce
-fstrict-aliasing -fssa
(GCP's site which benchmarks different flags)
It seems to me that the -march-athlon flag is a good one for my system since its a AMD chip, and the flag -fomit-frame-pointer seems to get alot
of use in different engines. -fssa is not useful for my system? and I think -fno-rtti is for c++ not c. I can optimize to -03 level, not above, so -04 etc.. I can't use.
Any ideas for a good (best) overall optimization for c code?
I have tried PGO only with Intel Compiler for Linux - it's free (see the license). It appears that recent versions of GCC supports PGO.
Regards
Ben-Hur Carlos Langoni Junior
http://sourceforge.net/projects/redqueenchess/
http://sourceforge.net/projects/redqueenchess/
-
bob
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: Optimize?
PGO is worth at least 10% to me. GCC sort of supports it. You can't PGO a multi-threaded code, it will run but the second compile complains about corrupted PGO data... Intel works fine with threads...bhlangonijr wrote:In addition, you can try a PGO (Profile Guided Optimization) perhaps you can improve your engine's performance a bit. I don't know, maybe the experts here can tell you about the overall results using PGO in their tests.bob wrote:There is only one way to find out. Try each one and do a benchmark run. Each compiler version is different, there are different types of processors that cause optimizations to work differently, etc.outAtime wrote:I have seen many examples of optimization flags used by different engines, and was wondering what might be the best to use overall to
compile the fastest code.
Some examples I have seen include:
-fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
(Stockfish)
-09 -march-athlon -funroll-all-loops -fomit-frame-pointer -fno-gsce
-fstrict-aliasing -fssa
(GCP's site which benchmarks different flags)
It seems to me that the -march-athlon flag is a good one for my system since its a AMD chip, and the flag -fomit-frame-pointer seems to get alot
of use in different engines. -fssa is not useful for my system? and I think -fno-rtti is for c++ not c. I can optimize to -03 level, not above, so -04 etc.. I can't use.
Any ideas for a good (best) overall optimization for c code?
I have tried PGO only with Intel Compiler for Linux - it's free (see the license). It appears that recent versions of GCC supports PGO.
Regards
-
outAtime
- Posts: 226
- Joined: Sun Mar 08, 2009 3:08 pm
- Location: Canada
Re: Optimize?
Kewl. I did a PGO build, everything worked fine...-fprofile-use worked without complaints. I included the -O3 flag with -frofile-use on the second
make, is that o.k.? Is there a way to view which optimizations the PGO
selected? Also, I ran the engine only once - Should I allow it to play more
games than (one) before re-compile?
Thanks again for a nice suggestion, PGO is new to me and seems to work
fine.
make, is that o.k.? Is there a way to view which optimizations the PGO
selected? Also, I ran the engine only once - Should I allow it to play more
games than (one) before re-compile?
Thanks again for a nice suggestion, PGO is new to me and seems to work
fine.
outAtime
-
bob
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: Optimize?
I have a set of positions I always use for a PGO run. I wanted to make sure that I include opening positions, middlegame positions, endgame positions, plus I run a couple that use parallel search so that the parallel code also gets profiled and optimized. If you use EGTBs you should also run some positions that beat on EGTBs as well so that the egtb.cpp code gets optimized.outAtime wrote:Kewl. I did a PGO build, everything worked fine...-fprofile-use worked without complaints. I included the -O3 flag with -frofile-use on the second
make, is that o.k.? Is there a way to view which optimizations the PGO
selected? Also, I ran the engine only once - Should I allow it to play more
games than (one) before re-compile?
Thanks again for a nice suggestion, PGO is new to me and seems to work
fine.
O3 is fine, that is independent of the PGO stuff. I don't know how much you can coax the compiler to give you, but for the most part, the PGO optimizations are all about moving blocks of code around to optimize branches and instruction prefetching.
-
mcostalba
- Posts: 2684
- Joined: Sat Jun 14, 2008 9:17 pm
Re: Optimize?
Well, -fno-strict-aliasing is actually a pessimizationoutAtime wrote: -fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
(Stockfish)
But I need that because of a very critical function pop_1s_bit() uses type punning when compiled for 32 bit, and is broken without that flag.
Regarding remaining flags I have taken as is from Glaurung, I am not very interested in this because final compilation of release version normally it's up to Jim that knows very well (and much better then me) how to tweak the compiler to get the most out of sources.
So getting the fastest compile is something I (gladly) leave to others.
-
bob
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: Optimize?
If you use egtb.cpp you _must_ use that flag, as Eugene does some cute aliasing that will break if the compiler is not careful..mcostalba wrote:Well, -fno-strict-aliasing is actually a pessimizationoutAtime wrote: -fno-exceptions -fomit-frame-pointer -fno-rtti -fno-strict-aliasing
(Stockfish)compiler have more constraints to honor so could miss some optmization opportunities.
But I need that because of a very critical function pop_1s_bit() uses type punning when compiled for 32 bit, and is broken without that flag.
Regarding remaining flags I have taken as is from Glaurung, I am not very interested in this because final compilation of release version normally it's up to Jim that knows very well (and much better then me) how to tweak the compiler to get the most out of sources.
So getting the fastest compile is something I (gladly) leave to others.