AMD Typewriter x86 사용자 설명서

다운로드
페이지 256
22
Use Const Type Qualifier
AMD Athlon™ Processor x86 Code Optimization 
22007E/0—November 1999
Use Const Type Qualifier
Use the “const” type qualifier as much as possible. This
optimization makes code more robust and may enable higher
performance code to be generated due to the additional
information available to the compiler. For example, the C
standard allows compilers to not allocate storage for objects
that are declared “const”, if their address is never taken.
Generic Loop Hoisting
To improve the performance of inner loops, it is beneficial to
reduce redundant constant calculations (i.e., loop invariant
calculations). However, this idea can be extended to invariant
control structures.
The first case is that of a constant “if()” statement in a “for()”
loop. 
Example 1:  
for( i ... ) {
if( CONSTANT0 ) {
DoWork0( i );
// does not affect CONSTANT0
} else {
DoWork1( i );
// does not affect CONSTANT0
}
}
The above loop should be transformed into:
if( CONSTANT0 ) {
for( i ... ) {
DoWork0( i );
}
} else {
for( i ... ) {
DoWork1( i );
}
}
This will make your inner loops tighter by avoiding repetitious
evaluation of a known “if()” control structure. Although the
branch would be easily predicted, the extra instructions and
decode limitations imposed by branching are saved, which are
usually well worth it.