Docsity

Assignment 2 with Solution Key for Computer System Organization | CS 433, Assignments of Computer Architecture and Organization

Toggle sidebar
bg1
CS433: Computer Systems Organization Spring 2007
Homework 2
Assigned: 2/6
Due in class 3/1
1. Tomasulo’s Algorithm [10 points]
This exercise examines Tomasulo’s algorithm on a simple loop operation. Consider the following code
fragment
LOOP: L.D F2, 0(R1)
L.D F4, 8(R1)
DIV.D F6, F2, F4
MUL.D F8, F6, F6
ADD.D F6, F2, F4
MUL.D F10, F6, F6
S.D F8, 0(R1)
S.D F10, 8(R1)
DADDI R1, R1, #16
BNEZ R1, LOOP
running on a system with the following specifications:
•The pipeline functional units are described by Table 1.
Functional Unit Cycles in EX # Functional Units # Reservation Stations
Integer 1 1 5
FP add/subtract 4 1 4
FP multiply/divide 15 2 4
Table 1: Functional Unit Specification
•Functional units are not pipelined.
•All stages except EX take one cycle to complete.
•There is no forwarding between functional units. Both integer and floating point results are
communicated through the CDB.
•Memory accesses use the integer functional unit to perform effective address calculation. All loads
and stores access memory during the EX stage.
•There are unlimited load/store buffers and an infinite instruction queue.
•Loads and stores take one cycle to execute.
•If an instruction is in the WR stage in cycle x, then an instruction that is waiting on the same
functional unit (due to a structural hazard) can begin execution in cycle x+ 1.
•Only one instruction can write to the CDB in a clock cycle.
•Branches and stores do not need the CDB.
•Whenever there is a conflict for a functional unit or the CDB, assume program order.
•When an instruction is done executing in its functional unit and is waiting for the CDB, it is
still occupying the functional unit and its reservation station (meaning no other instruction may
enter).
•Treat the BNEZ instruction as an Integer instruction. Assume L.D instruction after the BNEZ
can be issued the cycle after the BNEZ instruction is issued due to branch prediction.
•Initially, R1 <-16.
1
pf3
pf4
pf5

Partial preview of the text

Download Assignment 2 with Solution Key for Computer System Organization | CS 433 and more Assignments Computer Architecture and Organization in PDF only on Docsity!

CS433: Computer Systems Organization Spring 2007 Homework 2 Assigned: 2/ Due in class 3/

  1. Tomasulo’s Algorithm [10 points]

This exercise examines Tomasulo’s algorithm on a simple loop operation. Consider the following code fragment LOOP: L.D F2, 0(R1) L.D F4, 8(R1) DIV.D F6, F2, F MUL.D F8, F6, F ADD.D F6, F2, F MUL.D F10, F6, F S.D F8, 0(R1) S.D F10, 8(R1) DADDI R1, R1, # BNEZ R1, LOOP running on a system with the following specifications:

  • The pipeline functional units are described by Table 1.

Functional Unit Cycles in EX # Functional Units # Reservation Stations Integer 1 1 5 FP add/subtract 4 1 4 FP multiply/divide 15 2 4

Table 1: Functional Unit Specification

  • Functional units are not pipelined.
  • All stages except EX take one cycle to complete.
  • There is no forwarding between functional units. Both integer and floating point results are communicated through the CDB.
  • Memory accesses use the integer functional unit to perform effective address calculation. All loads and stores access memory during the EX stage.
  • There are unlimited load/store buffers and an infinite instruction queue.
  • Loads and stores take one cycle to execute.
  • If an instruction is in the WR stage in cycle x, then an instruction that is waiting on the same functional unit (due to a structural hazard) can begin execution in cycle x + 1.
  • Only one instruction can write to the CDB in a clock cycle.
  • Branches and stores do not need the CDB.
  • Whenever there is a conflict for a functional unit or the CDB, assume program order.
  • When an instruction is done executing in its functional unit and is waiting for the CDB, it is still occupying the functional unit and its reservation station (meaning no other instruction may enter).
  • Treat the BNEZ instruction as an Integer instruction. Assume L.D instruction after the BNEZ can be issued the cycle after the BNEZ instruction is issued due to branch prediction.
  • Initially, R1 < -16.

Fill in the execution profile for the first two iterations of the above code fragment in Table 2, including

  • The reservation station used by each instruction. This should include both the functional unit type and the number of the reservation station. If multiple reservation stations of a particular type are available, associate early program order with lower cardinality.
  • The cycles that each instruction occupies in the IS, EX, and WR stages.
  • Comments to justify your answer such as type of hazards and the registers involved.

Solution:

Instruction Reservation Station IS EX WR Comments (if appropriate) L.D F2, 0(R1) Integer 1 1 2 3 L.D F4, 8(R1) Integer 2 2 3 4 DIV.D F6, F2, F4 FP Mult/Div 1 3 5-19 20 RAW MUL.D F8, F6, F6 FP Mult/Div 2 4 20-34 35 RAW ADD.D F6, F2, F4 FP Add 1 5 6-9 10 MUL.D F10, F6, F6 FP Mult/Div 3 6 11-25 26 RAW S.D F8, 0(R1) Integer 1 7 36 37 RAW S.D F10, 8(R1) Integer 2 8 27 28 RAW DADDI R1, R1, #16 Integer 3 9 10 11 BNEZ R1, LOOP Integer 4 10 11 12 L.D F2, 0(R1) Integer 5 11 12 13 L.D F4, 8(R1) Integer 3 12 13 14 DIV.D F6, F2, F4 FP Mult/Div 4 13 26-40 41 Stuctural (Waiting for FU) MUL.D F8, F6, F6 FP Mult/Div 1 21 41-55 56 Waiting for Res St, RAW ADD.D F6, F2, F4 FP Add 1 22 23-26 27 MUL.D F10, F6, F6 FP Mult/Div 3 27 35-49 50 Waiting for Res St, Waiting for FU S.D F8, 0(R1) Integer 3 28 57 58 RAW S.D F10, 8(R1) Integer 2 29 51 52 RAW DADDI R1, R1, #16 Integer 4 30 31 32 BNEZ R1, LOOP Integer 5 31 32 33

