【发布时间】:2012-10-27 09:35:25
【问题描述】:
我知道连续的 R-Type 指令会造成危险,例如:
add $2, $2, $1
add $2, $2, $3
但是可以连续的I-Type指令吗?例如:
addi $2, $0, 10
addi $2, $0, 5
【问题讨论】:
标签: mips pipeline instruction-set
我知道连续的 R-Type 指令会造成危险,例如:
add $2, $2, $1
add $2, $2, $3
但是可以连续的I-Type指令吗?例如:
addi $2, $0, 10
addi $2, $0, 5
【问题讨论】:
标签: mips pipeline instruction-set
鉴于您的情况:
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 型指令仍然存在危险。
【讨论】:
addi $2, $0, 10 有两个寄存器,$2 和 $0 和一个 16 位立即数,10。