Skip to content
GATEiit

GATE EC · Digital Circuits

Instruction pipelining

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.

Before you start

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 k 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:

τ=max⁡i(ti)+treg,treg=tclk-q+tsetup

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, τ=3.2 ns; the 2 ns stage idles for 1.2 ns every cycle.
  • Latency gets worse. One instruction now takes kτ=9.6 ns instead of ∑ti=7.5 ns.
  • Throughput gets better. One instruction completes every τ, so the throughput is about 1τ=312.5 million instructions per second.

Balancing. Splitting the slowest stage, or moving logic between stages, reduces τ. If a total logic delay D is cut into k equal parts, τ=Dk+treg. As k grows, τ approaches treg, so the register overhead puts a ceiling on the clock rate.

IFfetchIDdecodeEXALUMEMdata memoryWBwrite backclockpipeline registers (latched on every clock edge)clock period τ = slowest stage delay + register overhead (t_clk-q + t_setup)
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 k-stage pipeline with no stalls, the first instruction completes after k cycles (filling the pipe) and every later one completes one cycle after the previous. For n instructions:

Tpipe=(k+n−1) τ

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.

  1. Non-pipelined takes the sum of the stage delays (no pipeline registers): S=n∑iti(k+n−1) τ
  2. Non-pipelined takes k cycles of the same clock per instruction:

The ideal speedup is k, reached only with equal stages, no register overhead, no stalls and n≫k.

Throughput for large n is 1CPI×τ, where CPI is 1 without stalls. In MIPS, an 800 MHz pipeline at CPI 1.6 gives 8001.6=500 MIPS.

Efficiency =Sk (fraction of stage-slots doing useful work). For n instructions with the second baseline it is nk+n−1.

Deeper is not always better. Take D=8 ns of logic and 0.5 ns register overhead; the non-pipelined design (one register) has period 8.5 ns.

k τ (ns) Clock (MHz) Speedup (large n)
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 k. On top of this, deeper pipelines have larger branch and load penalties, so real designs stop well short of very deep pipelines.

clock cycle12345678I1IFIDEXMEMWBI2IFIDEXMEMWBI3IFIDEXMEMWBI4IFIDEXMEMWBfirst result after k = 5 cyclesthen one per cycle: n − 1 = 3total for n = 4:k + n − 1 = 8
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 stall, branch prediction, delayed branch, earlier resolution

Kinds of data dependence. Take an older instruction A and a younger instruction B.

  • RAW (read after write, the true dependence): B uses as a source a register that A produces.
  • WAR (write after read, anti-dependence): B overwrites a register that A still has to read.
  • WAW (write after write, output dependence): A and B 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

CPI=1+sˉ,sˉ=mean stall cycles per instruction

T=n×CPI×τ(fill time ignored for large n)

S=kCPI(baseline: k cycles per instruction, same clock)

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 =1.3.

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 =k+(n−1)+stalls.

In the figure, LW then a dependent OR then a dependent XOR take 5+2=7 cycles plus 1 load-use stall, so 8 cycles with forwarding. Without forwarding the same code needs 7+2+2=11 cycles.

clock cycle12345678LW R6, 8(R7)IFIDEXMEMWBOR R8, R6, R9IFIDstallEXMEMWBXOR R10, R8, R6IFstallIDEXMEMWBArrows: forwarding of the load data (MEM/WB register) and of the OR result (EX/MEM register).The load-use pair still loses one cycle; the ALU-to-ALU pair loses none.
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 p. If the branch resolves in stage s and the pipeline simply waits, p=s−1: resolving in EX (stage 3) costs 2 cycles, in MEM (stage 4) costs 3.

With branch fraction b:

Policy Stall cycles per instruction
Always stall (flush) on a branch b p
Predict not taken b t p, with t the fraction of branches taken
Dynamic prediction with accuracy a b (1−a) p
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 p to 1.

Example. 20% branches, half of them taken, branch resolved in EX (p=2):

  • always stall: CPI =1+0.2×2=1.4;
  • predict not taken: CPI =1+0.2×0.5×2=1.2.

Against a non-pipelined unit taking 5 cycles per instruction at the same clock, the speedups are 51.4≈3.57 and 51.2≈4.17.

Formulas to remember

Clock period
τ=max⁡iti+tclk-q+tsetup
Time for n instructions, no stalls
T=(k+n−1) τ
Speedup over sum-of-delays baseline
S=n∑iti(k+n−1) τ
Speedup with stalls, same clockBaseline takes k cycles per instruction at the pipelined clock
S=kCPI
CPI with stalls
CPI=1+∑(frequency×stall cycles)
Branch stalls, predict not takenb: share of instructions that are branches; t: share of branches taken; p: cycles lost per taken branch
CPI=1+b t p
Throughput
MIPS=fclk (MHz)CPI
Efficiency
η=Sk

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.

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

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

  1. 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-n speedup (no stalls) for 4 and 8 equal stages, and the limit as the number of stages grows.

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