Worked examples — Pipelining — 5-stage pipeline, each stage
You have built the machinery in the parent note: the five stages IF, ID, EX, MEM, WB, the timing law , the speedup , and the fact that pipelines can stall when instructions depend on each other. This page does one thing: it drags those formulas through every kind of situation they can meet, so no exam problem surprises you.
Before any symbol appears, let us re-anchor the three numbers we will use constantly:
Because every example leans on the same two laws, let us restate them here on this page (they were derived in the parent) so you never have to leave to remember where they came from:
The scenario matrix
Every problem on this topic is one (or a blend) of these cells. We will hit all of them.
| Cell | What makes it special | Where it bites |
|---|---|---|
| A. Large | Speedup near its ceiling | |
| B. Small | comparable to | Fill cycles dominate, speedup poor |
| C. Degenerate | a single instruction | Speedup : pipelining does nothing |
| D. Limiting | infinite stream | Speedup exactly |
| E. Unbalanced stages | stages have different delays | Clock set by the slowest stage, not the average |
| F. Register overhead | latch adds | Real clock period grows, speedup shrinks |
| G. Stalls / hazards | bubbles inserted | Effective cycles |
| H. Word problem | real throughput in instr/sec | Translate cycles ↔ seconds |
| I. Exam twist | "how many stages for a target speedup?" | Solve the formula backwards |
Each worked example below is tagged with the cell(s) it covers.
Example 1 — Cell A (large , the happy case)
Steps.
-
Non-pipelined time. Each instruction visits all boxes, so it takes ; do that times in a row. Why this step? This is the baseline we are trying to beat — no overlap at all.
-
Pipelined time. Fill the pipe with cycles, then one instruction leaves every cycle for the remaining . Why this step? The fill cost is paid once; after that it is one-per-tick.
-
Speedup = old time ÷ new time. Why this step? Speedup answers "how many times faster", so it is a ratio of the two times.
Recall Verify (Example 1)
. Same as . ✓ Close to the ceiling , as Cell A predicts.
Example 2 — Cell B (small , pipelining barely helps)
Steps.
-
Non-pipelined: . Why this step? Baseline again.
-
Pipelined: . Why this step? Notice cycles for instructions — the fill cycles () are a huge fraction here.
-
Speedup: . Why this step? Ratio of times.
What the figure below shows (read it before moving on): three colored instruction rows (blue, orange, green) march diagonally down-right through the five labelled stage boxes IF→ID→EX→MEM→WB. Reading any vertical column tells you which stages are busy in that clock cycle. The gray slab along the bottom marks the first four cycles — the fill cycles () during which the pipe is not yet producing one finished instruction per tick. The red double arrow spans the full width and labels the total, cycles. Notice visually how wide the gray fill region is compared to the useful region when is only 3.

Recall Verify (Example 2)
. ✓ Much less than 5 — Cell B confirmed: fill cycles dominate.
Example 3 — Cell C (the degenerate single instruction)
Steps.
-
Non-pipelined time for one instruction: . Why this step? One instruction, all five stages.
-
Pipelined time: . Why this step? Plug into : the term vanishes. Nothing overlaps because there is nothing to overlap with.
-
Speedup: . Why this step? Equal times ⇒ ratio ⇒ no gain.
Recall Verify (Example 3)
. ✓
Example 4 — Cell D (the limiting value )
Steps.
-
Write the general speedup and divide top and bottom by . Why this step? Dividing by isolates how each term behaves as grows — the tool for "what happens in the limit."
-
Let . The term . Why this step? This is the limit: the value the sequence hugs but never quite touches.
-
Confirm it never reaches for finite : since always, the denominator is , so strictly. Why this step? Answers the "approaches but never equals" part.
What the figure below shows (read it before moving on): a blue curve of against the number of instructions . It rises steeply for small , then bends over and flattens. The dashed red horizontal line at height is the ceiling ; the blue curve creeps toward it but never touches it. The green dot at sits at height (the degenerate case of Example 3), and the gray annotation points to where the curve "flattens toward 5". The visual message: extra instructions give big gains at first, then almost none.

