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
}
}
}
Содержание ARCHITECTURE IA-32
Страница 1: ...IA 32 Intel Architecture Optimization Reference Manual Order Number 248966 013US April 2006...
Страница 220: ...IA 32 Intel Architecture Optimization 3 40...
Страница 434: ...IA 32 Intel Architecture Optimization 9 20...
Страница 514: ...IA 32 Intel Architecture Optimization B 60...
Страница 536: ...IA 32 Intel Architecture Optimization C 22...
Страница 560: ...IA 32 Intel Architecture Optimization E 14...