Computer Organization and Design--计组作业习题(5)
Computer Organization and Design
----------------------个人作业,如果有后辈的作业习题一致,可以参考学习,一起交流,请勿直接copy
Problem 1. Pipelining: Control Hazards
Consider the following code:
Assume the pipeline is empty at the beginning
lw 0 1 init 1
lw 0 2 endval 2
lw 0 4 neg5 3
loop beq 1 2 endl 4
lw 0 3 three 5
add 3 1 1 6
add 4 1 1 7
beq 0 0 loop 8
endl halt 9
init .fill 7
endval .fill -1
three .fill 3
neg5 .fill -5
1. Simple branch analysis (7 points)
i) In the absence of stalls for hazards, how many cycles would this code take?
i.e. Compute cycles required if control and data hazards never required and stalls
Loop循环4次,语句4执行4+1次,5/6/7/8各执行4次; 共执行3+(5*4+1)+1=25条语句
Total cycles:25+ 5 - 1 = 29
ii) Considering the effect of both data and control hazards.
How many cycles will this code take if each branch is predicted as taken?
a.第一个beq指令执行5次跳转1次,第二条beq指令执行4次跳转4次,故if each branch is predicted as taken,第一个beq指令预测失败4次,需要增加4*3=12 cycle ;
b.指令5与6 data hazard,采用forward,增加1个cycle,且循环了4次,因此,需要增加1*4=4个cycle;
Total cycles:12+4+29=45 cycle
iii) Considering the effect of both data and control hazards.
How many cycles will this code take if each branch is predicted as not taken?
第一个beq指令预测失败1次,第二个beq指令预测失败4次,需要增加5*3=15 个 cycle,指令5与6data hazard 需要增加1个cycle,执行4次,故需要增加4个cycle;
Total cycles:29+15+4=48cycle
2. Using a branch predictor (7 points)
Using the following FSM for branch prediction, complete each table using the above code:
Assume each branch starts at Weakly Not Taken
i) beq 1 2 endl
|
1 |
2 |
3 |
4 |
5 |
6 |
Predicated |
WNT |
SNT |
SNT |
SNT |
SNT |
WNT |
Actual |
NT |
NT |
NT |
NT |
T |
NA |
How many mispredictions were made?
1 misprediction were made
ii) beq 0 0 loop
|
1 |
2 |
3 |
4 |
5 |
Predicated |
WNT |
WT |
ST |
ST |
ST |
Actual |
T |
T |
T |
T |
NA |
How many mispredictions were made?
1 misprediction were made
iii) If each of the above branches where predicted in this way, how many cycles would it take to execute the above code? Consider the effect of both data and control hazards. Ignore any delays that could be needed to carry out the prediction (Correct prediction = 0 stalls, Incorrect prediction = 3 stalls)
共有2次预测失败,需要增加2 * 3=6 个cycle,第4个lw处data hazard需要增加1个cycle,循环4次,故需要增加4个cycle;
Total cycles:29+4+6=39