GCC 4.6 has added an option to generate i3/i5/i7 processor specific machine code. The option is corei7 and it generates optimized machine code for these cores with 64-bit extensions, MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1 and SSE4.2 instruction set support. Before going into the details of how to use this option with pentium-builder we will explain 3 GCC switches relevant in this context:

-march=cpu-type

generate instructions for this cpu-type. Implies -mtune=cpu-type (see next). Enables all instruction subsets supported by cpu-type and the generated code might not be compatible with other CPUs.

generate instructions for this cpu-type. Implies -mtune=cpu-type (see next). Enables all instruction subsets supported by cpu-type and the generated code might not be compatible with other CPUs. -mtune=cpu-type

Tune to cpu-type everything applicable about the generated code, except for the ABI and the set of available instructions. While picking a specific cpu-type schedules things appropriately for that particular chip, the compiler does not generate any code that cannot run on the default machine type.

Tune to cpu-type everything applicable about the generated code, except for the ABI and the set of available instructions. While picking a specific cpu-type schedules things appropriately for that particular chip, the compiler does not generate any code that cannot run on the default machine type. -mcpu=cpu-type

Deprecated. Same as -mtune.

Laptops with i3/i5/i7 CPU are very common nowadays. If you want to optimize your local applications (or even your locally compiled kernel) you can use the corei7 option. The utility that can help you do this without tinkering with the installed gcc on your system or editing a lot of Makefiles is pentium-builder. It creates wrappers to the default installed gcc, g++ etc. To install on Ubuntu, run:

$ sudo apt-get install pentium-builder

By default gcc, g++… will behave as usual even with pentium-builder installed. To add the optimization option export the following before you start a compilation:

$ export DEBIAN_BUILDARCH=corei7

If you want to use this option always, add it to your .bashrc. It’s easy to add new switches with pentium-builder. Open and edit /usr/bin/gcc which is now a link to /usr/bin/builder-cc installed by pentium-builder. The line of interest is

"-mcpu=$ENV{DEBIAN_BUILDARCH}", "-march=$ENV{DEBIAN_BUILDARCH}"

You can add new switches to it.