Intel ARCHITECTURE IA-32 Reference Manual page 88

Architecture optimization
Table of Contents

Advertisement

IA-32 Intel® Architecture Optimization
Assembly/Compiler Coding Rule 1. (MH impact, H generality) Arrange
code to make basic blocks contiguous and eliminate unnecessary branches.
For the Pentium M processor, every branch counts, even correctly
predicted branches have a negative effect on the amount of useful code
delivered to the processor. Also, taken branches consume space in the
branch prediction structures and extra branches create pressure on the
capacity of the structures.
Assembly/Compiler Coding Rule 2. (M impact, ML generality) Use the
and
instructions to eliminate unpredictable conditional branches
setcc
cmov
where possible. Do not do this for predictable branches. Do not use these
instructions to eliminate all unpredictable conditional branches (because using
these instructions will incur execution overhead due to the requirement for
executing both paths of a conditional branch). In addition, converting
conditional branches to
or
trades of control flow dependence for
cmovs
setcc
data dependence and restricts the capability of the out of order engine. When
tuning, note that all IA-32 based processors have very high branch prediction
rates. Consistently mispredicted are rare. Use these instructions only if the
increase in computation time is less than the expected cost of a mispredicted
branch.
Consider a line of C code that has a condition dependent upon one of the
constants:
X = (A < B) ? CONST1 : CONST2;
This code conditionally compares two values,
and
. If the condition is
A
B
true,
is set to
; otherwise it is set to
. An assembly code
X
CONST1
CONST2
sequence equivalent to the above C code can contain branches that are
not predictable if there are no correlation in the two values.
Example 2-1 shows the assembly code with unpredictable branches.
The unpredictable branches in Example 2-1 can be removed with the
use of the
instruction. Example 2-2 shows an optimized code that
setcc
does not have branches.
2-16

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ARCHITECTURE IA-32 and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF