1. Choose the appropriate compilation options (introduction)
-o0/1/2/3: The most important optimization options; if -o3 is selected, the compiler will try all possible optimization methods, but sometimes it may cause errors in the optimized program. -o0 and -o1 will not cause optimization errors, but the optimized performance will be greatly reduced.
-g: Allows the compiler to insert symbolic debugging information, which is a very good tool in the development and debugging phase, but should be avoided in the final product code compilation because it reduces parallel processing instructions and takes up additional code space, greatly affecting code performance.
-mt: instructs the compiler that the pointer parameters in all functions in the application do not point to the same address, but it only acts on the pointers in the function parameters and is invalid for the local pointers inside the function.
-k and -mw: These two options have nothing to do with the final code performance, but they can be used to obtain optimization feedback information from the compiler to help programmers adjust optimization strategies. The -k option retains the compiler's assembly output; -mw outputs information related to software pipelining
2. The "restrict" keyword
restrict works similarly to the -mt compiler option. It tells the compiler that a pointer cannot point to the same memory as other pointers in the function.
the restrict keyword can be applied to any pointers, regardless of whether it is a parameter, a local variable, or an element of a referenced dataobject. Moreover, because the restrict keyword is only effective in the function it is in, it can be used whenever needed
Note: The "restrict" keyword cannot be added randomly. We need to understand the on-chip memory composition of C6000. Restrict is only legal when the memory pointed to by the two pointers is in different blocks.
3. Provide information through pragma
You can insert some pragma instructions with specific syntax into the code to tell the compiler some information about the code. Because the compiler always optimizes the code with the worst plan when there is no information, if the programmer can provide some key information, it will greatly help the compiler make good decisions. The most commonly used ones are MUST_ITERATE and UNROLL.
|