Computer Organization
Pipelining
Ideal speedup ≈ stages — then subtract reality with stalls, hazards, and branch penalties.
GATE CSE instruction pipelining — ideal speedup, stalls, RAW/WAR/WAW, control hazards, forwarding, branch penalty, with samples and drills.
Learning outcomes
- Compute ideal and stall-adjusted pipeline speedup and effective CPI
- Classify structural, data (RAW/WAR/WAW), and control hazards with examples
- Explain how forwarding reduces many RAW stalls and when a load-use stall remains
- Account for branch penalties and pipeline fill/flush in numericals
Pipeline idea & ideal speedup
- Instruction pipelining overlaps stages of successive instructions (classic 5-stage: IF, ID, EX, MEM, WB).
- Balanced k-stage pipeline, no hazards, large N: speedup approaches k versus a non-pipelined design whose cycle equals the sum of the stage delays.
- Throughput approaches 1 instruction per clock once the pipe is full. Latency of one instruction remains about k clocks — pipelining improves throughput, not single-instruction latency.
- Pipeline registers sit between stages and hold intermediate results plus control. Clock period is set by the slowest stage (+ overhead).
- Fill (startup) and flush overhead become negligible when N is large — GATE often says “large number of instructions”.
Formulas to remember
-
Ideal speedup ≈ k (balanced, no stalls, large N) -
Speedup = T_nonpipe / T_pipe -
Time_pipe ≈ (k + N − 1) × T_clk (no stalls) -
CPI_pipe ≈ 1 + stalls_per_instruction
| Stage | Typical work | Writes / reads |
|---|---|---|
| IF | Fetch instruction | I-mem / I-cache |
| ID | Decode / read regs | Register file read |
| EX | ALU / EA / branch | ALU, flags |
| MEM | Load/store | D-mem / D-cache |
| WB | Write result | Register file write |
Worked example
Problem. 5-stage pipe, clock 2 ns. Non-pipe cycle 10 ns. Ideal speedup for large N?
Solution. Non-pipe ≈ 10 ns/instr; pipe ≈ 2 ns/instr ⇒ speedup ≈ 5.
Hazards, stalls & forwarding
- Structural hazard: two instructions need the same hardware resource in the same cycle (e.g., a single memory port for IF and MEM).
- Data hazards: RAW (read after write — true dependence), WAR (write after read), WAW (write after write). In a simple in-order 5-stage pipe, RAW is the main concern; WAR/WAW matter more with out-of-order / multi-issue.
- Control hazard: next PC is unknown or wrong until a branch/jump resolves — may require stall, flush, or prediction.
- Forwarding/bypassing routes an ALU/MEM result to a later instruction’s EX inputs before WB completes — eliminates many RAW stalls.
- Load-use hazard: a load’s data is available only after MEM; an immediately following consumer often needs one stall even with forwarding.
- Stall / bubble: insert a wait cycle (NOP-like slot) when the hazard cannot be resolved in time. Average stalls per instruction raise CPI above 1.
- Branch penalty: number of wasted cycles on a taken/mispredicted branch (flush wrong-path instructions). Speedup numericals often give fraction of branches × penalty.
Formulas to remember
-
CPI ≈ 1 + stall_cycles_per_instruction -
Speedup ≈ k / CPI (when non-pipe cycle ≈ k pipe clocks) -
Extra branch stalls ≈ (branch fraction) × (penalty) × N
Worked example
Problem. Average 0.25 stall cycles per instruction. Effective CPI?
Solution. CPI ≈ 1 + 0.25 = 1.25.
GATE exam tricks — pipeline
- Speedup ≈ k only if hazard-free and stages are balanced — check for stalls in the stem.
- Effective CPI = 1 + average stall cycles per instruction — not “stalls alone”.
- RAW = read after write; don’t swap with WAR.
- Forwarding does not fix everything — load-use often still stalls one cycle.
- Deeper pipelines can raise clock rate but also raise branch penalty and forwarding complexity.
- If non-pipe cycle time equals k × T_clk, ideal speedup is k; if the stem gives different times, use T_old/T_new directly.
- Count pipeline bubbles on a sketch for short code sequences — GATE loves 4–6 instruction traces.
Worked example
Problem. 5-stage pipe, CPI=1.25 due to stalls, non-pipe cycle = 5 pipe clocks. Speedup?
Solution. Non-pipe CPI≈5 pipe clocks/instr; pipe effective 1.25 ⇒ speedup ≈ 5/1.25 = 4.
Exam tips
- State assumptions: forwarding? branch penalty?
- CPI ≈ 1 + stalls/instr.
- Ideal speedup ≠ always equal to stage count once stalls appear.
- Sketch IF–ID–EX–MEM–WB for short dependency chains.
- Separate throughput (instr/cycle) from per-instruction latency.
10 GATE-style MCQs for Pipelining with full explanations. Attempt each question before revealing the answer.
Ideal speedup of balanced 5-stage pipe (no hazards, large N) vs non-pipe cycle = 5 pipe clocks:
Show answer & explanation
Answer: C
Throughput 1/clock vs 1 per 5 clocks ⇒ ≈5.
RAW hazard means:
Show answer & explanation
Answer: B
Read After Write.
Average 0.25 stall cycles/instr ⇒ CPI about:
Show answer & explanation
Answer: B
1 + 0.25 = 1.25.
Forwarding primarily reduces:
Show answer & explanation
Answer: B
Bypass paths for data hazards.
Structural hazard example:
Show answer & explanation
Answer: B
Resource conflict.
Control hazard relates to:
Show answer & explanation
Answer: B
Next PC uncertain.
Pipeline bubble means:
Show answer & explanation
Answer: B
Inserted wait / nop-like slot.
Latency of one instruction in a 5-stage pipe (no stall) is about:
Show answer & explanation
Answer: B
Still passes 5 stages.
Load-use hazard often needs:
Show answer & explanation
Answer: B
Result not ready for immediate next use.
Speedup with stalls is generally:
Show answer & explanation
Answer: B
Stalls reduce throughput.
Extra page-specific practice beyond the GATE samples. Attempt all 10, then reveal answers to check your reasoning.
4-stage ideal speedup (no hazards) ≈
Show answer & explanation
Answer: C) 4
Approaches stage count.
0.2 stalls/instr ⇒ CPI ≈
Show answer & explanation
Answer: B) 1.2
1 + 0.2.
WAR hazard is:
Show answer & explanation
Answer: A) Write After Read
Name dependency ordering.
Branch penalty of 2 cycles every 5 instrs adds stalls/instr:
Show answer & explanation
Answer: B) 0.4
2/5 = 0.4.
Throughput of a full ideal pipe is about:
Show answer & explanation
Answer: A) 1 instr / clock
One completion per clock when full.
Flushing a pipe after mispredict discards:
Show answer & explanation
Answer: B) Wrong-path instructions in flight
Control hazard recovery.
Balanced stages matter because:
Show answer & explanation
Answer: A) Clock set by slowest stage
Critical stage limits clock.
Data hazard not helped by forwarding alone when:
Show answer & explanation
Answer: A) Result needed immediately after load
Classic load-use.
Non-pipe time 10 ns/instr, pipe 2 ns/instr (ideal) ⇒ speedup:
Show answer & explanation
Answer: B) 5
10/2 = 5.
Pipeline speedup compares:
Show answer & explanation
Answer: B) Non-pipe latency/throughput vs pipelined
T_nonpipe / T_pipe.
Topic FAQs
Does pipelining reduce instruction latency to 1 cycle?
No. Throughput rises toward 1 instr/cycle; each instruction still flows through multiple stages.
What does forwarding fix?
Many RAW data hazards by bypassing results before write-back completes.
What is a pipeline bubble?
A stall cycle in which a stage holds no useful instruction work (an inserted wait/NOP-like slot).
Why can a load-use pair still stall with forwarding?
Load data is ready only after the MEM stage, so the next instruction’s EX often cannot receive it in time without one stall.
Hover a card to reveal the answer with a 3D flip. On touch devices, tap the card or use Show answer.