Dynamic Branch Prediction, on the other hand, uses information about taken or not taken branches gathered at run-time to predict the outcome of a branch. So, the current situation depends on past behaviour of branches.
2. Dynamic Branch Prediction(2-bit Prediction)
Dynamic Branch Prediction; the prediction changes while program
behavior changes.
It differs from Static Branch Prediction through gather level. The
prediction is gathered before the program execution at SBP but it is gathered
at run-time at DBP.
2-bit Prediction; is better than 1-bit to prediction. If you misprediction at
twice, it is changed at next time.
3. Dynamic Branch Prediction(2-bit Prediction)
BT BT
not taken
taken
taken
2-bit Prediction Scheme;
BNT BNT
taken
not taken
not taken
not taken taken
4. Dynamic Branch Prediction(2-bit Prediction)
Let’s evaluate below example;
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
Assume that Initial State is
Branch Taken
5. Dynamic Branch Prediction(1-bit Prediction)
For
i=0
If For
i=1
If For
i=2
If For
i=3
If For
i=4
If For
i=5
Result BT BNT BT BNT BT BN
T
BT BT BT BNT BNT
Prediction BT BT
1
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
Our inital state is BT and
branch is taken at for
loop so we can decade
next prediction state is
Branch Taken. We
decade this prediction
through graph at right. If
your state is BT and
result is taken, the
prediction for is
statement is BT
BT BT
not taken
taken
taken
BNT BNT
taken
not taken
not taken
not taken
6. Dynamic Branch Prediction(1-bit Prediction)
For
i=0
If For
i=1
If For
i=2
If For
i=3
If For
i=4
If For
i=5
Result BT BNT BT BNT BT BN
T
BT BT BT BNT BNT
Prediction BT BT BT
1 0
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
Our current state is BT
(strongly) and branch is
not taken at if condition
so we can decade next
prediction state is Branch
Taken. According to
graph at right, if our
state is Branch Taken
(strongly) and state is
not taken, our prediction
is Branch Taken
BT BT
not taken
taken
taken
BNT BNT
taken
not taken
not taken
not taken
7. Dynamic Branch Prediction(1-bit Prediction)
For
i=0
If For
i=1
If For
i=2
If For
i=3
If For
i=4
If For
i=5
Result BT BNT BT BNT BT BN
T
BT BT BT BNT BNT
Prediction BT BT BT BT
1 0 1
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
Our current state is BT
and branch is taken at
for loop so we can
decade next prediction
state is Branch Taken.
According to graph at
right, if our state is
Branch Taken and state
is taken, our prediction is
Branch Taken
BT BT
not taken
taken
taken
BNT BNT
taken
not taken
not taken
8. Dynamic Branch Prediction(1-bit Prediction)
For
i=0
If For
i=1
If For
i=2
If For
i=3
If For
i=4
If For
i=5
Result BT BNT BT BNT BT BN
T
BT BT BT BNT BNT
Prediction BT BT BT BT BT
1 0 1 0
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
Our current state is BT
(strongly) and branch is
not taken at if condition
so we can decade next
prediction state is Branch
Taken. According to
graph at right, if our
state is Branch Taken
(strongly) and state is
not taken, our prediction
is Branch Taken
BT BT
not taken
taken
taken
BNT BNT
taken
not taken
not taken
9. Dynamic Branch Prediction(1-bit Prediction)
For
i=0
If For
i=1
If For
i=2
If For
i=3
If For
i=4
If For
i=5
Result BT BNT BT BNT BT BN
T
BT BT BT BNT BNT
Prediction BT BT BT BT BT BT
1 0 1 0 1
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
Our current state is BT
and branch is taken at
for loop so we can
decade next prediction
state is Branch Taken.
According to graph at
right, if our state is
Branch Taken and state
is taken, our prediction is
Branch Taken
BT BT
not taken
taken
taken
BNT BNT
taken
not taken
not taken
10. Dynamic Branch Prediction(1-bit Prediction)
For
i=0
If For
i=1
If For
i=2
If For
i=3
If For
i=4
If For
i=5
Result BT BNT BT BNT BT BN
T
BT BT BT BNT BNT
Prediction BT BT BT BT BT BT BT
1 0 1 0 1 0
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
Our current state is BT
(strongly) and branch is
not taken at if condition
so we can decade next
prediction state is Branch
Taken. According to
graph at right, if our
state is Branch Taken
(strongly) and state is
not taken, our prediction
is Branch Taken
BT BT
not taken
taken
taken
BNT BNT
taken
not taken
not taken
11. Dynamic Branch Prediction(1-bit Prediction)
For
i=0
If For
i=1
If For
i=2
If For
i=3
If For
i=4
If For
i=5
Result BT BNT BT BNT BT BN
T
BT BT BT BNT BNT
Prediction BT BT BT BT BT BT BT BT
1 0 1 0 1 0 1
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
Our current state is BT
and branch is taken at
for loop so we can
decade next prediction
state is Branch Taken.
According to graph at
right, if our state is
Branch Taken and state
is taken, our prediction is
Branch Taken
BT BT
not taken
taken
taken
BNT BNT
taken
not taken
not taken
12. Dynamic Branch Prediction(1-bit Prediction)
For
i=0
If For
i=1
If For
i=2
If For
i=3
If For
i=4
If For
i=5
Result BT BNT BT BNT BT BN
T
BT BT BT BNT BNT
Prediction BT BT BT BT BT BT BT BT BT
1 0 1 0 1 0 1 1
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
Our current state is BT
(strongly) and branch is
taken at if condition so
we can decade next
prediction state is Branch
Taken. According to
graph at right, if our
state is Branch Taken
(strongly) and state is
taken, our prediction is
Branch Taken
BT BT
not taken
taken
taken
BNT BNT
taken
not taken
not taken
13. Dynamic Branch Prediction(1-bit Prediction)
For
i=0
If For
i=1
If For
i=2
If For
i=3
If For
i=4
If For
i=5
Result BT BNT BT BNT BT BN
T
BT BT BT BNT BNT
Prediction BT BT BT BT BT BT BT BT BT BT
1 0 1 0 1 0 1 1 1
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
Our current state is BT
and branch is taken at
for loop so we can
decade next prediction
state is Branch Taken.
According to graph at
right, if our state is
Branch Taken and state
is taken, our prediction is
Branch Taken
BT BT
not taken
taken
taken
BNT BNT
taken
not taken
not taken
14. Dynamic Branch Prediction(1-bit Prediction)
For
i=0
If For
i=1
If For
i=2
If For
i=3
If For
i=4
If For
i=5
Result BT BNT BT BNT BT BN
T
BT BT BT BNT BNT
Prediction BT BT BT BT BT BT BT BT BT BT BT
1 0 1 0 1 0 1 1 1 0
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
Our current state is BT
(strongly) and branch is
not taken at if condition
so we can decade next
prediction state is Branch
Taken. According to
graph at right, if our
state is Branch Taken
(strongly) and state is
not taken, our prediction
is Branch Taken
BT BT
not taken
taken
taken
BNT BNT
taken
not taken
not taken
15. Dynamic Branch Prediction(1-bit Prediction)
For
i=0
If For
i=1
If For
i=2
If For
i=3
If For
i=4
If For
i=5
Result BT BNT BT BNT BT BN
T
BT BT BT BNT BNT
Prediction BT BT BT BT BT BT BT BT BT BT BT
1 0 1 0 1 0 1 1 1 0 0
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
At the end;
Our 6 predictions are
correct!