Question: How should i optimize this mips code to make use of the branch delay slots and reduce CPI? ------------------------------------------------------------------------------------------------------- # There are 1,000 elements in
How should i optimize this mips code to make use of the branch delay slots and reduce CPI?
-------------------------------------------------------------------------------------------------------
# There are 1,000 elements in each array
nor $t0, $zero, $zero # Set index to -1 j LoopTest nop # Branch delay slot (assume jumps also need it)1 Loop: 7 sll $t1, $t0, 2 # Multiply the index by 4, we'll use it several places 1355 add $t2, $a0, $t1 # Compute the selector address lw $t2, 0($t2) # Load the value from the selector array beq $zero, $t2, UseRightValue # If the selector is zero, copy from right array #waiting for t2 to exec nop # Branch delay slot UseLeftValue: 1124 add $t2, $a1, $t1 # Compute the left address add $t3, $a3, $t1 # Compute the dest address lw $t2, 0($t2) # Load the value from the left array sw $t2, 0($t3) # Store the value to the right array j LoopTest # Jump to LoopTest nop # Branch delay slot (assume jumps also need it) UseRightValue: add $t2, $a2, $t1 # Compute the right address add $t3, $a3, $t1 # Compute the dest address lw $t2, 0($t2) # Load the value from the right array sw $t2, 0($t3) # Store the value to the right array LoopTest: 8 addi $t0, $t0, 1 # Advance the index slti $t1, $t0, 1000 # See if the index is less than one thousand #stall 2 bne $zero, $t1, Loop # If we're not done yet, loop again nop # Branch delay slot Exit:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
