How an instruction pipeline overlaps execution: cycle time, total time, speedup and throughput, structural, data and control hazards, forwarding and stalls, and CPI with branch and load penalties.
Separate instruction and data caches remove a structural hazard; cache misses add stalls.
CPI and execution time
Time instructions CPI cycle time is the base of every speedup question.
Concept notes
1. Pipeline timing and speedup
A -stage pipeline splits each instruction into steps done by separate hardware, so up to instructions are in flight at once. Registers (latches) between stages hold intermediate results.
Cycle time is set by the slowest stage:
For instructions with no stalls, the first takes cycles and each later one finishes one cycle after the previous:
Speedup over the non-pipelined machine (which takes per instruction, with no latches):
With equal stages, no latch delay and , . That is the ideal maximum. Unequal stages, latch delay and stalls all lower it.
Throughput is instructions completed per unit time, about for large . Efficiency .
Pipelining does not make one instruction faster; its latency is , often more than the non-pipelined time. It raises throughput.
Read whether the question's non-pipelined baseline is “sum of stage delays” or “same number of cycles at the same clock”. They give different speedups.
Space-time diagram of a 5-stage pipeline with no hazards
2. Hazards and stalls
A hazard stops the next instruction from entering its stage in the next cycle. The pipeline then stalls (inserts bubbles).
Hazard
Cause
Remedies
Structural
two instructions need the same hardware in one cycle (for example one memory port for fetch and data)
duplicate resources (split I/D caches), stall
Data
an instruction needs a result not yet written
forwarding, stalls, instruction scheduling
Control
the next fetch address depends on a branch not yet resolved
stall, predict, delayed branch
Data dependences between an earlier instruction and a later :
RAW (read after write, true dependence): reads what writes.
WAR (anti-dependence): writes what reads.
WAW (output dependence): both write the same register.
In the classic in-order 5-stage pipeline (IF, ID, EX, MEM, WB) every instruction reads registers in ID and writes only in WB, in program order, so only RAW causes hazards. WAR and WAW become hazards with out-of-order execution or writes in different stages.
With stalls, the effective CPI is
and execution time (plus the fill time, which is negligible for large ).
3. Forwarding and load-use stalls
Take the 5-stage pipeline with the usual convention: the register file is written in the first half of a cycle and read in the second half, so an instruction in ID can read a value written by WB in the same cycle.
Without forwarding, a consumer's ID must be in the producer's WB cycle or later. For back-to-back dependent instructions that is 2 stall cycles; with one independent instruction between them, 1 stall.
Forwarding (bypassing) sends a result from the EX/MEM or MEM/WB latch straight to the ALU input:
ALU result to the very next instruction: 0 stalls.
Load-use: a load's data is available only after MEM, so a dependent instruction right after a load still needs 1 stall.
Producer → next instruction
No forwarding
Full forwarding
ALU op → ALU op
2
0
Load → ALU op
2
1
Compilers reduce load-use stalls by scheduling: moving an independent instruction between the load and its use.
To count cycles, draw the space-time chart row by row. Each instruction starts IF one cycle after the previous one's IF (unless that IF itself is stalled), and an instruction can never overtake the one ahead of it.
4. Control hazards and branch penalty
A branch's outcome and target are known only in some later stage. Instructions fetched after the branch before that point may be wrong. The branch penalty is the number of cycles lost; if the branch resolves in stage , the penalty is typically cycles when the pipeline simply stalls.
With branch frequency and penalty :
Techniques
Stall (flush) on every branch: CPI .
Predict not taken: keep fetching sequentially; pay only for taken branches. With taken fraction , .
Dynamic prediction (branch history, branch target buffer): pay only on mispredictions.
Delayed branch: the instruction(s) right after the branch always execute; the compiler fills these delay slots with useful independent instructions.
Resolve earlier (compute the target and compare in ID): reduces .
Deeper pipelines give a shorter cycle but larger branch and load penalties, so speedup does not keep growing with .
Speedup with stalls, compared with a non-pipelined machine of the same clock that takes cycles per instruction:
Formulas to remember
Cycle time
Pipelined time for n instructions
SpeedupTends to for equal stages, no latches, large
CPI with stalls
Branch penaltyPredict not taken: branch fraction, taken fraction, penalty
Speedup with stallsSame clock; non-pipelined takes cycles
Common mistakes
Using the average stage delay instead of the maximum for the cycle time.
Forgetting the latch delay, or adding latches to the non-pipelined baseline.
Writing cycles instead of for a pipeline without stalls.
Assuming forwarding removes the load-use stall.
Charging the branch penalty on every branch when the processor predicts not taken; only taken branches pay.
Mixing up the two non-pipelined baselines (sum of stage delays vs cycles of the pipelined clock).
Worked examples
Try each step yourself, then reveal the working.
Example 1: Unequal stages with latch delay
numerical
A 5-stage pipeline has stage delays 150, 120, 160, 140 and 130 ps, and each latch adds 10 ps. Find the time to run 100 instructions with no stalls, and the speedup over a non-pipelined unit that takes the sum of the stage delays.
Step 1: Find the cycle time.
Try it on paper first.
Example 2: Counting cycles with and without forwarding
numerical
On the 5-stage pipeline (register write in the first half, read in the second half of a cycle), how many cycles do these four instructions take without forwarding and with full forwarding?
I1: ADD R1, R2, R3
I2: SUB R4, R1, R5
I3: LW R6, 0(R4)
I4: AND R7, R6, R8
Step 1: List the dependences.
Try it on paper first.
Example 3: CPI with predict-not-taken
numerical
In a 5-stage pipeline, 20% of instructions are branches and 60% of branches are taken. The processor predicts not taken; a taken branch costs 3 stall cycles. Ignore other stalls. Find the CPI and the speedup over a non-pipelined machine with the same clock that takes 5 cycles per instruction.
10 questions: up to 4 official PYQs and 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 CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.