Show how MIPS can implement the instruction swap rs, rt which swaps the values i
ID: 3747326 • Letter: S
Question
Show how MIPS can implement the instruction swap rs, rt which swaps the values in registers rs and rt. Consider the case when
a. there is an available register that may be destroyed.
b. there are no registers available for temporary storage.
If we implement this instruction in hardware, the additional logic will cause the clock period to increase by 15%, thus penalizing all instructions. Under what specific condition could we justify including hardware support for this instruction? Show this mathematically.
Explanation / Answer
Software takes three cycles, and hardware takes one cycle.
Let ‘Rs’ be the ratio of swaps in the code mix. Also, assume a base CPI=1 which it is for the MIPS. Now:
Average time per instruction: (Software):
Rs*3*T + (1 – Rs)*1*T = (2Rs + 1) * T
(Hardware):
T Hardware implementation makes sense only if: T <= (2Rs + 1) * T
-- > 15% increase in clock period:
Clock period = 1.15 * T
if swap instructions are greater than 5% of the instruction mix (Rs >= 0.05),
Then a hardware implementation would be preferable.
swap $rs,$rt can be implemented as follows:
addi $rd,$rs,0
addi $rs,$rt,0
addi $rt,$rd,0
No available register case:
sw $rs,temp($r0)
addi $rs,$rt,0
lw $rt,temp($r0)
Alternate solution:
xor $rs,$rs,$rt
xor $rt,$rs,$rt
xor $rs,$rs,$rt