我知道连续的 R-Type 指令会造成危险,例如:
add $2, $2, $1
add $2, $2, $3
但是可以连续的I-Type指令吗?例如:
addi $2, $0, 10
addi $2, $0, 5
我知道连续的 R-Type 指令会造成危险,例如:
add $2, $2, $1
add $2, $2, $3
但是可以连续的I-Type指令吗?例如:
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 时,流水线不会保证它是预期值。
考虑 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 型指令,并且考虑到这些潜在数据危险的定义,是的,I 型指令仍然存在危险。