Optimizing a compiler?
Sorry, this might be a little bit OT, but can anyone point me at some useful info about how to compile code so that it uses the best speed features of a given type of CPU?
I know that I can recompile the _kernel_ for and Athlon processor or an intel P4 etc, but how do I optimize my own code which has nothing to do with the kernel?
Do I need to change the code itself, or can I give gcc (in this case g++) some options that tell it to use the best possible number crunching code for my Athlon servers?
We're doing some research into video pattern recognition, so need to get the absolute maximum possible number munching from our servers as a single run take us at least 18 hours; every saved clock cycle adds up.
Thanks.
Paul.
Signature · 5 lines
Paul Furness Systems Manager 2+2=5 for extremely large values of 2.
Quoted 11 lines · Paul Furness
Sorry, this might be a little bit OT, but can anyone point me at some useful info about how to compile code so that it uses the best speed features of a given type of CPU?
I know that I can recompile the _kernel_ for and Athlon processor or an intel P4 etc, but how do I optimize my own code which has nothing to do with the kernel?
Do I need to change the code itself, or can I give gcc (in this case g++) some options that tell it to use the best possible number crunching code for my Athlon servers?
Select the specific choice of CPU via "-mcpu=" and "-march=".
Select optimisations and code generation options via various "-f" switches, as described in the "Optimize Options" and "Code Gen Options" pages of the GCC Info file (under "Invoking GCC").
The issue of which optimisations will actually make a difference depends upon the type of code being executed. For FP-intensive code, -ffast-math may help (but is potentially risky). -fomit-frame-pointer frees up an extra register, which can be quite significant on the register-starved x86 architecture, but prevents debugging.
If a significant amount of time is spent in library functions, consider static linking (the position-independent code used in shared libraries may add ~5% to execution times).
However, if your code has any significant algorithmic inefficiencies, the performance gain from improving the algorithms will dwarf anything which you will achieve through compilation switches. Incidentally, it's much easier to overlook potential sources of inefficiency when using C++ than with C.
Also, consider using a profiler to identify sections of the code which warrant maximum scrutiny.
Signature · 1 line
Glynn Clements <[email protected]>