Midterm Solution
Midterm Solution
I hereby affirm that all the answers below are my own. I have
neither searched online nor taken assistance from any external
entity.
---------------------------------
Student Signature Above
EE557—Spring 2024
MIDTERM 1
Open Books and Notes
No electronics but a calculator is allowed
Time limit: 1 hour and 50 minutes
Q1: / 20
Q2: / 20
Q3: / 10
Q4: / 18
Q5: / 16
Q6: / 20
TOTAL: / 104
The total number of pages is 18 (including this page). Staple and turn in all pages.
Static power is power dissipated when powered on but not active switching on inputs.
Give full credit if students mention anything similar to toggling and switching.
B) Describe what sub-threshold power leakage is for CMOS chips. Will clock-gating help to address
sub-threshold power leakage? (3 points)
(2pts) Even when the transistors are OFF, there exists a small current across transistors causing energy
dissipation.
C) Chip designers embrace the hybrid CPU architecture where E (efficient) and P (performance)
cores exist in a single package. E cores are optimized for power efficiency, and P cores are for
high-performance tasks. In this question, assume core specification when clocked at 𝑓 in Table 1.
Given 100 unit of workload and a CPU with 2 P cores and 4 E cores, how to distribute the
workloads to those 6 cores that result in the shortest runtime? Write down what is the shortest
runtime and energy consumption in terms of 𝑃! , 𝑃" , and 𝑇 . (5 points)
P Cores E Cores
Dynamic Power 6 ⋅ 𝑃! 𝑃!
𝑇
Time taken for 1 unit of workload 𝑇
4
2pt Total energy consumption is (16𝑃! + 8𝑃" ) ⋅ 8.33𝑇 = 133.28𝑇𝑃! + 66.64 ⋅ 𝑇𝑃"
Page 2 of 18
Name: __________________________
(Question 1 continued)
D) Repeat Part C for 100 units of workloads but CPU has 4 P cores and no E cores? (5 points)
E) Repeat Part C if we increase the VDD on E core only and clock them at 1.5𝑓 . (5 points)
Page 3 of 18
Name: __________________________
1/(1-3/5f) = 1.1
3f/5 = 1-1/1.1
f = .152 or 15.2%
B) For the program identified in Part (A), what is the maximum possible speedup if the described
enhancement provides infinite speedup? (2 points)
C) Now let us consider a different machine where two enhancements are proposed: one that can enhance
40% of execution time with a speedup of 1.5, and another that can enhance 25% of execution time
with some greater speedup value. Only one of these two can be implemented. How much of a
speedup is necessary in the second enhancement to beat the first enhancement? (3 points)
Grading: 1point per side of the equation and 1 point for simplification (do not deduct for calculation
error)
Page 4 of 18
Name: __________________________
(Question 2 continued)
Store to memory 6
FP multiplication 17
Others 65
You are considering upgrading your machine to one of two possible configurations. M1 reduces the
contribution of loads to the execution time by 3✕ and that of stores by 2✕. M2 reduces the contribution
of (only) floating-point multiplications to the execution time by 10✕. What is the overall speedup of the
program for each upgrade? You may express your answer in terms of an equation with all variables
explicitly substituted. You are not required to perform numerical calculations. (3 points)
Solution:
Grading: 1.5 points for the speedup equation for M1. 1.5 points for the speedup equation for M2.
E) What is the maximum possible speedup if all memory accesses could be speed up infinitely? What is
the maximum speedup if all (and only) floating-point multiplications could be sped up infinitely? You
may express your answer in terms of an equation with all variables explicitly substituted. You are not
required to perform numerical calculations. (3 points)
Solution:
Grading: 1.5 points for the speedup equation for memory. 1.5 points for the speedup equation for FP.
Page 5 of 18
Name: __________________________
(Question 2 continued)
F) Several researchers have suggested that adding a register-memory addressing mode to a load-store
machine might be useful. The idea is to replace sequences of
LD R1, 0(R8)
ADD R2, R2, R1
with
Assume that the new instruction will cause the clock cycle time to increase by 5% and will not affect
the CPI (clock per instruction). Also, assume loads constitute 25.1% of all instructions. What
percentage of the loads must be eliminated for the machine with the new instruction to have at least
the same performance? (6 points)
Solution:
Let 𝐿 be the fraction of loads that are eliminated. This means that 0. 251 × 𝐿 of all instructions are
eliminated.
𝐶𝑃𝑈 𝑡𝑖𝑚𝑒 𝑛𝑒𝑤 = ((1 − 0. 251 × 𝐿) × # 𝑜𝑓 𝑖𝑛𝑠𝑡𝑟𝑢𝑐𝑡𝑖𝑜𝑛𝑠) × 𝐶𝑃𝐼×((1 +. 05) × 𝑐𝑦𝑐𝑙𝑒 𝑡𝑖𝑚𝑒)
(1 − 0. 251 × 𝐿) × 1 × 1. 05 ≤ 1
0. 251 × 𝐿 ≥ 1 − 1/1.05
𝐿 ≥ 0. 19 𝑜𝑟 19%
Grading: 2 points for the basic time equation. 3 points for setting up the equation correctly to solve the
problem. No deductions for calculation mistakes.
Page 6 of 18
Name: __________________________
The applications you care for have a small code size and work on small data sets in the range of 64 KB.
These applications spend most of their time in loops whose iterations are independent of each other, but
typically have only a limited amount of ILP within a single iteration (within the current processor
implementation).
You have some extra transistor budget in (possibly several of) the following ways:
Some of these may be desirable additions, while others may not be too beneficial given the current
configuration. Which of the above four additions should you support, and which ones should you oppose
(you can support/oppose multiple of these)? You need to justify your choices bellow to receive credit.
1. Improve the branch predictor accuracy: This is a desirable addition. The problem states that the
branch predictor performs only moderately well and the processor has a long pipeline making branch
mispredictions expensive. Thus, improving branch prediction accuracy is quite likely to increase
performance.
Page 7 of 18
Name: __________________________
(Question 3 continued)
2. Add more reservation stations to your Tomasulo’s Algorithm-based Dynamic Scheduler: Support or
Oppose, and why?
2. Add more reservation stations to your Tomasulo’s Algorithm-based Dynamic Scheduler: This is a
desirable addition. More reservation stations would mean a larger window within which the processor
can search for ready instructions to execute, thus it can discover more parallelism and keep execution
units busy. This would lead to better performance, especially since our application needs to discover
parallelism across loop iterations.
3. Add more FPUs and Integer Units: Support or Oppose, and why?
3. Add more FPUs and Integer Units: This doesn’t seem to be a good addition. The current machine
already has enough FUs and we should try to improve other aspects of the processor. Adding more FUs
12 won’t help if the processor is unable to discover enough parallelism in the instruction stream to keep
them busy.
4. Add more Reorder Buffer entries: This is a desirable addition. The current configuration has very few
ROB entries. A large ROB helps to mask out the effects of long latency instructions and help search for
parallelism within a larger window (this goes together with (3)).
Grading: 2.5 points for correctly analyzing each part. 10 points total. Give partial credit (1 points) if
student gives valid reason for why improvement can be avoided.
Page 8 of 18
Name: __________________________
Integer 1 1 Yes
FP Add/Sub 3 1 Yes
FP Mult 8 1 Yes
FP Division 24 1 Yes
• The integer functional unit performs integer addition (including effective address calculation for
loads/stores), subtraction, and logic operations.
• There is full forwarding and bypassing, including forwarding from the end of a functional unit to
the MEM stage for stores.
• Loads and stores complete in one cycle. That is, they spend one cycle in the MEM stage after the
effective address calculation.
• There are as many registers, both FP and integer, as you need.
• Branches are resolved in ID and there is one branch delay slot.
• While the hardware has full forwarding and bypassing, it is the responsibility of the compiler to
schedule such that the operands of each instruction are available when needed by each
instruction.
• If multiple instructions finish their EX stages in the same cycle, then we will assume they can all
proceed to the MEM stage together. Similarly, if multiple instructions finish their MEM stages in
the same cycle, then we will assume they can all proceed to the WB stage together. In other
words, for the purpose of this problem, you are to ignore structural hazards on the MEM and WB
stages.
This problem explores the ability of the compiler to schedule code as efficiently as possible for such a
pipeline. Consider the following code (also repeated on the next pages for reference):
loop:
Note: DADDIU is just like ADDIU but for 64 bits which performs ADD IMMEDIATE operation.
Page 9 of 18
Name: __________________________
(Question 4 continued)
A) Rewrite the above loop (repeated below for reference), but let every row take a cycle (each row can
be an instruction or a stall). If an instruction can’t be issued on a given cycle (because the current
instruction has a dependency that will not be resolved in time), write “stall” instead, and move on to
the next cycle (row) to see if it can be issued then. Assume that a NOP is scheduled in the branch
delay slot (effectively stalling 1 cycle after the branch). Explain the cause of all stalls, but don’t
reorder instructions. How many cycles elapse before the second iteration begins? (6 points)
Page 10 of 18
Name: __________________________
(Question 4 continued)
B) Now reschedule the loop to compute the same results as quickly as possible. You can change
immediate values and memory offsets and reorder instructions without violating any of the
dependencies, but don’t change anything else. Show any stalls that remain. How many cycles elapse
before the second iteration begins? Show your work. (6 points)
Solution:
Grading: Full points for any correct sequence with minimum number of stalls. Partial credit only if the
sequence does the same computation and reduces some stalls. Deduct ½ point for each error e.g.
incorrect index. Deduct ½ point for each stall in excess of 2.
Page 11 of 18
Name: __________________________
(Question 4 continued)
C) Now unroll the loop the minimum number of times needed to eliminate all stalls (with rescheduling).
Show the unrolled and rescheduled loop. You can, and should, remove redundant instructions. How
many original iterations of the loop are in an iteration of your new unrolled loop? How many cycles
elapse before the next iteration of the unrolled loop begins? Don’t worry about start-up or clean-up
code outside the unrolled loop. Assume a very large number of iterations for the original loop. Show
your work. (6 points)
Solution: Note that in the solution below, the registers used could be different and there is some
flexibility in scheduling the instructions.
The loop has an unroll factor of 2: there are two iterations of the original loop in a single iteration of the
new loop. 17 cycles elapse before the next iteration of the unrolled loop begins.
Grading: 1 point for the correct iteration count. Deduct ½ point for each error or stall cycle. Give partial
credit (3 points) if three iterations are used instead of two and the solution is correct with three
iterations.
Page 12 of 18
Name: __________________________
A) Suppose we have a perfect branch predictor and there is no data dependency between instructions.
We have infinite execution units of each type and infinite reservation stations. All instructions take
one cycle in the EX-stage. What is the maximum achievable IPC? What is the minimum ROB size
required to guarantee that IPC? (4 points)
Solution: Each instruction holds its ROB entry for 4 cycles (Issue, Execute, CDB, and Commit). Therefore,
we must have a minimum ROB size of 16 to avoid any stalls. In that case, the throughput would be 4
instructions per cycle.
Grading: 2 point for correct IPC. 2 point for correct ROB size.
B) Suppose different FUs have different latencies in the EX-stage, as given by the following table.
Everything else is the same as in the previous part. What is the minimum size of the ROB required
now to avoid any issue stalls due to a full ROB? (4 points)
Integer ALU 3
Solution: If we issue an instruction to the FP multiplier, it will occupy its ROB entry for 16 cycles, and
would also block the instructions following it from committing. During that period, we could have issued
64 instructions in all. Thus, we need a minimum ROB size of 64 to avoid stalls. In that case we would get
a throughput of 4 instructions per cycle.
Grading: 2 points for realizing that FP multiplier is the bottleneck. 2 points for correct ROB size.
Page 13 of 18
Name: __________________________
(Question 5 continued)
C) In addition to the latencies above, now every 10th instruction is a load instruction. Assume the
address calculation and cache/memory access parts of the load both happen in the EX-stage. The hit
rate in the data cache is 95% and the misses are uniformly spaced through the instruction stream. A
hit takes 1 cycle in the EX-stage. However, upon a miss, the data has to be fetched from the memory
and this results in 120 cycles in the EX-stage. What is the ROB size required now to avoid any issue
stalls? (4 points)
Solution: A load instruction that misses in the cache would occupy its ROB entry for 1 + 120 + 1 + 1 = 123
cycles. During this time, we could have issued 492 instructions. This is the size of the ROB required to
continuously issue 4 instructions each cycle.
Grading: 2 points for calculating the correct latency of loads. 2 points for correct ROB size.
D) Now additionally assume we don’t have perfect branch prediction anymore. Instead, we have a
predictor with an accuracy of 95%. Assume every 8th instruction is a branch and the mispredictions
are uniformly spaced through the instruction stream. After a misprediction, how many instructions are
issued before the next misprediction is encountered? In light of this result, do you think we need a
ROB of the size you derived in Part C? Why/why not? If not, what do you think would be a good
ROB size to have? (4 points)
Solution: We would issue 8 × 20 = 160 instructions before a mispredict is encountered. Given this result,
it doesn’t make sense to have a ROB of size 492, because once we have a cache miss, soon after we
would run into a branch mispredict, and all the work done after that would be wasted anyway. A
reasonable ROB size would be 160.
Grading: 2 points for starting that a smaller ROB is sufficient. 2 points for correct ROB size.
Page 14 of 18
Name: __________________________
Assume that the current state of global history register is: ghist[8:0]= 111010111 and the current branch
PC is PC[5:0]= 000101. You are asked to update a TAGE Branch predictor that has the following
predictor tables:
Table 0 bimodal
address ctr (2 bits)
000 01 Table 1 Table 2 Table 3 Table 4
001 10 address
ctr tag u ctr tag u ctr tag u ctr tag u
010 00 00 001 110 00 101 101 01 110 111 01 100 011 00
011 01 01 101 010 11 000 011 00 101 100 00 101 100 00
100 01 10 100 100 01 101 000 10 010 010 01 000 101 11
101 11 11 111 100 10 111 110 11 011 000 10 111 001 10
110 01
111 00
You will have to use the global history, branch PC and the predictor tables to predict the outcome of the
branch then update the predictor tables.
You index the bimodal table (table 0) using the following bits from the branch PC: PC[5:3]
You index the predictor tables (tables 1-4) and compute the tag as follows. FHi is the folded history of i
bits that is computed from a subset of ghist bits as specified below.
Address: PC[4:3] ⊕ FH2, Tag: PC[2:0] ⊕ FH3, where ‘⊕’ is an xor operation
Note that table 1 uses history ghist[1:0], table 2 uses history ghist[3:0], table 3 uses history ghist[5:0], and
table 4 uses history ghist[7:0]. These ghist bits are used to compute FH2, FH3 which are then used for tag
and address computation. FHi is the folded global history and here is an example to show you how to
compute it:
Assume we are to fold 8 bits of global history ghist[7:0] into 4 bits or 3 bits:
Note also that we are using is a 3-bit counter in the tagged predictor components. Hence, 1xx is predicted
taken and 0xx is predicted not taken. A 2-bit counter is used in Table 0 (base predictor) so 1x is predicted
taken and 0x is predicted not taken.
Page 15 of 18
Name: __________________________
(Question 6 continued)
a) Find the outcome of the prediction from each predictor components (i.e. table 0-5). Show your
steps in details. (13 points)
Table 0:
Prediction: Use PC[5:3]=000 to index table 0 and get 01 so predict not taken
Table 1:
Table 2:
Table 3:
Table 4:
Page 16 of 18
Name: __________________________
(Question 6 continued)
b) Assume the branch is taken, how will you update the predictor components? mark the tables
below and show your steps. (7 points)
Table 0 bimodal
address ctr (2 bits)
000 01 Table 1 Table 2 Table 3 Table 4
001 10 address
ctr tag u ctr tag u ctr tag u ctr tag u
010 00 00 001 110 00 101 101 01 110 111 01 101 011 01
011 01 01 101 010 11 000 011 00 101 100 00 101 100 00
100 01 10 100 100 01 101 000 10 010 010 01 000 101 11
101 11 11 111 100 10 111 110 11 011 000 10 111 001 10
110 01
111 00
Page 17 of 18
Name: __________________________
Page 18 of 18