Load后的指令如何执行?
How does instruction after Load, execute?
管道中有 5 个阶段。
IF - Instruction fetch
ID - Instruction Decode, read the register
EX - On a memeory reference add up base and offset,
and for arithmetic instruction do the math.
MEM - If load or store access memory
WB - Place the result in appropriate register.
I1 : R0 <- M[loc] IF | ID | EX | MEM | WB |
I2 - R0 <- R0 + R0 | IF | ID | EX | MEM | WB |
I3 - R2 <- R2 - R0 | IF | ID | EX | MEM | WB |
认为 "Operand Forwarding " 已被使用。
解决方案说:-
Instruction I1
is a Load
instruction. So the next instruction ( I2
) cannot fetch until I1
finishes its EXE
stage.
但我认为:在MEM
阶段,处理器访问内存并选择所需的单词。并在 WB
阶段更新注册表。
因此,在 MEM
阶段之前,处理器控制内存,因此 I2
将在 I1
的 MEM
之后开始获取数据。
哪个是正确的?
没有给出阶段的描述,这是根据我的知识写的。
约定:
I denote a generic instruction.
I1, I2, I3, ... denote specific instructions.
S denote a generic stage of the pipeline.
IF, ID, EX, MEM, WB denote a specific stages of the pipeline.
I.S denote the cycle in which the instruction I was in the stage S.
指令 I2 需要 R0 但该寄存器不会从 I1 就绪直到 I1.WB 完成,假设是一个基本的管道。
在存在操作数转发的情况下,I2 可以在 I1 将结果写回寄存器文件时读取结果,即 I1.WB.
由于操作数是在ID阶段读取的,I2.ID和I1.WB必须同时发生。
这意味着 I2.IF 必须与 I1.MEM 同时发生。
现在您对 CPU 在同一时钟内执行两次读取(一次用于指令获取,一次用于加载)的能力持怀疑态度。
非常简单的 CPUs 实际上会在这种冲突上停止(在你的例子中 I2.IF 会发生在 I1.WB).
避免停顿的最简单方法是 Harvard architecture,其中 CPU 从不同的内存中获取指令。
哈佛架构 has been modified 通过使用缓存和预取数据和指令。
在这种情况下,只有当加载和指令提取都需要访问内存(而不是高速缓存)时才会发生停顿。
现代桌面架构具有 L1 数据缓存,可以一次处理多个访问,CPU 与它们紧密耦合,因此可以同时执行两个或更多 loads/stores时间,与从 L1 指令缓存加载并行。
最后,一些现代的 CPU 一次解码了一条以上的指令,从而减轻了停顿问题(但没有消除它)。
不过,缓存在避免停顿方面提供了最大的好处。
管道中有 5 个阶段。
IF - Instruction fetch
ID - Instruction Decode, read the register
EX - On a memeory reference add up base and offset,
and for arithmetic instruction do the math.
MEM - If load or store access memory
WB - Place the result in appropriate register.
I1 : R0 <- M[loc] IF | ID | EX | MEM | WB |
I2 - R0 <- R0 + R0 | IF | ID | EX | MEM | WB |
I3 - R2 <- R2 - R0 | IF | ID | EX | MEM | WB |
认为 "Operand Forwarding " 已被使用。
解决方案说:-
Instruction
I1
is aLoad
instruction. So the next instruction (I2
) cannot fetch untilI1
finishes itsEXE
stage.
但我认为:在MEM
阶段,处理器访问内存并选择所需的单词。并在 WB
阶段更新注册表。
因此,在 MEM
阶段之前,处理器控制内存,因此 I2
将在 I1
的 MEM
之后开始获取数据。
哪个是正确的?
没有给出阶段的描述,这是根据我的知识写的。
约定:
I denote a generic instruction.
I1, I2, I3, ... denote specific instructions. S denote a generic stage of the pipeline.
IF, ID, EX, MEM, WB denote a specific stages of the pipeline.
I.S denote the cycle in which the instruction I was in the stage S.
指令 I2 需要 R0 但该寄存器不会从 I1 就绪直到 I1.WB 完成,假设是一个基本的管道。
在存在操作数转发的情况下,I2 可以在 I1 将结果写回寄存器文件时读取结果,即 I1.WB.
由于操作数是在ID阶段读取的,I2.ID和I1.WB必须同时发生。
这意味着 I2.IF 必须与 I1.MEM 同时发生。
现在您对 CPU 在同一时钟内执行两次读取(一次用于指令获取,一次用于加载)的能力持怀疑态度。
非常简单的 CPUs 实际上会在这种冲突上停止(在你的例子中 I2.IF 会发生在 I1.WB).
避免停顿的最简单方法是 Harvard architecture,其中 CPU 从不同的内存中获取指令。
哈佛架构 has been modified 通过使用缓存和预取数据和指令。
在这种情况下,只有当加载和指令提取都需要访问内存(而不是高速缓存)时才会发生停顿。
现代桌面架构具有 L1 数据缓存,可以一次处理多个访问,CPU 与它们紧密耦合,因此可以同时执行两个或更多 loads/stores时间,与从 L1 指令缓存加载并行。
最后,一些现代的 CPU 一次解码了一条以上的指令,从而减轻了停顿问题(但没有消除它)。
不过,缓存在避免停顿方面提供了最大的好处。