branchPred
branchPred
Branch prediction:
• Resolve a branch hazard by predicting which path will be taken
• Proceed under that assumption
• Flush the wrong-path instructions from the pipeline & fetch the right
path if wrong
Think about:
• Is the number of branches in code changing?
• Is it getting harder to predict branch outcomes?
• Is the misprediction penalty changing?
• Is modern hardware design changing the dynamic frequency of
branches?
The rationale:
• having the prediction depend on the outcome of only 1 branch
might produce bad predictions
• some branch outcomes are correlated
example: same condition variable
if (d==0)
...
if (d!=0)
example: related condition variable
if (d==0)
b=1;
if (b==1)
Example:
Factors to consider:
• branch frequency (every 4-6 instructions)
• correct prediction rate
• 1 bit: ~ 80% to 85%
• 2 bit: ~ high 80s to low 90%
• correlated branch prediction: ~ 95%
• misprediction penalty
RISCs: 4 -7 cycles
Pentiums: larger, at least 9 cycles, 15 on average
• then have to multiply by the instruction width
• or misfetch penalty
have the correct prediction but not know the target address yet
(may also apply to unconditional branches)