Performing Program-Level Optimization (
−
pm and
−
o3 Options)
3-8
3.3.2 Optimization Considerations When Mixing C and Assembly
If you have any assembly functions in your program, you need to exercise cau-
tion when using the
−
pm option. The compiler recognizes only the C source
code and not any assembly code that might be present. Because the compiler
does not recognize the assembly code calls and variable modifications to C
functions, the
−
pm option optimizes out those C functions. To keep these func-
tions, place the FUNC_EXT_CALLED pragma (see section 5.4.3,
The
FUNC_EXT_CALLED Pragma
, on page 5-8) before any declaration or refer-
ence to a function that you want to keep.
Another approach you can take when you use assembly functions in your pro-
gram is to use the
−
op
n
option with the
−
pm and
−
o3 options (see section 3.3.1,
Controlling Program-Level Optimization
In general, you achieve the best results through judicious use of the
FUNC_EXT_CALLED pragma in combination with
−
pm
−
o3 and
−
op1 or
−
op2.
If any of the following situations apply to your application, use the suggested
solution:
Situation
Your application consists of C source code that calls assem-
bly functions. Those assembly functions do not call any C
functions or modify any C variables.
Solution
Compile with
−
pm
−
o3
−
op2 to tell the compiler that outside
functions do not call C functions or modify C variables.
If you compile with the
−
pm
−
o3 options only, the compiler
reverts from the default optimization level (
−
op2) to
−
op0. The
compiler uses
−
op0, because it presumes that the calls to the
assembly language functions that have a definition in C may
call other C functions or modify C variables.
Situation
Your application consists of C source code that calls assem-
bly functions. The assembly language functions do not call C
functions, but they modify C variables.
Solution
Try both of these solutions and choose the one that works
best with your code:
J
Compile with
−
pm
−
o3
−
op1.
J
Add the volatile keyword to those variables that may be
modified by the assembly functions and compile with
−
pm
−
o3
−
op2.
See section 3.3.1 on page 3-6 for information about the
−
op
n
option.
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...