Red Hat ENTERPRISE LINUX 3 - DEVELOPER TOOLS GUIDE Guide de l'utilisateur Page 56

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 100
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 55
Chapter 4. Compiling and Building
46
4.1.6.4. Recommended Optimization Options
Different projects require different optimization options. There is no one-size-fits-all approach when it
comes to optimization, but here are a few guidelines to keep in mind.
Instruction selection and tuning
It is very important to chose the correct architecture for instruction scheduling. By default GCC
produces code is optimized for the most common processors, but if the CPU on which your code will
run is known, the corresponding -mtune= option to optimize the instruction scheduling, and -march=
option to optimize the instruction selection should be used.
The option -mtune= optimizes instruction scheduling to fit your architecture by tuning everything
except the ABI and the available instruction set. This option will not chose particular instructions,
but instead will tune your program in such a way that executing on a particular architecture will be
optimized. For example, if an Intel Core2 CPU will predominantly be used, choose -march=core2.
If the wrong choice is made, the program will still run, but not optimally on the given architecture. The
architecture on which the program will most likely run should always be chosen.
The option -march= optimizes instruction selection. As such, it is important to choose correctly as
choosing incorrectly will cause your program to fail. This option selects the instruction set used when
generating code. For example, if the program will be run on an AMD K8 core based CPU, choose -
march=k8. Specifying the architecture with this option will imply -mtune=.
The -mtune= and -march= commands should only be used for tuning and selecting instructions
within a given architecture, not to generate code for a different architecture (also known as cross-
compiling). For example, this is not to be used to generate PowerPC code from an Intel 64 and
AMD64 platform.
For a complete list of the available options for both -march= and -mtune=, refer to the GCC
documention available here: GCC 4.4.4 Manual: Hardware Models and Configurations
5
General purpose optimization flags
The compiler flag -O2 is a good middle of the road option to generate fast code. It produces the best
optimized code when the resulting code size is not large. Use this when unsure what would best suit.
When code size is not an issue, -O3 is preferrable. This option produces code that is slightly larger
but runs faster because of a more frequent inline of functions. This is ideal for floating point intensive
code.
The other general purpose optimization flag is -Os. This flag also optimizes for size, and produces
faster code in situations where a smaller footprint will increase code locality, thereby reducing cache
misses.
Use -frecord-gcc-switches when compiling objects. This records the options used to build
objects into objects themselves. After an object is built, it determines which set of options were used
to build it. The set of options are then recorded in a section called .GCC.command.line within the
object and can be examined with the following:
$ gcc -frecord-gcc-switches -O3 -Wall hello.c -o hello
$ readelf --string-dump=.GCC.command.line hello
5
http://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/Submodel-Options.html#Submodel-Options
Vue de la page 55
1 2 ... 51 52 53 54 55 56 57 58 59 60 61 ... 99 100

Commentaires sur ces manuels

Pas de commentaire