AN2094 Freescale Semiconductor / Motorola, AN2094 Datasheet - Page 8

no-image

AN2094

Manufacturer Part Number
AN2094
Description
ITU-T G.729 Implementation on StarCore SC140
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Optimization Process
2.3.1 Function Inlining
Function inlining (also referred to as ‘inline expansion’ or simply ‘inlining’), is the process of replacing a function
call with the body of the function itself. This optimization technique improves execution time by eliminating
function-call overhead at the expense of larger code size.
Profiler information is used to determine whether a function should be inlined. Small, frequently-called functions
are the best candidates for inlining. However, other factors should also be considered, including the number and
type (input or output) of parameters the function passes, how the results are returned, and data alignment. In some
cases, the alignment property of a vector parameter is lost when the function is inlined. For example, a procedure
that calculates the energy of a signal represented in an array of 80 data samples takes 23 cycles when the all data
start addresses are multiples of eight. The same procedure on unaligned data takes 42 cycles.
In general, functions that take fewer than 25 cycles offer the most speed savings by inlining. The overhead to call
such a function is typically 20 percent or greater. Functions that take 25–35 cycles and pass several parameters are
also worth inlining. Function inlining is done in one of three ways:
/**** L_Extract is defined as ****/
/*
*/
/* next four L_Extract() calls were manually replaced with L_Extract() body*/
// L_Extract(sum0, &r_h[i], &r_l[i]);
// L_Extract(sum1, &r_h[i+1], &r_l[i+1]);
// L_Extract(sum2, &r_h[i+2], &r_l[i+2]);
// L_Extract(sum3, &r_h[i+3], &r_l[i+3]);
r_h[i]
r_h[i+1] = extract_h(sum1);
r_h[i+2] = extract_h(sum2);
r_h[i+3] = extract_h(sum3);
r_l[i]
r_l[i+1] = extract_l(L_msu( L_shr(sum1, 1), r_h[i+1], 16384));
r_l[i+2] = extract_l(L_msu( L_shr(sum2, 1), r_h[i+2], 16384));
r_l[i+3] = extract_l(L_msu( L_shr(sum3, 1), r_h[i+3], 16384));
Implicit and explicit inlining requires no knowledge of the code and is performed without examining code sections
because the compiler automatically tries to interleave consecutive calls. These techniques are recommended when
there is only one call to the inlined function.
8
void L_Extract(Word32 L_32, Word16 *hi, Word16 *lo)
{
}
*hi
*lo
return;
Implicitly, allowing the compiler to select the functions to be inlined. This is done in the Enterprise C
compiler by setting the –Og compiler option.
Explicitly, using the #pragma inline C statement [9]. To inline a function in several files, the function
should be placed in a header file, and the static keyword should be used in each file to prevent the linker
from generating duplicate global symbols.
Manually replacing a function call with the body of the function body. The manual inlining technique is
illustrated in Code Example 3, taken from the Autocorr() function.
= extract_h(sum0);
= extract_l(L_msu( L_shr(sum0, 1), r_h[i], 16384));
= extract_h(L_32);
= extract_l( L_msu( L_shr(L_32, 1) , *hi, 16384));
ITU-T G.729 Implementation on the StarCore™ SC140/SC1400 Cores, Rev. 1
Example 3. Manual Inlining Technique
Freescale Semiconductor

Related parts for AN2094