作者:
g1990822 (什麼東西?!)
2018-05-20 18:34:59最近兩天在寫白算盤的題目,遇到了幾題問題
因為在網路上找到的解答和我的想法不太一樣,
不確定是不是解答有誤還是我的觀念錯誤,希望版友可以幫忙指正
第一題:(來自白算盤第五版4.9題)題目給三個指令:
指令1: or r1,r2,r3
指令2: or r2,r1,r4
指令3: or r1,r1,r2
其中4.9.5題:Add nop instructions to this code to eliminate hazards
if there is ALU-ALU forwarding only
( no forwarding from MEM to EX stage)
我在網路上找到的解答:
or r1,r2,r3
or r2,r1,r4
or r1,r1,r2
也就是解答似乎認為沒有任何的Data hazard,所以沒有插入任何nop
而我的問題是,在有ALU-ALU forwarding的情況下,指令1,2的data hazard(r1)
和指令2,3的data hazard(r2)可以被解決,應該沒有問題
但是指令1,3也有data hazard(r1)不是嗎?而此data hazard只能夠用
forwarding from MEM to EX stage解決吧?(因為相隔一個指令)
但是題目說""no ""forwarding from MEM to EX stage
因此不是應該要在中間插入一個nop,
讓第三個指令在第一個指令於WB stage時才能ID嗎?
像是: 指令1 IF ID EX MEM WB
指令2 IF ID EX MEM WB
nop IF ID EX MEM WB
指令3 IF ID EX MEM WB
這樣的形式,才能讓指令3讀到正確的r1的值,但是這樣的話,
指令2的r2又只能藉由forwarding from MEM to EX stage給指令三...
我想到的是要:再插入一個nop變成:
C1 C2 C3 C4 C5 C6 C7 C8 C9
指令1 IF ID EX MEM WB
指令2 IF ID EX MEM WB
nop IF ID EX MEM WB
nop IF ID EX MEM WB
指令3 IF ID EX MEM WB
這樣一來指令3可以在C6時讀到指令1,2已經寫入的r1與r2的正確值
但是不知道這樣想法對不對..
第二題:(來自白算盤第五版4.15題)
In this exercise,assume that the breakdown of dynamic instructions into
various instruction categories is as follows:
R-Type BEQ JMP LW SW
40% 25% 5% 25% 5%
Also , assume the following btanch predictor accuracies:
Always-Taken Always-Not-Taken 2-Bit
45% 55% 85%
其中4.15.1小題: Stall cycles due to mispredicted branches increase the CPI
What is the extra CPI due to mispredicted branches with the
always-taken predictor?Assume that branch outcomes are
determinid in the EX stage,that there are no hazards,and
no delay slots are used.
網路上解答: 3*(1-0.45)*0.25=0.41
我的問題是為什麼是"3"*(1-0.45)*0.25
而不是:"2"*(1-0.45)*0.25呢?
因為題目說是在EX stage決定要不要branch,
所以若猜錯的penalty不是應該是兩個CLK而已嗎?
以上兩個問題再麻煩大大們幫解答,謝謝了!