25112 Rev. 3.06 September 2005

Software Optimization Guide for AMD64 Processors

To avoid a comparison chain and its undesirable effects on branch prediction, replace the switch statement with a series of if-elsestatements, as follows:

if (a==8) {

// Sequence for a==8

}

else if (a==16) {

// Sequence for a==16

}

...

else {

// Default sequence

}

Related Information

For information on preventing branch-prediction interference at the assembly-language level, see “Density of Branches” on page 126.

Chapter 2

C and C++ Source-Level Optimizations

27

Page 43
Image 43
AMD 250 manual Related Information