(MIPS)是一些汇编指令比其他指令更快?

时间:2015-01-11 23:56:50

标签: assembly mips

某些裸MIPS指令是否比其他指令更快?引起我兴趣的问题是将寄存器乘以2的幂。

假设$ t0有一个不会溢出的数字。如果我想将该寄存器乘以8,那么之间存在任何可量化的性能差异:

3位sll:

    sll     $t0,  $t0,3

使用mul命令(假设$ t8' s值为8):

    mul     $t0,  $t0,$t8

或使用mult命令?

    mult    $t0,  $t0,$t8

每个示例都包含一条指令,但我不知道一个指令是否比另一个指令快。直觉让我觉得mul比mult快,因为没有多余的位存入HI(这是正确的吗?)

或者,是否有人知道有关组装中个别指令速度(MIPS或其他)主题的任何文章/网页?我可以想象不同的指令由不同的电路/硬件组成,并且每条指令都在不同的时间内执行,但我似乎无法在线找到任何关于此的资源。

我对MIPS /汇编非常陌生,所以请原谅我没有运行时序示例(或者在上面的示例中可能使用了错误的语法)。

1 个答案:

答案 0 :(得分:3)

程序员的MIPS32TM架构 第二卷:MIPS32TM指令集,mul / mult instrutions'

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中可能比其他指令花费更多周期的少数事情之一。
手册指定mult的方式,它可能是实现为mul然后mflo,在这种情况下,mulmult显然具有完全相同的时序特征。它可以也真的是一个单独的指令,在这种情况下可能更快,但我怀疑很少有硬件实现这样做。乘法/除法单元是MIPS架构中较差的一个方面。