Instruction pipelining in a processor: stages and pipeline registers, clock period, time for n instructions, speedup, throughput and efficiency, structural, data and control hazards, forwarding, load-use stalls and branch penalties.
Loads, stores, ALU operations and branches behave differently in the pipeline.
Concept notes
1. Stages, pipeline registers and the clock period
A non-pipelined processor finishes one instruction before starting the next. Pipelining splits the work into stages that operate at the same time on different instructions, like an assembly line. The classic five stages are
Stage
Work
IF
fetch the instruction, update PC
ID
decode, read source registers
EX
ALU operation or address calculation
MEM
data memory read (load) or write (store)
WB
write the result to the register file
Pipeline registers (edge-triggered flip-flops) sit between stages and hold each instruction's intermediate values. All of them are clocked together, so every stage must finish within one clock period:
This is the same rule as for any synchronous circuit: the clock period is set by the critical path between registers, and here that is the slowest stage.
Consequences
Unbalanced stages waste time. With three stages of 2, 3 and 2.5 ns and 0.2 ns register overhead, ns; the 2 ns stage idles for 1.2 ns every cycle.
Latency gets worse. One instruction now takes ns instead of ns.
Throughput gets better. One instruction completes every , so the throughput is about million instructions per second.
Balancing. Splitting the slowest stage, or moving logic between stages, reduces . If a total logic delay is cut into equal parts, . As grows, approaches , so the register overhead puts a ceiling on the clock rate.
Five-stage pipeline: pipeline registers between stages are clocked together, so the clock period is the slowest stage plus register overhead
2. Time, speedup, throughput and efficiency
In a -stage pipeline with no stalls, the first instruction completes after cycles (filling the pipe) and every later one completes one cycle after the previous. For instructions:
The space-time chart shows this: rows are instructions, columns are clock cycles, and each row is shifted one cycle right.
Speedup compares with a non-pipelined unit. Read which baseline the question uses.
Non-pipelined takes the sum of the stage delays (no pipeline registers):
Non-pipelined takes cycles of the same clock per instruction:
S=k+n−1nkn→∞k
The ideal speedup is , reached only with equal stages, no register overhead, no stalls and .
Throughput for large is , where CPI is 1 without stalls. In MIPS, an 800 MHz pipeline at CPI 1.6 gives MIPS.
Efficiency (fraction of stage-slots doing useful work). For instructions with the second baseline it is .
Deeper is not always better. Take ns of logic and ns register overhead; the non-pipelined design (one register) has period ns.
(ns)
Clock (MHz)
Speedup (large )
1
8.5
118
1.00
2
4.5
222
1.89
4
2.5
400
3.40
8
1.5
667
5.67
The speedup falls ever further below . On top of this, deeper pipelines have larger branch and load penalties, so real designs stop well short of very deep pipelines.
Space-time chart of a 5-stage pipeline running 4 instructions with no stalls: 5 cycles to fill, then one completion per cycle, 8 cycles in all
3. Hazards and stalls
A hazard is a situation that prevents the next instruction from entering its next stage in the next cycle. The hardware then inserts stalls (bubbles), and the pipeline loses cycles.
Hazard
Cause
Typical remedies
Structural
a single unit is wanted by two instructions in the same cycle, for example one memory serving both fetch and load/store
duplicate the resource (separate instruction and data memories or caches), stall
Data
an instruction needs a value that an earlier instruction has not yet produced or written
forwarding, stalls, reordering instructions
Control
the address of the next instruction depends on a branch that is not yet resolved
Kinds of data dependence. Take an older instruction and a younger instruction .
RAW (read after write, the true dependence): uses as a source a register that produces.
WAR (write after read, anti-dependence): overwrites a register that still has to read.
WAW (write after write, output dependence): and have the same destination register.
In the in-order five-stage pipeline, every instruction reads its sources in ID and writes its result only in WB, in program order. A later instruction can never write before an earlier one reads or writes, so only RAW dependences cause stalls. WAR and WAW become real hazards when instructions can complete out of order or write in different stages.
Effect on performance
Stall contributions from different causes add, each weighted by how often it occurs. For example, 0.1 load-use stalls and 0.2 branch stalls per instruction give CPI .
4. Forwarding and the load-use stall
Take the usual register-file timing: writes happen early in the clock cycle and reads happen late. So when one instruction is in WB and a younger one is in ID during the same cycle, the younger one already sees the new value.
With no forwarding paths, the consumer's ID cycle can be no earlier than the producer's WB cycle.
Dependent instruction immediately after the producer: 2 stall cycles.
One independent instruction in between: 1 stall cycle.
Two or more in between: no stall.
Forwarding (bypassing) adds paths from the EX/MEM and MEM/WB pipeline registers back to the ALU inputs, with multiplexers controlled by a forwarding unit that compares register numbers.
ALU result needed by the next instruction's EX: forwarded from EX/MEM, no stall.
Load-use: a load's data is ready only at the end of MEM, but the next instruction wants it at the start of its EX in the same cycle. That cannot be forwarded backwards in time, so 1 stall remains. A hazard-detection unit in ID inserts it.
Producer, then immediate consumer
No forwarding
With forwarding
ALU op, then ALU op
2
0
Load, then ALU op
2
1
ALU op, then load/store using it as address
2
0
Scheduling. A compiler can hide the load-use stall by placing an unrelated instruction in the gap after the load.
Counting cycles. Draw the chart row by row. An instruction cannot start a stage until the one ahead has left it, and a stalled instruction holds back everything behind it. Total cycles .
In the figure, LW then a dependent OR then a dependent XOR take cycles plus 1 load-use stall, so 8 cycles with forwarding. Without forwarding the same code needs cycles.
With full forwarding, an instruction that uses a load result in the very next slot still waits one cycle; the next ALU-to-ALU dependence is forwarded with no further loss
5. Control hazards and branch penalty
After a branch is fetched, the processor does not know the next PC until the branch condition and target are worked out in some later stage. Instructions fetched in the meantime may be the wrong ones. The cycles lost are the branch penalty . If the branch resolves in stage and the pipeline simply waits, : resolving in EX (stage 3) costs 2 cycles, in MEM (stage 4) costs 3.
With branch fraction :
Policy
Stall cycles per instruction
Always stall (flush) on a branch
Predict not taken
, with the fraction of branches taken
Dynamic prediction with accuracy
Delayed branch, slot filled usefully
the delay slots cost nothing
Predict not taken. Keep fetching in sequence. A not-taken branch costs nothing; a taken branch flushes the wrongly fetched instructions.
Delayed branch. The instruction(s) in the delay slot right after the branch always execute, taken or not. The compiler fills the slot with an independent useful instruction (or a NOP if none exists).
Resolve earlier. Adding a comparator and target adder in ID cuts to 1.
Example. 20% branches, half of them taken, branch resolved in EX ():
always stall: CPI ;
predict not taken: CPI .
Against a non-pipelined unit taking 5 cycles per instruction at the same clock, the speedups are and .
Formulas to remember
Clock period
Time for n instructions, no stalls
Speedup over sum-of-delays baseline
Speedup with stalls, same clockBaseline takes cycles per instruction at the pipelined clock
CPI with stalls
Branch stalls, predict not taken: share of instructions that are branches; : share of branches taken; : cycles lost per taken branch
Throughput
Efficiency
Common mistakes
Using the average stage delay, or leaving out the register overhead, when finding the clock period.
Writing n × k cycles for n instructions; a stall-free pipeline needs k + n − 1.
Assuming forwarding removes the load-use stall; one stall remains after a load in the classic 5-stage pipeline.
Charging the branch penalty on every branch under predict-not-taken; only taken branches pay.
Mixing the two baselines for speedup: sum of stage delays versus k cycles at the pipelined clock.
Believing pipelining shortens the time for one instruction; it raises throughput while latency stays the same or grows.
Worked examples
Try each step yourself, then reveal the working.
Example 1: Clock, time and speedup for unequal stages
numerical
Five pipeline stages have delays of 200, 250, 300, 180 and 220 ps. Each pipeline register adds 20 ps (clock-to-Q plus setup). Find the clock period, the time to run 200 instructions with no stalls, the speedup over a non-pipelined unit taking the sum of stage delays, and the latency of one instruction.
Step 1: Find the clock period from the slowest stage.
Try it on paper first.
Example 2: Stall count for a short code sequence
numerical
Assume the five-stage pipeline whose register file writes early and reads late in a cycle. How many cycles does this code take with no forwarding, and with full forwarding?
I1: LW R2, 0(R1)
I2: ADD R4, R2, R3
I3: OR R7, R8, R9
I4: SUB R5, R4, R6
I5: AND R10, R5, R2
Step 1: List the RAW dependences and how far apart they are.
Try it on paper first.
Example 3: Choosing a branch policy
numerical
Branches make up 15% of the instruction mix of a 5-stage pipeline, 60% of them are taken, and they resolve in MEM. Ignoring other stalls, find the CPI for (a) stalling on every branch, (b) predict not taken, (c) predict not taken with branch resolution moved to ID. Give each speedup over a non-pipelined unit taking 5 cycles per instruction at the same clock.
Step 1: Find the penalty from the resolving stage.
Try it on paper first.
Example 4: How deep should the pipeline be?
numerical
A processor's logic has a total delay of 8 ns, and each register adds 0.5 ns. The non-pipelined version has one register, so its period is 8.5 ns. Find the clock period and the large- speedup (no stalls) for 4 and 8 equal stages, and the limit as the number of stages grows.
Step 1: Write the period for k equal stages.
Try it on paper first.
Previous year questions
No official GATE EC question is tagged with this topic yet. The topic test below uses practice questions.
Topic test
8 questions: original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.
Mark as mastered
Loading your progress…
My revision notes
Notes written by the GATEiit team against the official GATE EC syllabus; being checked by a reviewer. Updated 2026-11-29. Spotted a mistake? Use Report an issue on any question, or contact us.