Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Muddssar Hussain

MS150200187
Q#1

a)

Following hazards will occur in the clock cycle.


Structural Hazards: When the same resource is used by two different
instructions at the same time.
Data Hazard: When data is used before it is ready i.e when instruction operands
are produced by prior instruction still in the pipeline.
Forwarding also called bypassing: Data hazard can be resolved by this technique
by fetching the missing data rather than waiting.
Instructions
LW R1,
0(R0)
LW R2,
4(R0)
ADD R3, R1,
R2
SW R3,
12(R0)
LW R4,
8(R0)
ADD R5, R1,
R4
SW R5,
16(R0)

1 2
I ID
F
IF

3
E
x
ID

4
ME
M
Ex

IF

ID
IF

Clock cycle
5
6
7
8
stal WB
l
stal ME
WB
l
M
stal Ex
ME
WB
l
M
stal ID
Ex
ME
l
M
IF
ID
Ex
IF

10

11

WB

ID

ME
M
Ex

IF

ID

WB
ME
M
Ex

WB
ME
M

In this code we have 13 clock cycle. There is a hazard in add instruction due to
dependence on lw instruction.
b) Instructions to avoid pipeline stalls
LW R1, 0(R0)
LW R2, 4(R0)
LW R4, 8(R0)
ADD R3, R1, R2
SW R3, 12(R0)
ADD R5, R1, R4
SW R5, 16(R0)
Both hazard will be eliminated by moving up the third lw.

12

W
B

Sequence will complete in two fewer cycles than the original version with
forwarding.
Clock cycle is 11.
C) cycles are saved after executing the reordered instructions
1. 13s clock cycle before in given instruction
LW R1, 0(R0)
LW R2, 4(R0)
ADD R3, R1, R2
SW R3, 12(R0)
LW R4, 8(R0)
ADD R5, R1, R4
SW R5, 16(R0)
2. 11s clock cycle after recording
LW R1, 0(R0)
LW R2, 4(R0)
LW R4, 8(R0)
ADD R3, R1, R2
SW R3, 12(R0)
ADD R5, R1, R4
SW R5, 16(R0)

Q#2
Ans:
(a)

Describe the behavior of this new branch prediction method in

detail. How it is different from the standard 2-bit predictor?

The behavior of this new branch prediction method and difference form
the standard 2-bit predictor is as follows:
According to the picture if the state is set to predict taken and
after that predict not taken then the state will remain to predict
taken but if again predict not taken the state will change to
predict not taken. This same as in 2-bit predictor.
Until we take predict not taken twice, it will remain into predict
taken state.
When the predict not taken branch is set and after this predict
taken, then the state will change into predict taken which is
different from 2-bit predictor in which if the state is set at not
taken then it has to be wrong for two time before its state is
changed to taken.
Therefore, in this predictor decision to be set wrong twice before
prediction is reversed to predict taken to be changed to predict
not taken. In this case of prediction not taken, decision has to be
wrong once before prediction is reversed to predict not taken to
be changed to predict taken.

(b)

Under what assumptions about the program behavior

does this type of a branch prediction leads to better


performance than a standard 2-bit predictor?
Ans:
The predictor is better when branch predict taken is set.
Under following assumptions, the prediction leads to better
performance than a standard 2-bit predictor:
If the programs have longer loop, then the predictor
performance will be good and more accurate if we set the
branch as predict taken.
The predictor performance is also good if the conditional
structures like if, go, switch etc. are used.

Q#3 Verifying Tomasulos Algorithm by Refinement:


This research paper explains that Tomasulos algorithm for outof-order execution is a refinement of the sequential instruction
execution algorithm. The Tumaslo gives a predicted value on the
completion of instruction which are consistent and correct which can
be used as refinement of SEQ. Reservation Stations are used as slots
where instructions are executed. The values are declared as predict
values until there completion. These predict values are saved in
Reservation stations.
The predicted values are extracted by executing opcode function.
The result of both techniques are consistent as it is maintained by
comparing register files after code execution. Before the value is
written in the actual register file, the exact value is presented to out of
order execution. Two sets of registers values cannot be compared as
the algorithm is out of order. So these values are compared with SEQ
values as both are produced in the same step. So the Tomasulos outof-order execution algorithm produces the predicted values consistent
and correct.
So it can be concluded that Tomasulos algorithm for our-of-order
execution can be used as a modification of the sequential instruction
execution algorithm.

You might also like