Download Microcross i.MX GNU X
Transcript
Section 4. How to Use i.MX GNU X-Tools 4.7.6 Optimization i.MX GNU X-Tools GCC incorporates a sophisticated optimizing compiler; and for most target systems, it usually generates faster code than with the native compiler. Any ‘-Ox’ optimization can be used with any ‘-fx’ option (e.g., gcc -Os –funroll-loops –ffast-math –o outfile.x infile.c). Here are the most commonly used compilation options: -O0 No optimization. This is the default. With optimization turned off, GCC tries to generate code that is easy to debug; you can set a breakpoint between any two statements and modify variables, and the program will behave exactly as it should. The GCC also tries to generate code quickly. -O1 The compiler tries to moderately to reduce both the size of the compiled code and the execution time. Compilation is slower than with ‘–O0’ and requires more memory. -O2 Enables more optimizations than ‘–O1’. Compilation time is even slower; the resulting code should be even smaller and faster. -O3 Enables more optimizations than ‘–O2’. Try hardest of all to produce fast assembly code. Note that the emphasis is on fast: the resulting code may take much more room in memory because certain functions may be placed in-line and loops may be unrolled (as if each iteration in the for loop were written out independently). -Os Try to produce code that is small. The emphasis is on size, not speed. This option uses many of the same optimization algorithms as ‘–O2’, but with a different emphasis. -ffast-math Make floating-point arithmetic optimizations that violate the ANSI or IEEE standards. Code compiled with this option may yield incorrect results, but it will be slightly faster. Be sure to test your program thoroughly. -finline-functions Expand all “simple functions” into their callers. The compiler gets to decide whether any function is “simple” or not. Inline expansion is a two-edged sword; it can make a program faster (by eliminating calling overhead) or slower (by making instruction cache performance worse). -fno-inline Inhibit all inlining, even inlining that is requested by the inline keyword in the source code. The GCC performs inlining according to statements in the source code with both ‘–O1’ and ‘–O2’; the keyword is ignored if optimization is not in effect. -funroll-loops On some CPUs, loop unrolling can be a very important optimization. It minimizes loop overhead and creates many opportunities for further optimizations. With the ‘–funroll-loops’ option, GCC unrolls all loops that have a fixed iteration count known at the time of compilation. Loop unrolling is another risky optimization; it can improve performance, but it can also penalize performance significantly: the object file becomes larger, which can significantly hurt cache performance. Compile time also increases. 50 ■ i.MX GNU X-Tools User Guide