Skip to content
Tactiverge

Textbooks/Digital Logic and Computer Architecture/Chapter 8

8Performance and pipelining

Version 1 · Technically checked (automated checks only) · 4 source lessons · 8 practice items

Text
All chapters and search
  1. 1. Information as bits
  2. 2. Logic gates and Boolean algebra
  3. 3. Combinational building blocks
  4. 4. Binary arithmetic
  5. 5. From silicon to switches
  6. 6. State machines and sequential logic
  7. 7. Instructions and the datapath
  8. 8. Performance and pipelining
  9. 9. The memory hierarchy
  10. 10. Power, performance and the chip

Introduction

How fast is a processor? The Iron Law splits the answer into three factors: instructions per program, cycles per instruction and time per cycle. This chapter finds what limits the clock period, then shows how pipelining overlaps instructions like an assembly line, and why hazards stop the overlap from ever being perfect.

12345678i1IFIDEXMEMWBi2IFIDEXMEMWBi3IFIDEXMEMWBi4IFIDEXMEMWBcycle → · 8 cycles pipelined, 20 one after another
Figure 8.1. Four instructions in a five-stage pipeline. A grid with four instructions as rows and eight clock cycles as columns. Each instruction passes through IF, ID, EX, MEM and WB, starting one cycle after the one before. All four finish in 8 cycles instead of the 20 cycles they would take one after another.

Explanation

This chapter is built from 4 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.

8.1 How fast can the clock tick?

Why can't a processor designer just set the clock to 100 GHz and make everything 25 times faster?

The critical path

Every path from a register output through gates to a register input must settle within one clock period. The longest one sets the clock. In a ripple-carry adder it is the carry rippling through every column: about 2 gate delays per bit, so a 32-bit ripple adder is roughly eight times slower than a 4-bit one.

Shortening it

Designers attack the critical path with faster circuits (carry-lookahead adders compute carries in parallel at the cost of more gates), or by pipelining: putting registers in the middle of a long path so each piece fits a shorter period. The clock speeds up; each operation now takes more cycles, but a new one can start every cycle.

More cycles or faster cycles?

Run time = cycles × T_clk. A single-cycle design does everything in one long cycle; a multi-cycle design (like the 3-step model in the stepper) uses several short ones. Which wins depends on how evenly the work splits: the iron law T = IC × CPI × T_clk keeps every trade-off honest.

Derivation: The register-to-register timing constraint
  1. At a clock edge the launching register's output changes after t_clk→Q.

  2. The new value travels through combinational logic; the slowest route, the critical path, takes t_logic.

  3. The capturing register needs its input stable for t_setup before the next edge.

  4. So the next edge must come no sooner than T_clk ≥ t_clk→Q + t_logic + t_setup, and f_max = 1/T_clk.

  5. Example: 0.2 + 10 × 0.1 + 0.1 = 1.3 ns, so f_max = 1/1.3 ns ≈ 769 MHz.

Common mix-ups

  • A faster clock always means a faster program.
    ✓ If faster clocks need more cycles per operation, run time = cycles × period may not improve.

Open the full lesson: How fast can the clock tick? →

8.2 Single-cycle, multi-cycle and the Iron Law

Chip A runs at 4 GHz, chip B at 2 GHz. B finishes your program first. How?

Single-cycle datapath

Every instruction completes in one long clock cycle, so CPI = 1, but the cycle must be long enough for the slowest path (instruction memory → register read → ALU → data memory → register write, for a load). Simple instructions waste most of the cycle.

Multi-cycle datapath

Break execution into steps (fetch, decode, execute, memory, write-back) and give each step one short cycle. Instructions use only the steps they need, so CPI is now an average (perhaps 4) but the cycle is about the length of one step. Hardware can be reused across steps: one memory and one ALU instead of separate ones.

Three factors, coupled

A richer instruction set lowers IC but may raise CPI or the cycle time. A deeper pipeline shortens the cycle but raises CPI when hazards hit. A good comparison quotes all three and measures them on the same program, compiled the same way, which is why benchmark suites exist.

Derivation: The Iron Law, from units
  1. Time per program = (instructions / program) × (cycles / instruction) × (seconds / cycle).

  2. The units cancel: instructions × cycles/instruction × seconds/cycle = seconds. So T = IC × CPI × t_clk = IC × CPI / f.

  3. IC is set by the algorithm, the compiler and the instruction set. CPI by the microarchitecture (pipelining, caches, prediction). t_clk by the circuit and the process technology.

  4. Speed-up of B over A = T_A / T_B = (IC_A/IC_B) × (CPI_A/CPI_B) × (f_B/f_A).

  5. Example: A has IC = 10⁹, CPI = 2, 4 GHz: T = 0.5 s. B has IC = 0.8×10⁹, CPI = 1.1, 2 GHz: T = 0.44 s. B wins by 0.5/0.44 ≈ 1.14× despite half the clock.

