IBM SA14-2339-04 Personal Computer User Manual


 
2-26 PPC405 Core User’s Manual
Table 2-7 lists specific BO field contents, and the resulting actions;
z
represents a mandatory value of
0, and
y
is a branch prediction option discussed in “Branch Prediction.”
2.7.5 Branch Prediction
Conditional branches present a problem to the instruction fetcher. A branch might be taken. The
branch EXU attempts to predict whether or not a branch is taken before all information necessary to
determine the branch direction is available. This decision is called a
branch prediction
. The fetcher
can then prefetch instructions starting at the predicted branch target address. If the prediction is
correct, time is saved because the branched-to instruction is available in the instruction queue.
Otherwise, the instruction pipeline stalls while the correct instruction is fetched into the instruction
queue. To be effective, branch prediction must be correct most of the time.
The PowerPC Architecture enables software to reverse the default branch prediction, which is defined
as follows:
Predict that the branch is to be taken if ((BO[0]
BO[2])
s
)= 1
where
s
is the sign bit of the displacement for conditional branch (bc) instructions, and 0 for bclr and
bcctr instructions.
(BO[0]
BO[2]) = 1 only when the conditional branch tests nothing (the “branch always” condition).
Obviously, the branch should be predicted taken for this case.
If the branch tests anything, (BO[0]
BO[2]) = 0, and
s
entirely controls the prediction. The default
prediction for this case was decided by considering the relative form of bc, which is commonly used at
the end of loops to control the number of times that a loop is executed. The branch is taken every time
the loop is executed except the last, so it is best if the branch is predicted taken. The branch target is
the beginning of the loop, so the branch displacement is negative and
s
=1.
If branch displacements are positive (
s
= 0), the branch is predicted not taken. If the branch
instruction is any form of bclr or bcctr except the “branch always” forms, then
s
= 0, and the branch is
predicted not taken.
There is a peculiar consequence of this prediction algorithm for the absolute forms of bc (bca and
bcla). As described in “Unconditional Branch Target Addressing Options” on page 2-24, if the
algebraic sign of the displacement is negative (
s
= 1), the branch target address is in high memory. If
Table 2-7. Conditional Branch BO Field
BO
Value Description
0000
y
Decrement the CTR, then branch if the decremented CTR 0 and CR[BI]=0.
0001
y
Decrement the CTR, then branch if the decremented CTR = 0 and CR[BI] = 0.
001
zy
Branch if CR[BI] = 0.
0100
y
Decrement the CTR, then branch if the decremented CTR 0 and CR[BI] = 1.
0101
y
Decrement the CTR, then branch if the decremented CTR=0 and CR[BI] = 1.
011
zy
Branch if CR[BI] = 1.
1
z
00
y
Decrement the CTR, then branch if the decremented CTR 0.
1
z
01
y
Decrement the CTR, then branch if the decremented CTR = 0.
1
z
1
zz
Branch always.