Compiler Support For Branch Prediction; Example 2-10 Loop Unrolling - Intel ARCHITECTURE IA-32 Reference Manual

Architecture optimization
Table of Contents

Advertisement

IA-32 Intel® Architecture Optimization

Example 2-10 Loop Unrolling

Before unrolling:
do i=1,100
enddo
After unrolling
do i=1,100,2
enddo
In this example, a loop that executes 100 times assigns
even-numbered element and
unrolling the loop you can make both assignments each iteration,
removing one branch in the loop body.

Compiler Support for Branch Prediction

Compilers can generate code that improves the efficiency of branch
prediction in the Pentium 4 and Pentium M processors. The Intel C++
Compiler accomplishes this by:
keeping code and data on separate pages
using conditional move instructions to eliminate branches
generating code that is consistent with the static branch prediction
algorithm
inlining where appropriate
unrolling, if the number of iterations is predictable
With profile-guided optimization, the Intel compiler can lay out basic
blocks to eliminate branches for the most frequently executed paths of a
function or at least improve their predictability. Branch prediction need
not be a concern at the source level. For more information, see the
Intel® C++ Compiler User's Guide.
2-28
if (i mod 2 == 0) then a(i) = x
else a(i) = y
a(i) = y
a(i+1) = x
to every odd-numbered element. By
y
to every
x

Advertisement

Table of Contents
loading

Table of Contents