



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 Fall 2006 Homework 2 Solution Assigned: 9/ Due in class 9/
This exercise examines Tomasulo’s algorithm on a simple loop operation. Consider the following code fragment LOOP: DADDI R2, R2, # L.D F2, 0(R1) DIV.D F4, F2, F L.D F6, 0(R2) ADD.D F2, F2, F DIV.D F6, F4, F S.D F6, 16(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 3 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
Instruction Reservation Station IS EX WR Comments (if appropriate) DADDI R2, R2, #8 Integer 1 1 2 3 L.D F2, 0(R1) Integer 2 2 3 4 DIV.D F4, F2, F0 FP mult/div 1 3 5-19 20 RAW (L.D F2) L.D F6, 0(R2) Integer 1 4 5 6 ADD.D F2, F2, F6 FP add/sub 1 5 7-9 10 RAW (L.D F6) DIV.D F6, F4, F2 FP mult/div 2 6 21-35 36 RAW (DIV.D F4) S.D F6, 16(R1) Integer 1 7 37 - RAW (DIV.D F6) DADDI R1, R1, #32 Integer 2 8 9 11 CDB conflict DADDI R2, R2, #8 Integer 3 9 11 12 structural (Integer) L.D F2, 0(R1) Integer 4 10 12 13 structural (Integer) DIV.D F4, F2, F0 FP multi/div 3 11 20-34 35 structural (FP mult) L.D F6, 0(R2) Integer 2 12 13 14 ADD.D F2, F2, F6 FP add/sub 1 13 15-17 18 RAW (L.D F6) DIV.D F6, F4, F2 FP mult/div 4 14 36-50 51 RAW (DIV.D F4) S.D F6, 16(R1) Integer 2 15 52 - RAW (DIV.D F6) DADDI R1, R1, #32 Integer 3 16 17 19 CDB conflict
Table 2: Execution profile using Tomasulo’s Algorithm
Grading (10 points):
Consider the following MIPS code fragment. DADDI R1, R0, # LOOP1: DADDI R12, R0, # LOOP2: DSUBI R12, R12, # BNEZ R12, LOOP2 ; Branch 1 DSUBI R1, R1, # BNEZ R1, LOOP1 ; Branch 2
(a) Assume that 1 bit branch predictors are used. When the processor starts to execute the afore- mentioned 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 N N/T/N/T 4 T T N/T/N/T 5 N T T/T/N/T 6 T N N/T/N/T 7 T T N/T/N/T 8 N T T/T/N/T 9 T 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 (5 points): 12 point for each row. Note: The first row of each table was given and therefore is not graded.
Consider the speculative Tomasulo processor shown in Figure 3.29 of the text book. Assume that the ROB has four buffer entries, named 0, 1, 2, and 3. For the following code fragment, assume that ADD.D, and SUB.D insructions execute for 4 cycles, the ADDI and BNEZ instructions execute for 1 cycle, and MUL.D executes for 15 cycles. The branch is not taken, and assume that it is correctly predicted. Assume that the processor has sufficient function units and reservation stations (although not necessarily enough ROB entries) to avoid stalling instruction issue and execution. Finally, we issue and commit a maximum of one instruction per cycle. ADD.D F0, F8, F MUL.D F2, F8, F SUB.D F4, F0, F DADDI R1, R1, R BNEZ R1, LOOP ADD.D F0, F4, F Fill in the execution table below and show the ROB contents and history as it would exist at the beginning of the cycle when the DADDI commits. Pay particular attention to structural hazards for the ROB entries. Assume that F8, R1, and R2 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.
ROB entry Instruction IS EX WR CMT Stall Reason 0 ADD.D F0, F8, F8 1 2-5 6 7 1 MUL.D F2, F8, F8 2 3-17 18 19 2 SUB.D F4, F0, F2 3 19-22 23 24 RAW (MUL.D F2) 3 DADDI R1, R1, R2 4 5 6 25 Stall for in-order commit 0 BNEZ R1, LOOP 8 9 10 26 No ROB until 8; In-order commit 1 ADD.D F0, F4, F4 20 24-27 28 29 No ROB until 20; RAW (SUB.D F4)
Entry Instruction Destination Value Ready Commit 0 ADD.D F0 F8 + F8 Yes 7 1 MUL.D F2 F8 * F8 Yes 19 2 SUB.D F4 F0 - F4 Yes 24 3 DADDI R1 R1 + R2 Yes - 0 BNEZ R1 6 = 0 Yes - 1 ADD.D F0 - No -
Grading (10 points): 1 point for each row. Partial credit should be given for errors that cascade from previous errors. Note: The first row of each table was given and therefore is not graded.
(a) Show an example where this is the case and an example where the value field of the reservation stations is still needed. Use the speculative machine shown in Figure 3.29 of the textbook. Show MIPS code for both examples stating any machine architecture assumptions clearly. How many value fields are needed in each reservation station? Solution: The fundamental reason value fields must be present in both the reservation stations (RS) and the reorder buffer (ROB) is that ROB entries have finite lifetimes. Consider what happens when instruction i in an RS uses the value held in ROB entry j as one of its source operands. As long as instruction i begins execution before ROB entry j is committed to the register file, the RS doesn’t require a value field as the operand can be retrieved from the ROB. Conversely, if ROB entry j is committed to the register file before instruction i begins execution, instruction i is not able to determine the value held in RS j, as committing the ROB entry releases the entry back into the ROB pool. Consider the following code fragment ADD.D F0, F4, F4 ; ROB[0] = F MUL.D F1, F4, F4 ; ROB[1] = F ; ROB[0] retires here SUB.D F2, F0, F1 ; ROB[2] = F DIV.D F3, F4, F4 ; ROB[0] = F where we have a three entry ROB, FP add/sub takes one cycle to execute while FP mult/div takes ten cycles to execute and the machine has enough functional units to issue all instructions in the sequence without stalling. In this case, once the multiply completes, the subtract can execute, but can no longer obtain the correct value of F0 as the DIV.D instruction has overwritten it. Alternatively, consider the following code fragment ADD.D F0, F4, F4 ; F4 is in register file SUB.D F1, F4, F SUB.D F2, F4, F ADD.D F2, F0, F0 ; F0 is in register file with the same assumptions. In this case, it doesn’t matter if the RS have value fields as the instructions will always find their operands in the register file. Another possibility is the case where the code does not have the potential for an instruction to use a “stale” ROB entry as above. For the machine structure of Section 3.7 of the text, reservation stations must have a value field for each possible source operand of a given operation to avoid using corrupted data, unless the program can be guaranteed to behave in a particular fashion. Relying on the value fields on the ROB to guarantee uncorrupted data requires changing the behavior of the machine.
i. What is the best speedup (compared to N = 1) that one can achieve? For which value of N does one achieve this speedup?
tcritical(N ) =
This function is maximized when N = 7, giving a tcritical of 65 for a speedup of 3.77. ii. Assume the cost of the pipeline is given by cost(N ) = 25 · N + 100. For which value of N does one achieve the best speedup/cost ratio?
speedup cost
tcritical · cost(N ) This function is maximized for N = 4.
Grading (1 point): This was a poorly written problem as it was not clear whether the speedup is for a single instruction (my intention) or for a pipeline running completely full. 1 point for anything reasonable.
(c) Suppose that we have a deeply pipelined processor for which we implement a branch-target buffer for conditional branches. Assume that the misprediction penalty is always 6 cycles and the buffer miss penalty for taken branches is 3 cycles. Assume 30% of instructions are conditional branches. Of these, 2/3 are taken. Furthermore, assume for simplicity that taken branches are always predicted correctly, but not taken branches are incorrectly predicted 50% of the time. What should the hit rate in the branch target buffer be for this processor to be faster than a processor that has a fixed 2-cycle branch penalty but is equivalent is every other way? Assume that all other instructions have a CPI of 1 in both processors. Solution: The CPI of the second processor is given by CP I = 1 + 0.3(2) = 1.6. If the hit ratio of the BTX is x, the branch penalty of the first processor is given by 13 (0.5)6 + 2 3 (1^ −^ x)3 = 3^ −^2 x. As a result, the CPI of the first processor is CP I = 1 + 0.3(3 − 2 x) = 1. 9 − 0. 6 x. Solving for x, we find 1. 9 − 0. 6 x < 1 .6 and x > 0 .5.
Grading (5 points): 1 point for calculating the CPI of the second processor. 2 points for writing an equation for the CPI of the first processor. 2 points for the correct answer.