Generalization For Multiple Constant Control Code - AMD Athlon Processor x86 Optimization Manual

X86 code optimization
Table of Contents

Advertisement

22007E/0—November 1999

Generalization for Multiple Constant Control Code

Generic Loop Hoisting
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 );
} else {
DoWork1( i );
}
if( CONSTANT1 ) {
DoWork2( i );
} else {
DoWork3( i );
}
}
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 ... ) {
}
break;
case combine( 1, 0 ):
for( i ... ) {
}
break;
case combine( 0, 1 ):
for( i ... ) {
}
break;
AMD Athlon™ Processor x86 Code Optimization
//does not affect CONSTANT0
// or CONSTANT1
//does not affect CONSTANT0
// or CONSTANT1
//does not affect CONSTANT0
// or CONSTANT1
//does not affect CONSTANT0
// or CONSTANT1
DoWork0( i );
DoWork2( i );
DoWork1( i );
DoWork2( i );
DoWork0( i );
DoWork3( i );
23

Advertisement

Table of Contents
loading

Table of Contents