Example 2-1 Assembly Code With An Unpredictable Branch; Example 2-2 Code Optimization To Eliminate Branches - Intel ARCHITECTURE IA-32 Reference Manual

Architecture optimization
Table of Contents

Advertisement

Example 2-1
Assembly Code with an Unpredictable Branch
cmp
jge
mov
jmp
L30:
mov
L31:
Example 2-2
Code Optimization to Eliminate Branches
xor
ebx, ebx
cmp
A, B
setge bl
sub
ebx, 1
and
ebx, CONST3
add
ebx, CONST2
See Example 2-2. The optimized code sets
and B. If A is greater than or equal to B,
decreased and "
sets
to either zero or the difference of the values. By adding
ebx
back to
ebx
zero, the last instruction can be deleted.
Another way to remove branches on Pentium II and subsequent
processors is to use the
shows changing a
eliminating a branch. If the
will be moved to
representative of an unpredictable branch.
A, B
L30
ebx, CONST1
L31
ebx, CONST2
; clear ebx (X in the C code)
; When ebx = 0 or 1
; OR the complement condition
; ebx=11...11 or 00...00
; CONST3 = CONST1-CONST2
; ebx=CONST1 or CONST2
-ed" with the difference of the constant values. This
and
, the correct value is written to
and
cmov
and branch instruction sequence using
test
test
. This branch is data-dependent, and is
eax
General Optimization Guidelines
; condition
; conditional branch
; ebx holds X
; unconditional branch
to zero, then compares A
ebx
is set to one. Then
ebx
. When
ebx
instructions. Example 2-3
fcmov
sets the equal flag, the value in
2
is
ebx
CONST2
is equal to
CONST2
and
cmov
ebx
2-17

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?

Questions and answers

Subscribe to Our Youtube Channel

Table of Contents