某些裸 MIPS 指令是否比其他指令更快?引起我兴趣的问题是将寄存器乘以 2 的幂。
假设 $t0 有一个不会溢出的数字。如果我想将该寄存器乘以 8,以下之间是否存在可量化的性能差异:
3 位 sll:
sll $t0, $t0,3
使用 mul 命令(假设 $t8 的值为 8):
mul $t0, $t0,$t8
或使用 mult 命令?
mult $t0, $t0,$t8
每个示例都包含一条指令,但我不知道一个指令是否比另一个指令更快。直觉让我认为 mul 比 mult 更快,因为没有将无关位存储到 HI 中(这是正确的吗?)
或者,有人知道有关汇编中的单独指令速度(MIPS 或其他)主题的任何文章/网页吗?我想象不同的指令由不同的电路/硬件组成,并且每条指令执行的时间不同,但我似乎无法在网上找到任何有关此的资源。
我对 MIPS/汇编非常陌生,因此请原谅我没有运行计时示例(或者在上面的示例中可能使用了不正确的语法)。
最佳答案
面向程序员的 MIPS32TM 架构
第二卷:MIPS32TM 指令集,
mul/mult 指令'
:
Programming Notes:
In some processors the integer multiply operation may proceed asynchronously and allow other CPU instructions to
execute before it is complete. An attempt to read LO or HI before the results are written interlocks until the results are
ready. Asynchronous execution does not affect the program result, but offers an opportunity for performance
improvement by scheduling the multiply so that other instructions can execute in parallel.
Programs that require overflow detection must check for it explicitly.
Where the size of the operands are known, software should place the shorter operand in GPR rt. This may reduce the
latency of the instruction on those processors which implement data-dependent instruction latencies.
所以,是的,乘以任意数字是 MIPS 中极少数比其他指令需要更多周期的事情之一。
手册指定 mul
的方式,这是可能的将其实现为 mult
然后是 mflo
,在这种情况下,mul
和 mult
显然具有完全相同的时序特点。
它可能确实是一条单独的指令,在这种情况下它可能更快(也许至少出于功耗原因避免计算高半部分),但我怀疑很少有硬件实现这样做。
乘法/除法单元是 MIPS 架构中较差的方面之一。
关于assembly - (MIPS)某些汇编指令是否比其他指令更快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27893526/