






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Name:
Alias:
NetID:
Instructions:
Problem No. Maxm Points Points Scored 1 25 2 25 3 25 4 25 Total 100
Use the following code fragment:
loop: LW R0, 0(R2) LW R4, 0(R3) ADDI R0, R0, R SUB R4, R4, R SW 0(R2), R SUB R6, R6, - BNEZ R6, Loop
Consider the standard 5 stage pipeline machine (IF ID EX MEM WB). As- sume the initial value of R6 is 396 and all memory accesses hit in the cache. Show the timing for the above code fragment for the first iteration as well as for the load of the second iteration. Assume the pipeline has full forwarding and bypassing hardware (as discussed in class). Assume branches are resolved in the ID stage and are predicted as not taken. How many cycles does this loop take to complete? (Expand the table if you need more cycles)
Instruction C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C13 C14 C15 C LW R0, 0(R2) F D X M W LW R4, 0(R3) F D X M W ADDI R0, R0, R4 F D - X M W SUB R4, R4, R0 F - D X M W SW 0(R2), R4 - F D X M W SUB R6, R6, -4 F D X M W BNEZ R6, Loop F D - X M W LW R0, 0(R2) F D X M W
Grading: 1 point off for each mistake. No cascading errors.
bnez r3, project nop
Grading: 1 point off for each error.
Total Cycles: 25
project: ldf F3, 0(r1) ldf F4, 4(r1) multf F10, F3, F multf F11, F4, F addi r1, r1, # subi r3, r3, # addi r2, r2, # addf F12, F10, F <-- 1 stall divf F13, F12, F <-- 6 stalls bnez r3, project stf -4(r2), F
Total cycles: 18 cycles.
project: 2 * N of ldf 2 * N of multf N of addf N of divf addi
subi addi N - 1 of stf bnez stf
The bottleneck is the divf instruction, which will have 9 cycles in EX. As long as we can unroll the loop enough times that will cause no stalls for divf instructions, with integer addi and subi inserted before the stf, we will have no stalls. Since stf uses the result of divf only in its MEM stage, so as long as we have enough instructions to execute in the 9 - 1 = 8 cycles between the first divf (inclusive) and first stf, we will have no stalls. So we have : N + 3 = 8. N = 5.
Grading: 0.5 point off for each error.
Step Br1 Predict. Br1 Action Br2 Predict. Br2 Action
1 NT T NT T 2 T T T NT 3 T T 4 T NT 5 T T 6 T T 7 T T 8 T NT
Number of correct predictions: Br1: 5, Br2: 0
Complete the following table using Tomasulo’s algorithm with the above specifications. Fill in the cycle numbers in each pipeline stage for each in- struction in the first two iterations of the loop, assuming the branch is always taken. The entries for the first instructions of the first iteration are filled in for you. CMT stands for the commit stage.
Iteration 1 Iteration 2 Instruction Issue EX WR CMT Issue EX WR CMT LP: L.D F0, 0(R1) 1 2 3 4 5 7 8 38 DIV.D F2, F0, F6 1 4-18 19 20 5 36-50 51 52 L.D F6, 8(R1) 2 3 4 20 6 8 9 52 ADD.D F4, F6, F6 2 5-9 10 21 6 10-14 15 53 DIV.D F6, F6, F2 3 20-34 35 36 7 52-66 67 68 S.D F4, 16(R1) 3 11 - 36 7 16 - 68 DADDI R1, R1, #-32 4 5 6 37 8 9 10 69 BNEZ R1, LP 4 7 - 37 8 11 - 69
Grading: 1 point off for each error, no cascading errors. 2 points for dual commit and 2 points for dual issue.