2012-10-27 25 views

回答

2

鑑於你的情況:

addi $2, $0, 10 
addi $2, $0, 5 

你永遠不會遇到數據的危險,因爲你永遠不會讀的值被寫入後(寫後讀)

也許可以這樣想:

$2 = $0 + 10 
$2 = $0 + 5 

你可以看到$ 2沒有被用在s第二次計算和$ 0沒有被改變,所以沒有數據危險。

如果你做到這一點:

addi $2, $0, 10 # $2 = $0 + 10 
addi $3, $2, 5 # $3 = $2 + 5 

流水線不能保證$ 2是當它第二次計算過程中,讀預期值。

認爲lw和sw也是I型指令;

RAW 
    A Read After Write hazard occurs when, in the code as written, one instruction 
    reads a location after an earlier instruction writes new data to it, but in the 
    pipeline the write occurs after the read (so the instruction doing the read gets stale data). 
WAR 
    A Write After Read hazard is the reverse of a RAW: in the code a write occurs after a read, 
    but the pipeline causes write to happen first. 
WAW 
    A Write After Write hazard is a situation in which two writes occur out of order. We normally 
    only consider it a WAW hazard when there is no read in between; if there is, then we have a RAW 
    and/or WAR hazard to resolve, and by the time we've gotten that straightened out the WAW has 
    likely taken care of itself. 

http://www.cs.nmsu.edu/~pfeiffer/classes/473/notes/hazards.html

因爲用於讀取和寫入數據的操作是I型指令並給這些潛在的危害數據的定義,是的,我型指令可還是有危險。

+0

你確定addi不是我的指令嗎? 'addi $ 2,$ 0,10'有兩個寄存器,$ 2和$ 0以及一個16位立即數,10個。 –

+0

@ user1687682哦對不起,我誤讀了。我會編輯。 –

+0

好吧,這是有道理的,謝謝! –