Loop Unrolling; Example 2-9 A Peeling Technique To Reduce Indirect Branch Misprediction - Intel ARCHITECTURE IA-32 Reference Manual

Architecture optimization
Table of Contents

Advertisement

IA-32 Intel® Architecture Optimization
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.
Example 2-9
A Peeling Technique to Reduce Indirect Branch Misprediction
function ()
{
int n
= rand();
if( !(n & 0x01) ) n = 0;
// n will be 0 half the times
if (!n) handle_0();
else {
switch (n) {
case 1: handle_1(); break;
case 3: handle_3(); break;// uncommon
default: handle_other();
}
}
}

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.
2-26
// random integer
// peel out the most common target
// with correlated branch history
// uncommon
// make the favored target in
// the fall-through path
0 to RAND_MAX

Advertisement

Table of Contents
loading

Table of Contents