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(1-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.
1-bit Prediction; is the simplest way to prediction. Once you
misprediction, then it is changed at next time.
2-bit Prediction is used as better solution.
4. Dynamic Branch Prediction(1-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;
}
…
BT BNT
not taken
taken
taken not taken
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
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 BN
1 0
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
BT BNT
not taken
taken
taken not taken
Our current state is BT
and branch is not taken
at if condition so we can
decade next prediction
state is Branch Not
Taken. According to
graph at right, if our
state is Branch Taken
and state is not taken,
our prediction is Branch
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 BNT BT
1 0 0
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
BT BNT
not taken
taken
taken not taken
Our current state is BNT
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 Not Taken and
state is taken, our
prediction is Branch
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 BNT BT BNT
1 0 0 0
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
BT BNT
not taken
taken
taken not taken
Our current state is BT
and branch is not taken
at if condition so we can
decade next prediction
state is Branch Not
Taken. According to
graph at right, if our
state is Branch Taken
and state is not taken,
our prediction is Branch
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 BNT BT BNT BT
1 0 0 0 0
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
BT BNT
not taken
taken
taken not taken
Our current state is BNT
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 Not Taken and
state is taken, our
prediction is Branch
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 BNT BT BNT BT BNT
1 0 0 0 0 0
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
BT BNT
not taken
taken
taken not taken
Our current state is BT
and branch is not taken
at if condition so we can
decade next prediction
state is Branch Not
Taken. According to
graph at right, if our
state is Branch Taken
and state is not taken,
our prediction is Branch
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 BNT BT BNT BT BNT BT
1 0 0 0 0 0 0
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
BT BNT
not taken
taken
taken not taken
Our current state is BNT
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 Not Taken and
state is taken, our
prediction is Branch
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 BNT BT BNT BT BNT BT BT
1 0 0 0 0 0 0 1
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
BT BNT
not taken
taken
taken not taken
Our current state is BT
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 and state
is taken, our prediction is
Branch 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 BNT BT BNT BT BNT BT BT BT
1 0 0 0 0 0 0 1 1
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
BT BNT
not taken
taken
taken not taken
Our current state is BT
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 and state
is taken, our prediction is
Branch 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 BNT BT BNT BT BNT BT BT BT BNT
1 0 0 0 0 0 0 1 1 0
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
BT BNT
not taken
taken
taken not taken
Our current state is BT
and branch is not taken
at if condition so we can
decade next prediction
state is Branch Not
Taken. According to
graph at right, if our
state is Branch Taken
and state is not taken,
our prediction is Branch
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 BNT BT BNT BT BNT BT BT BT BNT
1 0 0 0 0 0 0 1 1 0 1
…
int a = 3;
int i = 0;
for(i =0;i<5;i++){
if(i == a)
a=0;
}
…
At the end;
Our 4 predictions are
correct!