Common mix-ups

  • A higher clock frequency always means a faster computer.
    ✓ Only if IC and CPI stay the same. Execution time on the real workload is the only fair measure.
  • Multi-cycle machines are slower because CPI > 1.
    ✓ Their cycle is much shorter, so time per instruction can be lower; CPI alone says nothing.

Open the full lesson: Single-cycle, multi-cycle and the Iron Law →

8.3 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?

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.

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).

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.

Open the full lesson: Pipelining: an assembly line for instructions →

8.4 Hazards, forwarding and branch prediction

An instruction needs a number the previous one hasn't finished computing. Does the whole assembly line stop?

Data hazards

A read-after-write hazard occurs when an instruction needs a register that an earlier, still-in-flight instruction will write. Without help, the reader stalls in ID until the writer reaches WB: 2 bubbles for adjacent instructions in the classic 5-stage pipe. Forwarding (bypassing) wires the ALU output straight back to the ALU input, removing the stall for ALU results.

The load-use stall

A load's data appears only at the end of MEM. Even with forwarding, an instruction that uses it immediately must wait one cycle. Compilers hide this by scheduling an independent instruction between the load and its use, which is why the 'Load then use' program in the pipeline diagram has an unrelated sub in the middle.

Control and structural hazards

A branch is not resolved until EX, so the pipeline has already fetched 2 instructions that may be wrong. Stalling on every branch wastes those cycles always; predict not taken wastes them only when the branch is taken; dynamic predictors learn each branch's habit and are right well over 90% of the time on typical code. A structural hazard arises when two stages need one resource, like a single memory port for fetch and data: hence separate instruction and data caches.

Hazards in the Iron Law

Every stall adds to CPI: CPI = 1 + (data stalls per instruction) + (branch fraction × mispredict rate × penalty) + (memory stalls). Deeper pipelines raise the branch penalty, so a faster clock can lose to a shorter pipe with a better predictor.

Common mix-ups

  • Forwarding removes all data hazards.
    ✓ It cannot help a load followed immediately by its use: the data does not exist yet.
  • Branch prediction is a guess, so it cannot be relied on.
    ✓ Wrong guesses are detected and flushed; prediction only affects speed, never correctness.

Open the full lesson: Hazards, forwarding and branch prediction →

Worked examples

How fast can the clock tick?: example 1

A 16-bit ripple adder has 2 gate delays per bit plus 1, at 0.08 ns each, between registers with t_cq = 0.15 ns and t_su = 0.1 ns. Find f_max.

Solution

Gate delays = 2 × 16 + 1 = 33; t_logic = 2.64 ns. T = 0.15 + 2.64 + 0.1 = 2.89 ns. f_max ≈ 346 MHz.

Single-cycle, multi-cycle and the Iron Law: example 1

A mix is 50% ALU (4 steps), 20% loads (5), 10% stores (4), 20% branches (3). Step time 200 ps. Compare with an 800 ps single-cycle design.

Solution

CPI = 0.5×4 + 0.2×5 + 0.1×4 + 0.2×3 = 4.0. Time per instruction = 4.0 × 200 ps = 800 ps: a tie. Shorten the step to 180 ps (balancing stages better) and multi-cycle wins: 720 ps.

Pipelining: an assembly line for instructions: 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.

Solution

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

Hazards, forwarding and branch prediction: example 1

lw r1, 0(r2) then add r3, r1, r4, with forwarding. Stalls?

Solution

  1. The loaded value exists only after MEM; add's EX must come the cycle after lw's MEM, one cycle later than it would without the dependency.
Hazards, forwarding and branch prediction: example 2

Branches are 15% of instructions; a predictor is wrong 8% of the time; the penalty is 3 cycles. Extra CPI?

Solution

0.15 × 0.08 × 3 = 0.036. With base CPI 1, effective CPI 1.036.

Interactive figures

Figure 8.2 from Pipelining: an assembly line for instructionsChoose '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.
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.

Interactive figure (online). Description: 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.

Figure 8.3 from Hazards, forwarding and branch predictionEvery stall cycle adds to CPI, and this calculator shows how much. Set branches to 20%, mispredict to 10% and penalty to 2: read the CPI. Raise the penalty to 15 (a deep pipeline) and watch the branch slice grow. Pin a design, then trade a faster clock for a bigger penalty and read the speed-up.
Can't use the interactive? Read a description instead

The Iron Law calculator shows CPI as base + branch stalls + memory stalls. With 20% branches, 10% mispredicted at 2 cycles, and 30% memory instructions missing 5% at 40 cycles, CPI = 1 + 0.04 + 0.6 = 1.64, and T = IC × CPI ÷ f.

Interactive figure (online). Description: The Iron Law calculator shows CPI as base + branch stalls + memory stalls. With 20% branches, 10% mispredicted at 2 cycles, and 30% memory instructions missing 5% at 40 cycles, CPI = 1 + 0.04 + 0.6 = 1.64, and T = IC × CPI ÷ f.

