gpt4 book ai didi

assembly - 为什么 ARM7 上 MUL 表达式的前两个参数不能相同?

转载 作者:行者123 更新时间:2023-12-02 04:17:06 25 4
gpt4 key购买 nike

我一直在帮助实验室进行 ARM7 汇编语言类(class),今天遇到一个问题,学生输入了以下表达式:

MUL R0, R0, R1

代码未编译。解决方案是将表达式更改为:

MUL R0, R1, R0

即MUL 的前两个参数不能是同一个寄存器。我已经知道这一点,因为它是 ARM 文档的一部分: http://infocenter.arm.com/help/topic/com.arm.doc.dui0489i/DUI0489I_arm_assembler_reference.pdf

学生很高兴他们的问题得到了解决,但我很沮丧,因为我不知道为什么 ARM7 要求这样传递参数。我认为这可能与乘法器移位和加法时用于存储中间值的寄存器之一有关,但我什至不确定乘法在 ARM 上是否是这样工作的(事实上,我相当清楚)当然不是)。为什么参数的顺序在这里如此重要?

最佳答案

“在 ARMv6 之前的架构中,Rn 必须与 Rd 不同”这一事实表明,这是原始三级 ARM 流水线中如何实现乘法的设计限制。 ARMv6 之前是指采用 ARM7 或更早设计的 CPU,这些 CPU 都使用简单的三级管道。与大多数指令不同,乘法需要多个周期来执行,并且根据指令集限制,您的怀疑似乎是正确的,目标寄存器Rd在每个周期都会被修改以计算结果。

论文Verifying ARM6 Multiplication by Anthony Fox ,通过图 4(下面重新格式化以适应 Stack Exchange 标记的限制)显示了在 ARM6 内核执行乘法指令期间如何修改 Rd 来支持这一点:

  • t3

    • Fetch an instruction
    • Increment the program counter
    • Set mul1 to reg[Rs]
    • Set borrow to false
    • Set count1 to zero


    • Set reg[Rd] to reg[Rn] if accumulate, otherwise zero

    • Set mul to mul1[1:0]
    • Set mul2 to mul1[31:2]
    • Set borrow2 to borrow
    • Set mshift to MSHIFT2(borrow,mul,count1)
  • tn

    • Set alub to reg[Rm] shifted left by mshift
    • Set alua to reg[Rd]
    • Set mul1 to mul2[29:0]
    • Set borrow to mul[1]
    • Set count1 to mshift[4:1] + 1


    • Set reg[Rd] to ALU6<sup>*</sup>(borrow2,mul,alua,alub)

    • Set mul to mul1[1:0]
    • Set mul2 to mul1[31:2]
    • Set borrow2 to borrow
    • Set mshift to MSHIFT2(borrow,mul,count1)
    • Update NZC flags of CPSR (if S flag set)
    • If the last iteration then decode the next instruction

Fig. 4: ARM6 implementation of the multiply instructions. Each cycle is split into two phases. The tn cycle is repeated until MULX(mul2,borrow,mshift) is true. Register Rd is not updated when Rd is equal to Rm or fifteen.

reg[Rd]在初始设置周期 t3 和重复 tn 周期期间进行修改,结果将是垃圾如果 Rd == Rm因为步骤“将 alua 设置为 reg[Rm] 左移 mshift”期望读取 Rm 的原始未修改值,而不是存储在 Rd 中的当前中间值>.

某些 ARM7 CPU 有一个“快速乘法器”,每个周期处理 8 位,而不是如上所述的每个周期处理 2 位,但它似乎也会在计算过程中修改寄存器。

关于assembly - 为什么 ARM7 上 MUL 表达式的前两个参数不能相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33046876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com