Processor Datapath & Pipelining
Level: 4 (Application — novel problems, no hints) Time Limit: 60 minutes Total Marks: 60
Question 1 — Timing & Datapath Choice (12 marks)
A designer characterizes the following component delays for a MIPS-style processor:
| Component | Delay (ps) |
|---|---|
| Instruction Memory (read) | 200 |
| Register File (read) | 100 |
| ALU | 150 |
| Data Memory (read/write) | 250 |
| Register File (write) | 100 |
Assume mux, control, and wiring delays are negligible. Instruction mix: 25% load, 10% store, 45% R-type, 15% branch, 5% jump. A load traverses IM → RegRead → ALU → DataMem → RegWrite. An R-type traverses IM → RegRead → ALU → RegWrite.
(a) Compute the minimum clock period for a single-cycle implementation. State which instruction sets it. (3)
(b) A multi-cycle design uses cycles bounded by the slowest single component. Give the cycle time. Loads take 5 cycles, stores 4, R-type 4, branches 3, jumps 3. Compute the average CPI and the average instruction time. (5)
(c) Which design is faster for this workload, and by what speedup factor (multi-cycle time ÷ single-cycle time as a ratio)? Show the comparison. (4)
Question 2 — Hazard Detection & Forwarding (14 marks)
Consider the classic 5-stage pipeline (IF/ID/EX/MEM/WB) with a full forwarding unit and a load-use hazard detection unit. Code:
I1: lw $t0, 0($s0)
I2: add $t1, $t0, $s1
I3: sub $t2, $t1, $t0
I4: sw $t2, 4($s0)
I5: and $t3, $t2, $s1
(a) Identify every RAW dependency (producer → consumer, register). (4)
(b) Determine which dependencies are resolved purely by forwarding and which require a stall. State the number of stall cycles inserted and where. (4)
(c) For the forwarding case of I3 reading $t1 (produced by I2), specify the forwarding source (EX/MEM or MEM/WB pipeline register) and the exact condition the forwarding unit checks. (3)
(d) Give the total cycle count to complete all 5 instructions (start counting cycle 1 at I1's IF). (3)
Question 3 — Throughput, CPI & Deep Pipelining (12 marks)
A processor runs at 2.0 GHz with an ideal 5-stage pipeline. A benchmark of 10⁹ instructions has: 20% branches with a 30% misprediction rate (2-cycle penalty each mispredict), and 15% loads of which 40% cause a 1-cycle load-use stall.
(a) Compute the effective CPI including hazard penalties. (4)
(b) Compute the execution time in seconds. (3)
(c) The team proposes a 10-stage pipeline at 3.4 GHz. The branch penalty rises to 5 cycles (same misprediction rate) and the load-use stall to 2 cycles (same fraction of loads). Compute the new effective CPI and execution time. Is it faster? Give the speedup. (5)
Question 4 — Structural Hazard Analysis (10 marks)
A pipelined machine has a single unified memory port shared by the IF stage and the MEM stage (rather than separate instruction/data caches).
(a) Explain precisely when a structural hazard occurs on this port during steady-state execution, referencing the stages of overlapping instructions. (4)
(b) A program has fraction of memory instructions (loads + stores). Assuming one stall cycle is inserted every time a MEM-stage access collides with an IF-stage access, and every memory instruction collides exactly once, derive the CPI as a function of . (3)
(c) For , compute the CPI and the percentage slowdown versus the ideal CPI of 1. (3)
Question 5 — Precise Exceptions (12 marks)
An overflow exception can be raised by the ALU in the EX stage. Consider the pipeline running:
I1: add $s0, $s1, $s2 ; overflows in EX
I2: lw $t0, 0($s3)
I3: sub $t1, $t4, $t5
(a) Define what makes an exception precise in a pipelined processor. (3)
(b) When I1's overflow is detected in EX, I2 is in ID and I3 is in IF. Describe the actions the pipeline must take to preserve precise exception semantics. (4)
(c) Explain why exceptions arising in different pipeline stages of different instructions during the same cycle must be handled in a specific priority order, and state which instruction's exception takes precedence if I1 (add, EX) and I2 (lw, MEM in a later cycle) both signal — reason in program order. (5)
Answer keyMark scheme & solutions
Question 1
(a) Single-cycle period = critical path of slowest instruction = load: Load sets it. (3 marks: path 2, sum 1)
(b) Multi-cycle cycle time = slowest single component = Data Memory = 250 ps. (1) Average CPI: (2) Average instruction time = ps. (2)
(c) Single-cycle instruction time = 800 ps (all instructions take one 800 ps cycle). Multi-cycle avg = 1012.5 ps. Ratio multi/single = . Single-cycle is faster here (by ~26.6%) because the multi-cycle CPI is high and its cycle time only saved a little. (4 marks: comparison 2, correct conclusion + factor 2)
Question 2
(a) RAW dependencies: (4, one each ≈1)
- I1→I2 on
$t0 - I2→I3 on
$t1 - I1→I3 on
$t0 - I3→I4 on
$t2 - I3→I5 on
$t2
(b)
- I1(lw)→I2 on
$t0: load-use hazard — value available only after MEM. I2 needs it in EX the cycle right after I1's MEM would produce it → 1 stall cycle inserted between I1 and I2. After stall, MEM/WB forwarding supplies it. (2) - I2→I3 (
$t1), I1→I3 ($t0, already old enough), I3→I4 ($t2), I3→I5 ($t2): all resolved by forwarding, no stalls. (2) - Total stalls = 1.
(c) I3 reads $t1 produced by I2. When I3 is in EX, I2 is in MEM. Forward from EX/MEM pipeline register. Condition:
Here EX/MEM.Rd = $t1 = ID/EX.Rs → forward ALU result. (3)
(d) Without stalls, 5 instructions in 5-stage pipeline take cycles. Add 1 load-use stall → 10 cycles. (3)
Question 3
(a) Penalties per instruction:
- Branch:
- Load-use:
(4)
(b) Cycle time = ns. (3)
(c) New penalties:
- Branch:
- Load-use: Cycle time = ns. Speedup = . Faster by ~1.41×. (5)
Question 4
(a) In steady state, five instructions occupy the five stages each cycle. A structural hazard occurs whenever the instruction in the MEM stage (a load or store performing a data access) needs the memory port in the same cycle as the instruction in the IF stage fetching the next instruction. Both demand the single unified port simultaneously. (4)
(b) Every memory instruction (fraction ) collides once, adding 1 stall cycle: (3)
(c) : CPI . Slowdown vs ideal CPI 1 = 35% slower. (3)
Question 5
(a) An exception is precise if, when it is taken: (i) all instructions before the faulting instruction (in program order) have completed and updated architectural state; (ii) the faulting instruction and all instructions after it have not modified any architectural state; and (iii) the saved PC points exactly to the faulting instruction (or the next), enabling clean restart/resume. (3)
(b) On detecting I1's overflow in EX:
- Prevent I1 from writing back (squash its later MEM/WB effects). (1)
- Flush I2 (in ID) and I3 (in IF) — they must not complete, since they follow the faulting instruction. (1)
- Save I1's PC in EPC and set Cause register. (1)
- Redirect fetch to the exception handler address. Instructions older than I1 (already past EX) are allowed to finish. (1)
(c) Multiple exceptions can be pending in different stages in one cycle; to preserve program order semantics the exception of the oldest (earliest in program order) instruction must be taken first, because a precise exception requires all prior instructions to have completed and all later ones squashed — taking a later instruction's exception first would violate this. Between I1 (add, program order first) and I2 (lw, program order second), I1's exception takes precedence even though physically I2 might signal in a later cycle in the MEM stage. The pipeline handles exceptions in program order; I1 being older wins. (5)
[
{"claim":"Q1a single-cycle load period is 800 ps","code":"result = (200+100+150+250+100)==800"},
{"claim":"Q1b multi-cycle average CPI is 4.05","code":"cpi=0.25*5+0.10*4+0.45*4+0.15*3+0.05*3; result=abs(cpi-4.05)<1e-9"},
{"claim":"Q1b avg instruction time 1012.5 ps","code":"result=abs(4.05*250-1012.5)<1e-9"},
{"claim":"Q1c single-cycle faster, ratio ~1.2656","code":"result=abs((1012.5/800)-1.265625)<1e-6"},
{"claim":"Q2d total cycles 10","code":"result=(5+(5-1)+1)==10"},
{"claim":"Q3a CPI 1.18","code":"cpi=1+0.20*0.30*2+0.15*0.40*1; result=abs(cpi-1.18)<1e-9"},
{"claim":"Q3b time 0.59 s","code":"result=abs(1e9*1.18*0.5e-9-0.59)<1e-9"},
{"claim":"Q3c new CPI 1.42","code":"cpi=1+0.20*0.30*5+0.15*0.40*2; result=abs(cpi-1.42)<1e-9"},
{"claim":"Q3c speedup ~1.4127","code":"t1=1e9*1.18*0.5e-9; t2=1e9*1.42*(1/3.4e9); result=abs(t1/t2-1.4127)<1e-3"},
{"claim":"Q4c CPI 1.35 and 35% slowdown","code":"cpi=1+0.35; result=abs(cpi-1.35)<1e-9 and abs((cpi-1)/1-0.35)<1e-9"}
]