Skip to content
Tactiverge

School/✦ Research Engineer/Week 20

Pipelining: an assembly line for instructions

A laundry takes 30 minutes to wash, 40 to dry and 20 to fold. How long do four loads take if you never wait for one to finish before starting the next?

About 45 min · 3 goals · Checked by automated tests

1.Why should I care?

Pipelining is why one processor core retires billions of instructions per second. It is also a general engineering pattern: video codecs, network routers and factory lines all overlap stages. Understanding its limits stops you expecting a 20-stage pipeline to be 20 times faster.

  • ◇ Draw a pipeline diagram for n instructions on a k-stage pipeline and count total cycles k + n − 1.
  • ◇ Explain why pipelining improves throughput but not the latency of one instruction.
  • ◇ Derive the limit on pipeline speed-up from stage imbalance and register overhead.

2.Discover

Choose 'Independent ALU ops', turn forwarding on and choose 'Perfect predictor'. Read the diagonal staircase and check the cycle count against k + n − 1. Then pick the other programs to see the ideal break: that is next lesson's topic.

Loading the interactive…

Can't use the interactive? Read a description instead

The pipeline table has one row per instruction and one column per clock cycle; each instruction's IF, ID, EX, MEM and WB cells shift one column to the right of the previous instruction's, forming a staircase. For 5 independent instructions it ends at cycle 9.

3.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1 · a fresh version every time

127 instructions run on a 4-stage pipeline. Hazards insert 6 stall cycles in total. How many clock cycles until the last instruction completes?

cycles

4.Predict

5 instructions on an ideal 5-stage pipeline (one cycle per stage, no hazards). How many cycles?

Guess first. Being wrong here is how the surprise works.

5.Understand

Throughput versus latency

Pipelining does not make one instruction faster: it still passes through every stage, and register overhead makes it slightly slower. What improves is throughput: once full, the pipeline completes one instruction every cycle. Ideal CPI approaches 1 for long runs.

The classic five stages

IF fetches the instruction, ID decodes it and reads registers, EX uses the ALU, MEM accesses data memory, WB writes the result back. Registers between stages hold each instruction's state so the stages can work on different instructions at once.

Balance and overhead

The clock must suit the slowest stage, and every stage boundary adds a register's setup and clock-to-output delay. Deeper pipelines get diminishing returns and, as you will see, pay more for every hazard. Modern designs settle on roughly 10–20 stages as a compromise.

Explain it another way

A sandwich bar with one person doing everything makes a sandwich every 4 minutes. Four people, each doing one step, make one every minute once the line is going, though each sandwich still takes 4 minutes.

Derivation: How much faster can a pipeline be?
  1. Unpipelined: each instruction takes T, so n instructions take n·T.

  2. Split into k stages. If perfectly balanced, each stage is T/k, but each needs a pipeline register adding overhead o. Cycle = T/k + o.

  3. Pipelined time for n instructions = (k + n − 1)(T/k + o).

  4. Speed-up S = n·T / ((k + n − 1)(T/k + o)). As n → ∞, S → T/(T/k + o) = k / (1 + k·o/T).

  5. With no overhead the limit is k. With o = 0.1 T, a 5-stage pipe tops out at 5/1.5 ≈ 3.3×; a 20-stage pipe at 20/3 ≈ 6.7×, not 20×.

  6. Unbalanced stages are worse: the cycle is set by the slowest stage, so S ≤ T / max(stage delay).

Worked example 1

Stages of 200, 150, 250, 300 and 100 ps, register overhead 20 ps. Find the cycle time and the speed-up for many instructions versus the 1000 ps unpipelined design.

Cycle = slowest stage + overhead = 300 + 20 = 320 ps. Limit speed-up = 1000/320 ≈ 3.1×, well below 5× because the stages are unbalanced.

Common mix-ups

  • A k-stage pipeline makes the processor k times faster.
    ✓ Only with perfect balance, no overhead, no hazards and infinitely long programs. Real gains are smaller.
  • Pipelining makes each instruction finish sooner.
    ✓ It makes instructions finish more often. Each one still takes all k stages.

6.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2 · a fresh version every time

A single-cycle datapath has a 5 ns cycle. It is split into 10 equal stages, each adding 0.1 ns of register (latch) overhead. What is the speed-up for 100 instructions with no stalls?

×

Practice 3

Compared with the unpipelined design, the latency of a single instruction in a pipeline is…

Practice 4 · a fresh version every time

83 instructions run on a 8-stage pipeline. Hazards insert 9 stall cycles in total. How many clock cycles until the last instruction completes?

cycles

Practice 5

A 1,200 ps datapath is split into 6 perfectly balanced stages with 50 ps register overhead each. What is the speed-up limit for very long programs?

×

7.Apply it

Sketch a 4-stage pipeline for a robot's sensor loop: read sensor, filter, decide, actuate. Give each stage a realistic time, find the cycle time and throughput, then argue whether the pipeline's extra latency is acceptable for a control loop.

8.Reflect

Concepts: Pipelining, hazards and the Iron Law · Sequential logic and memory