| ||Disables all optimisations and is useful for debugging.|
| || Enables all the flags for
| ||Safest optimisation level for speed.|
| ||Enables aggressive optimisations.|
| ||Only in recent compilers, enables even more optimisations by violating standards compliance.|
The most common optimisation levels are
-O2. Anything more aggressive than than that is bound to break code on a large scale. The optimisation levels are cumulative such that specifying
-O3 will include the optimisations from
Note that you will find many instances along the following lines:
-fomit-frame-pointer is already included in
-O1 which is included in
-O2 which makes specifying the flag redundant. When in doubt, consult the official optimisation options manual.
-march that can be set is
-march=native which allows the compiler to guess the processor's features and use them during compilation. This is a feature supported from
GCC 4 and up and eliminates the need to supply an
However, if you need to specify a
-mtune, then a good procedure is as follows:
CPUyou have and on Linux you can issue
cat /proc/cpuflagsto see the flags supported by your
CPU. A description of those features can be found on the cpuflags page.
gcc -vin a terminal to determine which compiler version you have.
-mtunethat closely matches the
CPUfeatures you have. It is important to specify a processor that has less or the same set of features matching your
As an example, suppose we have an Intel
i7 running on
4.2.4. Looking at the list on the manual page above, we find:
pentium4, pentium4m Intel Pentium4 CPU with MMX, SSE and SSE2 instruction set support. prescott Improved version of Intel Pentium4 CPU with MMX, SSE, SSE2 and SSE3 instruction set support. nocona Improved version of Intel Pentium4 CPU with 64-bit extensions, MMX, SSE, SSE2 and SSE3 instruction set support.
Since we are running a
64-bit processor, and because the Intel
i7 supports the
SSE3 instruction set, the most suiting for us in
prescott and even
pentium4 will be fine.
To switch between 64bit and 32bit use the flag
The following is the list of
SSE flags for the
-msse2 -msse3 -mssse3 -msse4.1 -msse4.2
They do not need to all be listed in the
CFLAGS as the compiler will choose the most advanced one during compilation.
can be added in order to enable multimedia extensions.
-O2 -m64 -flto -msse4.1 -mfpmath=sse -ffast-math -funroll-loops
Nehalem processors which support
-O2 -flto -mssse3 -mfpmath=sse