识别所有原始&在MIPS代码中插入“ NOP”(S)
这是MIPS代码:
(1) Loop : lw $2, 0($1)
(2) lw $3, 0($2) # $2
(3) add $4, $3, $2 # $3, $2
(4) sw $4, 4($2) # $4
(5) beq $4, $5, Loop # $4
用于识别代码中的所有原始依赖项, 我认为指令2和3的$ 2在指令1中的原始依赖性至$ 2。指令3中的$ 3在指令2中的原始依赖性为$ 3。最后,指令4和5中的$ 4在指令3中的原始依赖性为$ 4。i。不知道这是否正确。
问题:假设管道的处理器提供完整的转发,但没有危险检测逻辑。假设分支目标地址计算和分辨率是在ID中完成的,最后进行了最后的BEQ指令。如果需要,请在说明之间和BEQ之间插入“ NOP”,以避免危害。 [提示:如果需要两个摊位,则可以插入两个NOP]
首先,我不确定是否正确检查了所有原始的RAWS。其次,我不知道该将NOP放入代码中的位置,我只在未循环的代码中插入了NOP。请帮助我。谢谢
- 我再次编辑,感谢该评论。我不习惯堆叠
This is the MIPS code :
(1) Loop : lw $2, 0($1)
(2) lw $3, 0($2) # $2
(3) add $4, $3, $2 # $3, $2
(4) sw $4, 4($2) # $4
(5) beq $4, $5, Loop # $4
For identifying all the RAW dependencies in the code,
I think that $2 in instruction 2 and 3 have RAW dependency to $2 in instruction 1. And $3 in instruction 3 has RAW dependency to $3 in instruction 2. Lastly, $4 in instruction 4 and 5 have RAW dependency to $4 in instruction 3. I don't know if this is right or not.Question : Assume the pipelined processor provides full forwarding but no hazard detection logic. Assume branch target address calculation and resolution is done in ID and the last beq instruction is taken. Please insert "nop" between instructions and after beq if needed to avoid the hazards. [hint : you can insert two nops if you need two stall cycles]
First, I'm not sure If I checked all the RAWs right or not. and Second, I have no idea where to put nop(s) in the code, I only inserted nop in the codes that are not in loop. please help me with this. Thank you
- I edited again thanks to the comment. I'm not used to stackoverflow
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对原始危害的评估看起来不错。
对于
nop
插入假设的管道处理器,没有危险的降低,可能最好与管道表一起使用。它是一张二维表,一个轴上有时间/周期#,另一个轴上的5个管道阶段。  (哪个轴实际上并不重要。) 然后在表的单元格中放置指令号 - 表有效地告诉我们哪个说明在哪个周期##。
我们可以使用表检测原始危害:检查所有真实的数据依赖项,并查看读取指令的ID阶段(指令解码)相对于写作指令的WB阶段(写回)。
每当有数据依赖关系的情况下,读者的ID阶段比作者的WB阶段较早,那也是一种数据依赖性,也是一种原始危害。 这是原始危害的定义。
(让我们注意,数据依赖于指令(4)的$ 2作为读者和指令(1)作为作者阵容:以便(4)的ID阶段与(1)的WB阶段相同的周期。 ;这不是一个数据依赖性
。每个这样的插入都会改变时间安排,以使ID阶段与给定危险的WB阶段对齐 - 但是,请注意,NOP插入以减轻一种原始危害也将改变其他数据依赖性的时间,以便它们可能不会不会更长的原始危害。
因此,该方法是为了将一个或两个
nop
s(根据需要根据需要一个或两个)插入指令流中,减轻首先发生原始危害< /em>,然后使用新的代码序列,重做原始危害列表(并重做表),以便您仅处理保留在新修改的代码中的原始危害。&nbsp;重复直到没有危害。Your assessment of the RAW hazards look good.
For the
nop
insertion on the hypothetical pipelined processor with no hazard mitagation, probably best to work with a pipeline table.It is a two-dimensional table, with time/cycle# on one axis and the 5 pipeline stages on the other. (Which axis is which doesn't really matter.) Then in the cells of the table, put the instruction number — the table effectively tells us which instruction is in which pipeline stage at what cycle#.
We can use the table to detect RAW hazards: check all the true data dependencies and look at where the ID stage (Instruction Decode) of the reading instruction is relative to the WB stage (Write Back) of the writing instruction.
Whenever there is a data dependency where the ID stage of the reader is earlier in time than the WB stage of the writer, that is a data dependency that is also a RAW hazard. This is the definition of RAW hazard.
(Let's note that the data dependence on $2 of instruction (4) as reader and instruction (1) as writer line up: so that (4)'s ID stage is in the same cycle as (1)'s WB stage. This is a data dependency that is not a RAW hazard.)
For each RAW hazard some
nop
(s) must be inserted to accommodate the hypothetical processor. Each such insertion changes the timing so that minimally the ID stage lines up with the WB stage for a given hazard — however, let's note that nop's inserted to mitigate one RAW hazard will also change timings of the other data dependencies, such that they may no longer be RAW hazards.So, the approach then is to insert one or two
nop
s (one or two as needed) into the instruction stream, to mitigate the first occurring RAW hazard, then using the new code sequence, redo the list of RAW hazards (and redo the table), such that you only work on the RAW hazards that remain in the newly modified code. Repeat until no hazards.