Laboratory

Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.

Guided practice

Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.

Practice 1

t_clk→Q = 0.2 ns, logic = 1.0 ns, t_setup = 0.1 ns. What is f_max, in MHz (nearest whole number)?

MHz

Practice 2

What sets the maximum clock frequency of a synchronous design?

Practice 3 · a fresh version every time

A program executes 750 million instructions with an average CPI of 0.8 on a 2 GHz processor. How long does it take, in milliseconds?

ms

Practice 4

Design A: CPI 1.6 at 3 GHz. Design B: CPI 1.0 at 2.4 GHz, same instruction count. What is B's speed-up over A?

×

Practice 5 · 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

Practice 6

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?

×

Practice 7

lw r5, 4(r2) / add r6, r5, r1. Which hazard and, with forwarding, how many stall cycles?

Practice 8

On the classic 5-stage pipeline with no forwarding, a chain of 4 ALU instructions each uses the previous one's result. How many total cycles? (Ideal is 8.)

cycles
  1. t_clk→Q = 0.2 ns, logic = 1.0 ns, t_setup = 0.1 ns. What is f_max, in MHz (nearest whole number)? (MHz)
  2. What sets the maximum clock frequency of a synchronous design?
    • The shortest register-to-register path
    • The longest register-to-register path (the critical path)
    • The number of registers
    • The supply voltage only
  3. A program executes 750 million instructions with an average CPI of 0.8 on a 2 GHz processor. How long does it take, in milliseconds? (ms)
  4. Design A: CPI 1.6 at 3 GHz. Design B: CPI 1.0 at 2.4 GHz, same instruction count. What is B's speed-up over A? (×)
  5. 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)
  6. 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. lw r5, 4(r2) / add r6, r5, r1. Which hazard and, with forwarding, how many stall cycles?
    • Structural, 0
    • Data (load-use), 1
    • Control, 2
    • Data, 0 thanks to forwarding
  8. On the classic 5-stage pipeline with no forwarding, a chain of 4 ALU instructions each uses the previous one's result. How many total cycles? (Ideal is 8.) (cycles)

Engineering applications

  • Comparing processors fairly

    A higher clock frequency does not guarantee a faster program: if the faster clock needs more cycles per instruction, the Iron Law can come out worse. Engineers compare time for the same program.

  • Real-time control

    A control loop must finish within its sample period every time. Pipeline stalls and branch mispredictions make timing vary, so real-time systems often measure worst-case time, not average time.

Watch

Optional verified videos. Nothing loads from YouTube until you press play.

Covers caches, pipelining, branch prediction and multiple cores: the tricks that make processors fast, in one sitting.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

  • Advanced CPU Designs: Crash Course Computer Science #9 (CrashCourse)

Chapter summary

  • Iron Law: time per program = instructions per program × cycles per instruction × time per cycle.
  • The clock period must be at least the delay of the slowest (critical) path between registers.
  • An ideal k-stage pipeline finishes n instructions in k + n − 1 cycles; throughput approaches one instruction per cycle.
  • Data, control and structural hazards add stall cycles; forwarding and branch prediction remove many of them.

Glossary

Pipelining
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.
Pipeline hazards and forwarding
A hazard is a situation where the next instruction cannot proceed on schedule. Data hazards happen when an instruction needs a result an earlier one has not finished producing.
Clock speed, cycles and CPI
Execution time equals the number of instructions times the average cycles per instruction (CPI) divided by the clock frequency.
Amdahl's law
Amdahl's law says the overall speed-up from improving part of a task is limited by the fraction of time that part takes.
Propagation delay
Propagation delay is the time a gate's output takes to respond to a change at its input. The slowest path between flip-flops, the critical path, sets the fastest safe clock.

Definitions from the Field Guide.

Project: Pipeline or not?

A single-cycle design has a 10 ns critical path. Splitting it into five stages adds 0.5 ns of register overhead per stage, and 20 % of instructions stall for one cycle. Estimate the time per instruction for both designs and decide whether pipelining pays, showing every step.

Deliverables

  • The pipelined clock period with the overhead included
  • The average CPI with stalls
  • Time per instruction for both designs and the speed-up
  • One assumption that could change your answer

Keep your work in your Engineering Journal; it stays private unless you choose to share it.

References

  • David A. Patterson and John L. Hennessy (2017). Computer Organization and Design RISC-V Edition: The Hardware Software Interface. Morgan Kaufmann.
  • John L. Hennessy and David A. Patterson (2017). Computer Architecture: A Quantitative Approach, 6th edition. Morgan Kaufmann.

Publication record

Version
1
Status
Technically checked (automated checks only)
Technical review
Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
Written by
Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
Licence
All rights reserved by the founders unless a licence is approved.
Corrections
None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.