Computer Organization and Design--计组作业习题(5.5)
计算机组成原理
Class Problem
----------------------个人作业,如果有后辈的作业习题一致,可以参考学习,一起交流,请勿直接copy
1.Assume the first branch is taken 50% of the time and the loop iterates 100 times, and forwarding for all data hazards.
add 1 2 3
beq 1 5 1
lw 6 4 1
add 3 4 5
beq 5 7 -5
2).How many cycles does the code take assuming speculate and squash where all branches are predicted fall through
No hazard:5*100-50=450
Data hazards:50*1=50
Control hazards:100*3+100*3=600
Total:4+450+50+600 = 1104
3).How many cycles does the code take assuming speculate and squash where backward branches are predicted taken and forward branches fall through?
No hazard:5*100-50=450
Data hazards:50*1=50
Control hazards:(100-50)*3+100*3=450
Total:4+450+50+450 =954
2.Assume the first branch has the pattern TTTN that repeats, and the loop is iterated 100 times
add 1 2 3
beq 1 5 1
lw 6 4 1
add 3 4 5
beq 5 7 -5
1).How many cycles does the code take assuming detect and stall for control hazards?
No hazard:5*100-100*(3/4)=425
Data hazards:100*(1/4)*1=25
Control hazards:100*3+100*3=600
Total:4+425+25+600 =1054
2).How many cycles does the code take assuming speculate and squash where backward branches are predicted taken and forward branches fall through?
No hazard:5*100-100*(3/4)=425
Data hazards:100*(1/4)*1=25
Control hazards:100*3+100*(1/4)=375
Total:4+ 425+25+375=829
3).What if a 2-bit counter BTB is used to predict each branch, how many cycles does the code take?
No hazard:5*100-100*(3/4)=425
Data hazards:100*(1/4)*1=25
Control hazards:第一个beq,除了第一次TTTN时,有3次预测失败,此后每次TTTN只有1次失败,共计失败27次
第二个beq,只有0和1两个状态预测失败,失败2次
所以:(27+2)*3 = 87
Total:4+ 425+25+87=541