Docsity

Midterm Solution - Computer System Organization | CS 433, Exams of Computer Architecture and Organization

Partial preview of the text

Download Midterm Solution - Computer System Organization | CS 433 and more Exams Computer Architecture and Organization in PDF only on Docsity!

CS433 Midterm

Prof Josep Torrellas

October 16, 2008

Time: 1 hour + 15 minutes

Name:

Alias:

NetID:

Instructions:

  1. This is a closed-book, closed-notes examination.
  2. The exam has 4 questions. Please budget your time.
  3. Calculators are allowed.
  4. Please write your answers neatly. Good luck!

Problem No. Maxm Points Points Scored 1 25 2 25 3 25 4 25 Total 100

1 Pipeline [ 25 points ]

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.

  1. [4 points] How many cycles does this loop take per iteration?

Total Cycles: 25

  1. [7 points] Reschedule the code to run in as few cycles per iteration as possible. Do not unroll the loop, just reschedule. How many cycles does the rescheduled loop take per iteration?

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.

  1. [7 points] Assume the loop has been unrolled so that there are N bodies of the loop per iteration. Assume that the instructions from the unrolled loop have been scheduled such that all loads are scheduled first, then all multiplies, then all the floating point adds and then the rest of the instructions. What is the minimum value of N such that there are no stalls or nop instructions in such a scheduled code? Why? Solution: The unrolled loop body will look like the following to min- imize the number of stalls:

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.

  1. [8 Points] Now assume that 4 bit saturation counters are used. When the processor starts to execute the above code, both counters contain value 7. What is the number of correct predictions? Use the following table to record the prediction and action of each branch. [7 points]

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

  1. [5 Points] Now assume that 2 level correlating predictors of the form (2,1) are used. How many bits does the branch predictor need for these two branches? For each branch, 2^2 ∗ 1 = 4bits, total 8 bits.
  2. [4 points] List two differences between a Branch History Table and a Branch Target Buffer. Solution: 1. Branch Target Buffer stores the target address, while Branch History table stores only the predictor.
    1. Branch Target Buffer is accessed during IF, while Branch History Table is accessed in ID.
  • Assume you have unlimited reorder buffer and reservation stations.

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.