Control Hazard
Control Hazard
48 or $13, $2, $6
...
72 lw $4, 50($7)
Clock cycle 4
Instruction at location 72 being fetched and
Single bubble or nop instruction in the pipeline as a result of
the taken branch
DYNAMIC BRANCH PREDICTION
The steady-state prediction behavior will mispredict on the first and last
loop iterations
Mis-predicting the last iteration is inevitable since the prediction bit will
indicate taken, as the branch has been taken nine times in a row at that
point
The mis-prediction on the first iteration happens because the bit is
flipped on prior execution of the last iteration of the loop, since the
branch was not taken on that exiting iteration
LOOP AND PREDICTION (2)
The prediction accuracy for this branch that is taken 90% of
the time is only 80%
Two incorrect predictions and eight correct ones
Ideally, the accuracy of the predictor would match the taken
branch frequency for these highly regular branches
2-BIT PREDICTION SCHEME
To remedy this weakness, 2-bit prediction schemes are often used
In a 2-bit scheme, a prediction must be wrong twice before it is
changed
Assume starting with predict taken
Prediction is correct so it loop
within predict taken for nine
branches
When tenth branch comes
prediction turn out to be wrong
Though wrong it wont change the
decision
Since changing decision requires
two consecutive wrong prediction
When it come back to 1st decision
in a loop, prediction found to be
correct
So prediction accuracy is 90 %
2-BIT PREDICTION SCHEME