IA-32 Intel® Architecture Optimization
2-26
best performance from a coding effort. An example of peeling out the
most favored target of an indirect branch with correlated branch history
is shown in Example 2-9.
Loop Unrolling
The benefits of unrolling loops are:
•
Unrolling amortizes the branch overhead, since it eliminates
branches and some of the code to manage induction variables.
•
Unrolling allows you to aggressively schedule (or pipeline) the loop
to hide latencies. This is useful if you have enough free registers to
keep variables live as you stretch out the dependence chain to
expose the critical path.
•
Unrolling exposes the code to various other optimizations, such as
removal of redundant loads, common subexpression elimination,
and so on.
Example 2-9
A Peeling Technique to Reduce Indirect Branch Misprediction
function ()
{
int n = rand();
// random integer 0 to RAND_MAX
if( !(n & 0x01) ) n = 0;
// n will be 0 half the times
if (!n) handle_0();
// peel out the most common target
// with correlated branch history
else {
switch (n) {
case 1: handle_1(); break;
// uncommon
case 3: handle_3(); break;// uncommon
default: handle_other();
// make the favored target in
// the fall-through path
}
}
}
Summary of Contents for ARCHITECTURE IA-32
Page 1: ...IA 32 Intel Architecture Optimization Reference Manual Order Number 248966 013US April 2006...
Page 220: ...IA 32 Intel Architecture Optimization 3 40...
Page 434: ...IA 32 Intel Architecture Optimization 9 20...
Page 514: ...IA 32 Intel Architecture Optimization B 60...
Page 536: ...IA 32 Intel Architecture Optimization C 22...