在MIPS中,I型指令会导致危险吗?

在MIPS中,I型指令会导致危险吗?,mips,pipeline,instruction-set,Mips,Pipeline,Instruction Set,我知道连续的R型指令可能会导致危险,例如: add $2, $2, $1 add $2, $2, $3 addi $2, $0, 10 addi $2, $0, 5 但是连续的I型指令可以吗?例如: add $2, $2, $1 add $2, $2, $3 addi $2, $0, 10 addi $2, $0, 5 鉴于你的情况: addi $2, $0, 10 addi $2, $0, 5 您永远不会遇到数据危险,因为您永远不会在写入值后读取该值(写入后读取) 也许可以这样想:

我知道连续的R型指令可能会导致危险,例如:

add $2, $2, $1
add $2, $2, $3
addi $2, $0, 10
addi $2, $0, 5
但是连续的I型指令可以吗?例如:

add $2, $2, $1
add $2, $2, $3
addi $2, $0, 10
addi $2, $0, 5
鉴于你的情况:

addi $2, $0, 10 
addi $2, $0, 5
您永远不会遇到数据危险,因为您永远不会在写入值后读取该值(写入后读取)

也许可以这样想:

$2 = $0 + 10
$2 = $0 + 5
您可以看到$2未在第二次计算中使用,并且$0未被更改,因此没有数据危险

如果要这样做:

addi $2, $0, 10 # $2 = $0 + 10
addi $3, $2, 5  # $3 = $2 + 5
在第二次计算期间读取$2时,管道将不能保证$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.


鉴于读取和写入数据的操作是I型指令,并且给出了这些潜在数据危险的定义,是的,I型指令仍然可能存在危险。

您确定addi不是I型指令吗
addi$2、$0、10
有两个寄存器,$2和$0以及一个16位立即数10。