Computer architecture
Pipelining
Also called: instruction pipeline · 5-stage pipeline · IF ID EX MEM WB · throughput
Definition
Pipelining splits instruction execution into stages and overlaps them, so that while one instruction executes the next is being decoded and the one after is being fetched.
Picture it
It is a laundry line: washer, dryer, folding, each busy with a different load. Each instruction still takes five steps, but once the pipe is full one instruction finishes every cycle. Hazards, when an instruction needs something not ready yet, insert bubbles.
The maths
unpipelined: n × k cycles pipelined (ideal): k + (n − 1) cycles speed-up → k as n grows
| Quantity | Unit | Symbol |
|---|---|---|
| clock cycles | cycle (count) | 1 |
Worked example
How many cycles do 100 independent instructions take on a 5-stage pipeline, and without pipelining? What is the speed-up?
- Pipelined: 5 + 99 = 104 cycles
- Unpipelined: 100 × 5 = 500 cycles
- Speed-up = 500 / 104 = 4.81
Answer104 versus 500 cycles: about 4.81 times faster.
✓ The 2 numbers in this answer are recomputed from scratch by an automated test.
laundry line
Pipeline diagram
| Instruction | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| add r1, r2, r3 | IF | ID | EX | MEM | WB | |||||||
| sub r4, r1, r5 | IF | ID | ·· | ·· | EX | MEM | WB | |||||
| and r6, r4, r1 | IF | ·· | ·· | ID | ·· | ·· | EX | MEM | WB | |||
| or r7, r2, r3 | IF | ·· | ·· | ID | EX | MEM | WB |
Classic 5-stage in-order pipeline: register file written in the first half of WB and read in the second half of ID. A teaching model, not any specific processor.
Common misconceptions
- Misconception: Pipelining does not make one instruction faster; it improves throughput.
- Misconception: The speed-up is never quite k because of filling, draining and hazards.