Instruction pipelining
Overlapping the execution of instructions: the stages and pipeline registers, the space-time diagram, fill and drain, latency versus throughput, the clock set by the slowest stage plus register overhead, balancing and splitting stages, and why uniform RISC instructions pipeline well.
Why it exists
In the instruction cycle a processor fetches, decodes, executes and writes the result of one instruction, then starts the next. While the ALU is executing, the instruction memory sits idle and the decoder sits idle. Pipelining puts every part of the hardware to work at once: it splits the instruction into stages, gives each stage its own hardware, and lets several instructions be in different stages in the same clock cycle, like cars on an assembly line. One instruction is no faster, but one finishes every cycle. GATE asks for the number of cycles, the speedup, the clock period of a pipeline and what limits it; the next page does the full arithmetic, and the hazard pages deal with what goes wrong.
Prerequisites
You need the steps of the instruction cycle, which become the pipeline's stages.
Precise definitions
Pipeline. A processing unit divided into stages. A pipeline register (latch) between consecutive stages holds the results of one stage while the next one uses them. On each clock cycle every instruction moves one stage forward and a new instruction enters the first stage.
The classic five stages (the textbook teaching pipeline):
| Stage | Name | Work |
|---|---|---|
| IF | instruction fetch | read the instruction at PC, compute PC + 4 |
| ID | instruction decode | decode, read the source registers |
| EX | execute | ALU operation, or compute the address of a load, store or branch |
| MEM | memory access | read or write the data memory (loads and stores only) |
| WB | write back | write the result into a register |
Other splits are common in questions: a 4-stage pipeline (fetch, decode, execute, write back), or the six-stage one used in some books (fetch instruction, decode instruction, calculate operands, fetch operands, execute, write operand). Always use the number of stages the question gives.
Space-time (pipeline) diagram. A table with a row per instruction and a column per clock cycle; each cell names the stage the instruction occupies. It is the main tool for counting cycles. In a diagram without stalls, instruction () is in stage () during cycle .
Fill, steady state and drain. For the first cycles the pipeline is filling: some stages are idle. From cycle on, every stage is busy and one instruction completes per cycle. After the last instruction is fetched the pipeline drains.
Latency and throughput.
- The latency of one instruction is the time from entering the first stage to leaving the last: cycles. Pipelining does not shorten it (and with register overhead it lengthens it).
- The throughput is the number of instructions completed per unit time: ideally one per cycle.
Clock cycle. All stages share one clock, so the period must cover the slowest stage plus the delay of the pipeline register (setup time and clock-to-output delay):
If the stages are unequal, the fast stages wait for the slowest one (waste). Balancing the stages, by moving work between them or splitting the slowest one in two, shortens the clock but adds a stage and a register.
What the pipeline registers carry. Everything later stages need: the instruction fields, the register values read, the ALU result, the data loaded, and the control signals for the remaining stages. The control information travels with its instruction, so each stage knows what to do for the instruction currently in it.
Why RISC pipelines well. Fixed-length instructions make the fetch and decode stages uniform; simple instruction formats let decoding and register reading happen together; loads and stores are the only instructions that access memory, so the MEM stage is used predictably; and each instruction needs each stage at most once and in the same order. Instructions of widely different lengths and complexity (many CISC instructions) leave stages unbalanced and some instructions needing a stage several times, which is why they are translated to simple internal operations before pipelining.
Stall (bubble). A cycle in which an instruction is held in its stage, or in which a stage does nothing useful, because the instruction cannot proceed. Stalls lower throughput below one instruction per cycle; their causes are the subject of pipeline hazards.
How it works
The first animation is the baseline: three instructions on a machine without a pipeline. One instruction runs through all five stages before the next starts, so at any moment four of the five stages are idle.
Without a pipeline: three instructions one after another: start
Pipeline simulated, not typed| cycle | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| I1 | |||||||||||||||
| I2 | |||||||||||||||
| I3 |
Step 0
The pipeline is empty. Each row is an instruction, each column a clock cycle, and a cell says which stage of the 5-stage pipeline (IF, ID, EX, MEM, WB) the instruction is in during that cycle.
The second animation is the same hardware pipelined. Step through it and watch the fill (cycles 1 to 4), the full pipeline (cycle 5 onward: five different instructions in five different stages) and the drain. Six instructions finish in cycles, against 30 without the pipeline.
A 5-stage pipeline, six instructions, no stalls: start
Pipeline simulated, not typed| cycle | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| I1 | ||||||||||
| I2 | ||||||||||
| I3 | ||||||||||
| I4 | ||||||||||
| I5 | ||||||||||
| I6 |
Step 0
The pipeline is empty. Each row is an instruction, each column a clock cycle, and a cell says which stage of the 5-stage pipeline (IF, ID, EX, MEM, WB) the instruction is in during that cycle.
The third animation shows what a stall does to the diagram. It is the subject of the next pages; for now notice that a held instruction blocks all those behind it, and every extra cycle is paid by everything after it.
The same pipeline when two instructions are held up: start
Pipeline simulated, not typed| cycle | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| I1 | |||||||||||||
| I2 | |||||||||||||
| I3 | |||||||||||||
| I4 | |||||||||||||
| I5 | |||||||||||||
| I6 |
Step 0
Same pipeline, but I3 must stay in ID for 2 extra cycles and I5 for 1 extra cycle (for example because each is waiting for a result; the hazard pages explain why and how to shorten the wait). Every instruction behind a held one is blocked as well.
Worked examples
EX 1Counting cycles with and without a pipeline
EasyA 5-stage pipeline with one-cycle stages and no stalls. How many cycles do instructions need with and without pipelining?
#include <stdio.h>
int main(void) {
int k = 5;
long ns[5] = {1, 2, 6, 100, 1000000};
for (int i = 0; i < 5; i++) {
long n = ns[i];
long plain = n * k, piped = n + k - 1;
printf("n = %7ld: without pipeline %7ld cycles, with %7ld cycles, speedup %.3f\n", n, plain, piped, (double)plain / (double)piped);
}
return 0;
}n = 1: without pipeline 5 cycles, with 5 cycles, speedup 1.000
n = 2: without pipeline 10 cycles, with 6 cycles, speedup 1.667
n = 6: without pipeline 30 cycles, with 10 cycles, speedup 3.000
n = 100: without pipeline 500 cycles, with 104 cycles, speedup 4.808
n = 1000000: without pipeline 5000000 cycles, with 1000004 cycles, speedup 5.000Reading it. Without a pipeline: cycles. With it: the first instruction takes cycles and each of the other finishes one cycle later, so . A single instruction gains nothing; the speedup climbs towards as grows but never reaches it.
EX 2Reading the space-time diagram
EasyIn the second animation (six instructions), what is every stage doing in cycle 6?
Instruction is in stage in cycle , so in cycle 6: IF has I6 (), ID has I5, EX has I4, MEM has I3, WB has I2. I1 finished at the end of cycle 5. In the same cycle every stage works on a different instruction, which is exactly why the hardware is fully used. Step the animation to cycle 6 and compare with the stage boxes below the diagram.
EX 3When does the last instruction finish?
MediumA -stage pipeline has a clock period and no stalls. The -th instruction enters stage 1 in cycle and leaves stage at the end of cycle , so it completes at time . For , , : , against without pipelining at the same clock.
EX 4Splitting the slowest stage
MediumThe five stages take 12, 8, 10, 14 and 6 ns and each pipeline register adds 1 ns. The clock period is ns. Split the 14 ns stage into two stages of 7 ns: the stages are now 12, 8, 10, 7, 7, 6. The slowest is 12, so the period becomes ns: instructions complete times as fast. The price: one more stage and register, and the latency rises from ns to ns. The next split would have to cut the 12 ns stage, since it is now the limit. Splitting a stage that is not the slowest changes nothing.
EX 5Is the pipelined machine faster for one instruction?
GATE levelUsing the same stage delays, an instruction on the non-pipelined machine needs ns (no registers between the stages). On the pipelined machine the same instruction takes ns. So a single instruction is slower, by 25 ns, but a long run of instructions is faster: one finishes every 15 ns instead of every 50 ns. Pipelining improves throughput, not latency. A question that asks "time for the first instruction" has the answer , not a speedup.
Cheat box
Cheat box
- stages; one instruction enters and one completes per cycle once full.
- Cycles for instructions with no stalls: . Without a pipeline: .
- Instruction is in stage in cycle .
- Clock period . Latency period. Throughput instruction per period.
- Pipelining raises throughput; latency of one instruction does not fall.
- Speedup . Unbalanced stages waste the fast ones. Split the slowest stage to speed the clock up.
- RISC (fixed length, load/store) pipelines easily. Stalls reduce throughput.
Traps and GATE patterns
Connections
Builds on
Unlocks
Across subjects
No cross-subject links yet.
Within this subject
Journeys that pass through here
The stages come from the instruction cycle and the hardware in each is the datapath cut by pipeline registers. A regular instruction set (ISA design) is what makes the stages uniform. The exact speedup arithmetic is on pipeline speedup and CPI, and the causes of stalls are in pipeline hazards.
PYQs
3 previous year questions from your book. I re-solved each one myself (3 by running or simulating, 0 by reasoning only); the book's key is shown next to my answer. All PYQs
Suppose the functions F and G can be computed in 5 and 3 nanoseconds by functional units UF and UG, respectively. Given two instances of UF and two instances of UG, it is required to implement the computation F(G(Xi)) for 1 ≤ i ≤ 10. Ignoring all other delays, the minimum time required to complete this computation is nanoseconds.
Consider the following reservation table for a pipeline having three stages S1, S2 and S3. The minimum average latency (MAL) IS
Consider a 4 stage pipeline processor. The number of
cycles needed by the four instructions I1, I2, I3, I4 in
stages S1, S2, S3, S4 is shown below.
What is the number of cycles needed to execute the
following loop?
For (i = 1 to 2) {I1; I2; I3; I4;}- (a)16
- (b)23
- (c)28
- (d)30 Computer Organization and Architecture
Self-check
Question 1
How many cycles does a 4-stage pipeline need for 20 instructions with no stalls?
Show answerHide
cycles.
Question 2
Stage delays are 5, 7, 6, 9 and 4 ns with a 1 ns register. What is the clock period and the time for the first instruction?
Show answerHide
Period ns. The first instruction needs ns.
Question 3
In a 5-stage pipeline with no stalls, which instruction is in the MEM stage in cycle 9?
Show answerHide
Instruction is in stage 4 (MEM) in cycle , so .
Question 4
Why does splitting a stage that is not the slowest not speed up the pipeline?
Show answerHide
The clock period is set by the slowest stage, which is unchanged. The split only adds a stage and a register.
Revision card
One-screen revision
- stages with registers between; one instruction in each stage per cycle.
- No stalls: cycles; instruction in stage at cycle .
- Period ; latency period.
- Throughput improves, one-instruction latency does not.
- Split the slowest stage to shorten the clock.
References
- ·Hennessy and Patterson, Computer Organization and Design, Chapter 4 The Processor (an overview of pipelining, a pipelined datapath and control)
- ·Hamacher, Vranesic, Zaky, Computer Organization, 5th ed., the Pipelining chapter (basic concepts, pipeline performance)
- ·Stallings, Computer Organization and Architecture, Instruction pipelining chapter (pipelining strategy, pipeline performance)
Verification
The space-time diagrams are produced by a cycle-by-cycle simulation (scripts/gen-coa-pipe-traces.py) and re-checked by tests/coa-pipe-traces.test.ts (one instruction per stage per cycle, stage order, in-order finish, cycles = k + n - 1 for the ideal pipeline). scripts/enum-checks/coa_pipe.py compares the schedule with an independent tick-by-tick model on 4000 random stall patterns and checks the speedup formulas with exact fractions. The cycle-count table is produced by the C program on this page (npm run verify:c). The five stages and their work are the textbook teaching pipeline; real pipelines differ in depth and in what each stage does, and GATE questions may give another stage count. Textbook chapter titles are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand (long C programs were not re-read line by line: they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)