IA-32 Intel® Architecture Optimization
2-28
In this example, a loop that executes 100 times assigns
x
to every
even-numbered element and
y
to every odd-numbered element. By
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
Example 2-10 Loop Unrolling
Before unrolling:
do i=1,100
if (i mod 2 == 0) then a(i) = x
else a(i) = y
enddo
After unrolling
do i=1,100,2
a(i) = y
a(i+1) = x
enddo
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...