【问题标题】:mips number of clock cycles and how improving codemips 时钟周期数以及如何改进代码
【发布时间】:2013-06-29 17:50:33
【问题描述】:

我真的是 MIPS 的新手,我有这些问题,我为他们找到了很多不同的答案......如果有人可以提供帮助,那就太好了。谢谢

这段代码需要多少个时钟周期?

#Macro Instructions
li  $t0, 32         #  1 or 2 cycles ?      
                    #                lui $at, Upper 16-bits of value 
                    #                ori Rd, $at, Lower 16-bits of value
                    #                -----------------------------------
                    #                ori Rt, $0, value
                    #
                    #  Which set of instructions will be executed?


div $t2, $t2, $t0   #  41 cycles?          
                    #                bne Rt, $0,
                    #                break $0
                    #                ok: div Rs, Rt
                    #                mflo Rd

#Integer Instruction

lw  $t2, 0($t13)    #  1  cycles?
sw  $t2, 0($t3)     #  1  cycles?

如何显着改进这 4 行代码?通过避免使用宏或...?

【问题讨论】:

    标签: assembly mips cycle clock mips32


    【解决方案1】:
    • li $t0, 32

    您可以通过反汇编您的可执行文件或目标文件轻松检查这一点。使用 MIPS 工具链中的 objdump-d-D 选项。我猜这个汇编器足够聪明,不会为这么小的值生成lui


    • div $t2, $t2, $t0

    由于您是除以二 (32) 的幂,因此有一种更快的方法:右移 log2(divisor) 位(即 5 位):

    srl $t2, $t2, 5   # if $t2 is unsigned
    


    sra $t2, $t2, 5   # if $t2 is signed
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      相关资源
      最近更新 更多