AMD x86 manual Generalization for Multiple Constant Control Code

Models: x86

1 256
Download 256 pages 58.62 Kb
Page 39
Image 39

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;

Generic Loop Hoisting

23

Page 39
Image 39
AMD x86 manual Generalization for Multiple Constant Control Code