有人可以用更简单的方式解释一下吗?

标签 c assembly mips cpu-architecture loop-unrolling

我一年前学习了计算机组织类(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/

相关文章:

c - 从不兼容的指针类型传递参数 1 of 'recievematrix'

C转MIPS的麻烦

algorithm - 仅通过加法计算指数

c - 为什么我的线程不在程序完成之前将其结果存储在数组中?

c++ - 为有限范围的 N 个整数数组实现查找数组

c - 如何使用指针向函数中的数组添加项目?

assembly - 我不明白 SBC 是怎么回事

linux - 为什么我无法在自修改代码中单步执行 aeskeygenassist 指令?

c++ - STL find 的性能优于手工循环

python - 你如何在 Python 中模拟硬件?