Using Inline Function Expansion
2-28
2.6 Using Inline Function Expansion
When an inline function is called, the C source code for the function is inserted
at the point of the call. This is known as inline function expansion. Inline func-
tion expansion is advantageous in short functions for the following reasons:
-
It saves the overhead of a function call.
-
Once inlined, the optimizer is free to optimize the function in context with
the surrounding code.
Inline function expansion is performed in one of the following ways:
-
Intrinsic operators are expanded by default.
-
Automatic inline expansion is performed on small functions that are
invoked by the optimizer with the
−
o3 option. For more information, see
Automatic Inline Expansion (
−
oi Option)
-
Definition-controlled inline expansion is performed when you invoke the
compiler with optimization (
−
x option) and the compiler encounters the
inline keyword in code.
Note: Function Inlining Can Greatly Increase Code Size
Expanding functions inline expands code size, and inlining a function that is
called in a number of places increases code size. Function inlining is optimal
for functions that are called only from a small number of places and for small
functions. If your code size seems too large, try compiling with the
−
oi0
option and note the difference in code size.
2.6.1 Inlining Intrinsic Operators
The compiler automatically expands the intrinsic operators of the target sys-
tem (such as abs) by default. This expansion happens whether or not you use
the optimizer and whether or not you use any compiler or optimizer options on
the command line. (You can defeat this automatic inlining by invoking the com-
piler with the
−
x0 option.) Functions that expand the intrinsic operators are:
-
abs
-
labs
-
fabs
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...