我一年前学习了计算机组织类(class),现在我有一个后续类(class)“计算机体系结构”,我正在使用 John Hennessy 的书“计算机体系结构的定量方法”的第三版,我经历了MIPS ISA,但仍然需要一些帮助,您能否更详细地解释这行代码
源代码:
for(i=1000; i>0; i--)
x[i] = x[i] + s;
汇编代码:
Loop: L.D F0, 0(R1) ; F0 = array element
ADD.D F4, F0, F2 ; add scalar
S.D F4, 0(R1) ; store result
DADDUI R1, R1,# -8 ; decrement address pointer
BNE R1, R2, Loop ; branch if R1 != R2
这是作为循环展开以利用 ILP 的示例,我有一些疑问。我确实知道数组从 Mem[0+R1] 开始并向后直到 Mem[R+8](如文本中给出),有什么原因或者他们只是随机占据了这个位置?
另外,当我们添加有符号数 (-8) 时,为什么要使用 DADDUI(无符号)?
请对此进行详细概述,以便我可以跟进其余主题。 谢谢
最佳答案
内存访问按照源代码中循环指定的顺序对地址执行。
daddiu
指令足以执行此类地址算术。 “负”值以补码形式完成减法。地址既不是负数也不是正数;它们只是位模式。请参阅ISA reference了解有关 MIPS 和指令的更多信息。
The 16-bit signed immediate is added to the 64-bit value in GPR rs and the 64-bit arithmetic result is placed into GPR rt . No Integer Overflow exception occurs under any circumstances.
…
The term “unsigned” in the instruction name is a misnomer; this operation is 64-bit modulo arithmetic that does not trap on overflow. It is appropriate for unsigned arithmetic such as address arithmetic, or integer arithmetic environments that ignore overflow, such as C language arithmetic.
该示例未优化或展开。这只是源代码的直译。
关于有人可以用更简单的方式解释一下吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29327043/