CS232 Spring 2006 Forwarding, Stalling and Hazards October 16, 2006Problem 1: Loop unrolling is a code optimization technique to sp e ed up loops. The code onthe right is functionally equivalent to the code on the left (for even values of $a1).loop: loop:lw $s0, 0($a0) lw $s0, 0($a0)addi $s0, $s0, 100 addi $s0, $s0, 100sw $s0, 0($a0) sw $s0, 0($a0)addi $a0, $a0, 4 lw $s0, 4($a0)addi $a1, $a1, -1 addi $s0, $s0, 100bne $a1, $0, loop sw $s0, 4($a0)addi $a0, $a0, 8addi $a1, $a1, -2bne $a1, $0, loopAssume that full forwarding is implemented, and that branches are resolved in the ID stageand always predicted taken. The initial value of $a1 = 4.(a) Fill the pipeline diagram for iteration 1 of the left code. Include the lw of iteration 2.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16(b) Fill the pipeline diagram for only the first iteration of the right code.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16(c) Calculate the total number of cycle s required for each piece of code.1CS232 Spring 2006 Forwarding, Stalling and Hazards October 16, 2006Problem 2: Software PipeliningSoftware Pipelining is another code optimization technique to reduce pipeline stalls. The givencode can be rewritten as follows:li $t1, 1lw $s0, 0($a0)loop:addi $s0, $s0, 100sw $s0, 0($a0)lw $s0, 4($a0)addi $a0, $a0, 4addi $a1, $a1, -1bne $a1, $t1, loopaddi $s0, $s0, 100sw $s0, 4($a0)Assume that full forwarding is implemented, and that branches are resolved in the ID stageand always predicted taken. The initial value of $a1 = 4.(a) Fill the pipeline diagram for the first iteration of the loop (don’t include lw):1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16(b) Calculate the number of cycles required for the code to exec ute.(c) Suppose branches are predicted not taken. How many cycles does the code require
View Full Document