Recall Verify (Example 4)
At : — under 5, and closer than at . ✓ The limit is .
Example 5 — Cell E + F (unbalanced stages and register overhead)
We will need one total time and one per-cycle time here, so to avoid clashing with (the total non-pipelined time), we name the single-cycle clock period .
Steps.
-
Non-pipelined (single-cycle) period = whole instruction = sum of stages. Why this step? With no latches, one clock does the entire journey; see Single-cycle vs Multi-cycle Datapath. This is a per-instruction period, not the total .
-
Pipelined clock = slowest stage + register overhead. Not the average — the whole pipe waddles at the pace of its slowest member. Why this step? Every stage must fully finish inside one tick; the worst stage sets the tick.
-
Times. Non-pipelined total: . Pipelined: . Why this step? Now is , not an idealised balanced value.
-
Speedup: . Why this step? Ratio — far below the ceiling because the pipe is unbalanced and pays register overhead.
Recall Verify (Example 5)
; ; ; . ✓
What the figure below shows (read it before moving on): four vertical bars, one per stage, with heights equal to the stage delays ns (each labelled). The tallest bar (orange, 5 ns) is the bottleneck. A red slab of height ns sits on top of that tallest bar, and a dashed red line runs across the whole plot at height ns — the clock period. Visually, the short bars (like the 2 ns one) leave empty space below the dashed line: that empty space is idle time, hardware sitting still because the whole pipe waits for the 5 ns stage.

Example 6 — Cell G (a stall / hazard adds bubbles)
Steps.
-
Ideal pipelined cycles (no stalls): cycles. Why this step? Start from the perfect world, then add penalties.
-
Add the stall bubbles. Each stall injects 1 extra cycle; 4 stalls ⇒ cycles. Why this step? A bubble is a wasted tick where the pipe advances a "do-nothing" so the dependency resolves.
-
Times. . Non-pipelined: . Why this step? Convert cycles to time with ns.
-
Effective speedup: . Why this step? Ratio. Compare to the stall-free value — the hazards cost about of speedup.
Recall Verify (Example 6)
Stall-free cycles , with 4 stalls ; ; ideal-with-no-stall . ✓ Bubbles bite.
Example 7 — Cell H (word problem: instructions per second)
Before the numbers, one new word we will lean on:
Steps.
-
Ideal throughput = one instruction per cycle. With , that is Why this step? Throughput is 1 instr per tick in the ideal pipe; convert ticks to seconds.
-
Account for stalls via CPI. Each instruction costs cycle plus of a bubble cycle on average, so the effective Why this step? CPI is exactly the tool for folding stalls into an average cost per instruction; ideal CPI is 1, stalls push it up.
-
Sustained throughput = one instruction per (CPI × clock period). Why this step? More cycles per instruction ⇒ fewer instructions per second.
-
Compare: — you keep about of ideal, losing . Forecast confirmed. Why this step? Sanity check that the loss matches the overhead of adding 0.1 cycle onto 1.1.
Recall Verify (Example 7)
Effective CPI ; throughput instr/s; fraction of ideal . ✓
Example 8 — Cell I (exam twist: solve the formula backwards)
Steps.
-
For , Example 4 showed . So to get ideally, you need Why this step? In the limit the ceiling is the stage count — invert it directly.
-
Reality check — why not ? First define the two clock models so we can reconcile them:
- In Example 5 the stages were given individually and were unbalanced, so the clock was set by the single worst stage: .
- Here we imagine instead taking one fixed lump of logic — call its total delay (the "combinational work" of the whole instruction, in ns) — and slicing it evenly into equal stages. Even slicing means each stage's delay is , so the clock becomes These are the same rule ( stage ); the second is just the ideal special case where every stage is equal to , so the max equals . Use the form when stage delays are given; use the form when you are free to slice a total delay into balanced pieces. Why this step? We must express in terms of to see what happens as grows.
-
Now watch as grows. The useful term shrinks toward , but is fixed. So the clock cannot fall below no matter how many stages you add — beyond some the register overhead dominates and extra stages barely raise real speedup, while hazards/branch penalties grow with depth (see Branch Prediction and Superscalar and Out-of-Order Execution). Why this step? Answers the twist: the ideal is necessary, but deeper is not freely better.
-
Practical answer: the smallest that keeps stages balanced, here . Why this step? meets the target; gives a limiting speedup of only .
Recall Verify (Example 8)
Ideal limit , so ⇒ smallest integer ; check gives limiting . ✓ And gives only . ✓
Coverage check
Recall Which example covered which matrix cell?
A → Ex 1 · B → Ex 2 · C → Ex 3 · D → Ex 4 · E,F → Ex 5 · G → Ex 6 · H → Ex 7 · I → Ex 8. Every cell hit.
Related depth: for why stalls happen and how forwarding removes some, jump to Pipeline Hazards (Data, Control, Structural) and Forwarding and Bypassing; for the fundamental limit on any speedup from a partial improvement, Amdahl's Law.