Table 2: Execution profile using Tomasulo’s Algorithm

Grading: 0.5 points per line. Partial credit is ok and its ok if the mistake cascades down (since the cycles are dependent).

  1. Dynamic Branch Prediction [10 points]

Consider the following MIPS code fragment. DADDI R1, R0, # LOOP1: DADDI R2, R1, # LOOP2: DSUBI R2, R2, # BNEZ R3, LOOP2 ; Branch 1 DSUBI R1, R1, # BNEZ R1, LOOP1 ; Branch 2

(a) [3 points] Assume that 1 bit branch predictors are used. When the processor starts to execute the aforementioned code, both predictors contain value N (not taken). What is the number of correct predictions? Use the following tables to record the prediction and action of each branch.

Branch 1 Step Prediction Action New State 1 N T N/N/N/T 2 N T N/T/N/T 3 N T T/T/N/T 4 T N N/T/N/T 5 T T N/T/N/T 6 N T T/T/N/T 7 T N N/T/N/T 8 T T N/T/N/T 9 N N N/T/N/T

Correct Predictions: 3

Branch 2 Step Prediction Action New State 1 N T N/N/T/N 2 T T N/N/T/N 3 T N N/N/N/N

Correct Predictions: 1

Grading: 0.25 points per line.

  1. Short Answer for branches [10 points] Consider the following code fragment:

ADDI R1, R0, # LOOP: BNEZ R1, END ; Branch 1 ANDI R2, R1, # BNEZ R2, ODD ; Branch 2 EVEN: ... J DECR ODD: ... DECR: DSUBI R1, R1 ,# J LOOP END: ... (This is roughly equivalent to)

for (i = 100; i > 0; i--) { // Branch 1 if (i mod 2 == 0) { // Branch 2 ... } else { ... } } ...

(a) [3 points] For branch 1, would a (2,1) correlating predictor or a 2-bit saturation counter be more appropriate. Why? Solution: The 2-bit saturation counter would be better. Although in the long run, both options would provide similar performance for this branch, the branch has no correlation with the previous 2 branches and the correlating predictor would make more initial mispredictions. Grading: 1 point for choosing the correct predictor, 2 points for the explaination. (b) [3 points] For branch 2, would a (2,1) correlating predictor or a 2-bit saturation counter be more appropriate. Why? Solution: The correlating predictor would be better On the even iterations of the loop, the branch is always taken while on the odd iterations the branch is always not taken. The correlating predictor would have enough history to see this pattern. The 2-bit predictor on the other hand would keep flip flopping is predictions and mispredict the majority of the time.

Grading: 1 point for choosing the correct predictor, 2 points for the explaination. (c) [2 points] What would type of branch predictor would be able to handle both branches well? Solution: A Tournament predictor consisting of a saturation counter and a correlating predictor. The tournament predictor will learn which predictor gives the best performance for each branch. Grading: 2 points. (d) [2 points] What is the branch target buffer and why does it improve performance? Solution: The branch target buffer caches the branch target addresses. By caching the branch target addresses, we don’t need to wait to calculate the branch target and can load the next instruction as soon as the branch is resolved (or predicted). Grading: 2 points.

  1. Speculative Execution [10 points] Consider the speculative Tomasulo processor shown in Figure 2.9 of the text book. Assume the fol- lowing: - The ROB has four buffer entries, named 0, 1, 2, and 3. - Integer operations including BNEZ require 1 cycle to execute, FP ADD.D requires 4 cycles and FP MUL.D requires 15 cycles. - Assume there are enough reservation stations, and functional units to accomodate all instructions being issued (there might not be enough ROB entries however). - Assume there is full forwarding between all functional units (i.e. when an instruction is waiting for the result from another instruction, it can begin execution after the dependant instruction completes its EX stage). - The processor is single issue, single commit. - The branch is not taken and assume that it is correctly predicted.

For the following piece of code, completely fill in the execution table but show the ROB contents and history as it would be at the end of the cycle where DSUBI commits. Assume that F8, R1, and R are initialized and that the ROB is initially empty. Because a ROB is implemented as a circular queue, the entry number labels repeat modulo 4 reading down the table. When ROB entries are reallocated during the simulated execution time, write the details of the new allocation in the next available correspondingly numbered table row. In the Value column, write the computed result in algebraic form (ex. F5 - F3). If the result has not been computed yet, write a dash. In the Ready Column, write Yes if the ready bit for this entry was set to Yes, otherwise write No. Use the Commit column to indicate the cycle number when the instruction committed. If the instruction has not committed yet, simply write a dash. LOOP: MUL.D F0, F8, F ADD.D F2, F8, F ADD.D F4, F0, F DSUBI R1, R1, # BNEZ R1, LOOP ADD.D F6, F6, F ROB entry Instruction IS EX WR CMT Stall Reason 0 MUL.D F0, F8, F8 1 2-16 17 18 1 ADD.D F2, F8, F8 2 3-6 7 19 2 ADD.D F4, F0, F2 3 17-20 21 22 RAW (MUL.D F0) 3 DSUBI R1, R1, #1 4 5 6 23 Stall for in-order commit 0 BNEZ R1, LOOP 19 20 21 25 No ROB until 19; In-order commit 1 ADD.D F6, F6, F4 20 21-24 25 26 No ROB until 20