



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!




CS433: Computer Systems Organization Spring 2007 Homework 2 Assigned: 2/ Due in class 3/
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:
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
Fill in the execution profile for the first two iterations of the above code fragment in Table 2, including
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).
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
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
Grading: 0.25 points per line.
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.
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