我知道连续的R-Type指令可能会导致危险,例如:
add $2, $2, $1
add $2, $2, $3
但可以连续输入I-Type指令吗?例如:
addi $2, $0, 10
addi $2, $0, 5
答案 0 :(得分:2)
根据你的情况:
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型指令仍然存在危险。