← 🚰 Instruction Pipelining & Hazards
Subtopic 1 of 8

2.1Idea

The idea

Pipelining overlaps instructions: while one is executing, the next is already being decoded and the one after is being fetched.

Think of it like this: Laundry with a washer, dryer and folder: start the second load in the washer as soon as the first moves to the dryer.

Why it exists

Without it, most of the CPU sits idle waiting for a single instruction to finish all its stages. Pipelining uses every stage every cycle.

How it works

  1. Split an instruction into k stages (IF, ID, EX, MEM, WB).
  2. Each stage works on a different instruction in the same cycle.
  3. The first instruction needs k cycles; after that one instruction finishes every cycle.
  4. One instruction still takes k cycles (latency unchanged), but throughput rises.

Worked example: 5 stages, 3 instructions

Without a pipeline: 3 × 5 = 15 cycles. With a pipeline: k + n − 1 = 5 + 3 − 1 = 7 cycles.

Now play with it

  • →Press Play on both tabs and compare the finish times.
  • →In the graph drag "stages k" and see why speedup never exceeds k.
123456789101112131415
I1IFIDEXMEMWB
I2IFIDEXMEMWB
I3IFIDEXMEMWB

3 instructions × 5 cycles = 15 cycles. Hardware sits idle most of the time.

1100instructions n5.30speedup

instructions n = 10 → speedup = 3.571

Speedup nk/(k+n−1) climbs toward k but never reaches it.

Check yourself

A 5-stage pipeline runs 100 instructions with no stalls. How many cycles?

Remember: Time = (k + n − 1) cycles; speedup approaches k.
Exam notes (the dense version)

Overlap execution of instructions by splitting into stages (e.g. IF, ID, EX, MEM, WB). Improves throughput, not the latency of a single instruction.

Previous year questions: Instruction Pipelining & Hazards (15)

PYQs are grouped by topic, so this is the full set for Instruction Pipelining & Hazards; try the ones that match this subtopic. Open all 15 on the topic page.