HP C Programmer's Guide (92434-90009)

Chapter 4 95
Optimizing HP C Programs
Level 3 Optimizations
Level 3 Optimizations
Level 3 optimization includes level 2 optimizations, plus full optimization across all
subprograms within a single file. Level 3 also inlines certain subprograms within the input
file. Use +O3 to get level 3 optimization.
Level 3 optimization produces faster run-time code than level 2 on code that frequently
calls small functions within a file. Level 3 links faster than level 4.
Inlining within a Single Source File
Inlining substitutes functions calls with copies of the function's object code. Only functions
that meet the optimizer's criteria are inlined. This may result in slightly larger executable
files. However, this increase in size is offset by the elimination of time-consuming
procedure calls and procedure returns.
Example of Inlining
The following is an example of inlining at the source code level. Before inlining, the source
file looks like this:
/* Return the greatest common divisor of two positive integers, */
/* int1 and int2, computed using Euclid's algorithm. (Return 0 */
/* if either is not positive.) */
int gcd(int1,int2)
int int1;
int int2;
{
int inttemp;
if ( ( int1 <=0)||(int2 <=0)){
return(0);
}
do {
if ( int1 < int2 ) {
inttemp = int1;
int1 = int2;
int2 = inttemp;
}
int1 = int1 - int2;
} while (int1 > 0);
return(int2);
}
main()
{
int xval,yval,gcdxy;
/* statements before call to gcd */
gcdxy = gcd(xval,yval);
/* statements after call to gcd */
}