Generic Loop Hoisting
23
22007E/0—November 1999
AMD Athlon™ Processor x86 Code Optimization
Generalization for Multiple Constant Control Code
To generalize this further for multiple constant control code
some more work may have to be done to create the proper outer
loop. Enumeration of the constant cases will reduce this to a
simple switch statement.
Example 2:
for(i ... ) {
if( CONSTANT0 ) {
DoWork0( i );
//does not affect CONSTANT0
// or CONSTANT1
} else {
DoWork1( i );
//does not affect CONSTANT0
// or CONSTANT1
}
if( CONSTANT1 ) {
DoWork2( i );
//does not affect CONSTANT0
// or CONSTANT1
} else {
DoWork3( i );
//does not affect CONSTANT0
// or CONSTANT1
}
}
The above loop should be transformed into:
#define combine( c1, c2 ) (((c1) << 1) + (c2))
switch( combine( CONSTANT0!=0, CONSTANT1!=0 ) ) {
case combine( 0, 0 ):
for( i ... ) {
DoWork0( i );
DoWork2( i );
}
break;
case combine( 1, 0 ):
for( i ... ) {
DoWork1( i );
DoWork2( i );
}
break;
case combine( 0, 1 ):
for( i ... ) {
DoWork0( i );
DoWork3( i );
}
break;
Summary of Contents for Athlon Processor x86
Page 1: ...AMD Athlon Processor x86 Code Optimization Guide TM...
Page 12: ...xii List of Figures AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 16: ...xvi Revision History AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 202: ...186 Page Attribute Table PAT AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 252: ...236 VectorPath Instructions AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...
Page 256: ...240 Index AMD Athlon Processor x86 Code Optimization 22007E 0 November 1999...