Pipeline Basics
Pipelining is the key technique for improving instruction throughput. We study the classic 5-stage MIPS pipeline (IF, ID, EX, MEM, WB), the three types of pipeline hazards (structural, data, control), and how pipelining affects CPI and overall performance.
Learning Objectives
Key Concepts
Five-Stage Pipeline
The classic MIPS pipeline has five stages:
- -IF (Instruction Fetch): read instruction from I-cache using PC
- -ID (Instruction Decode / Register Read): decode instruction, read registers
- -EX (Execute): ALU operation or address calculation
- -MEM (Memory Access): load from or store to D-cache
- -WB (Write Back): write result to register file
Each stage takes one clock cycle. With pipelining, up to 5 instructions overlap execution.
- -
Ideal pipeline CPI = 1 (one instruction completes per cycle)
- -
Pipeline registers (IF/ID, ID/EX, EX/MEM, MEM/WB) hold intermediate values between stages
- -
Pipeline speedup approaches the number of stages for long instruction streams
- -
Clock cycle time is determined by the slowest pipeline stage
Pipeline Hazards
Hazards are situations that prevent the next instruction from executing in the next cycle:
- -Structural hazards: two instructions need the same hardware resource simultaneously
- -Data hazards: an instruction depends on the result of a previous instruction still in the pipeline
- -Control hazards: the pipeline doesn't know the next instruction address (branches/jumps)
- -
RAW (Read After Write) is the most common data hazard — true dependency
- -
WAR (Write After Read) and WAW (Write After Write) are name dependencies — not a problem in simple in-order pipelines
- -
Structural hazards are avoided by design (e.g., separate I-cache and D-cache)
- -
Control hazards cause a pipeline flush on mispredicted branches (typically 1-3 cycle penalty)
Pipeline Performance
Pipeline performance is measured by how close the actual CPI is to the ideal CPI of 1. Stalls from hazards increase the effective CPI:
- -
Pipeline throughput = 1 instruction per cycle (ideal)
- -
Latency of a single instruction increases with pipelining (k cycles vs 1 cycle)
- -
Throughput is what matters for overall performance, not single-instruction latency