By the end of this chapter you'll be able to…

  • 1Explain why pipelining improves throughput but not instruction latency
  • 2Compute the clock period from stage delays and register overhead
  • 3Compute total cycles for n instructions on a k-stage pipeline
  • 4Compute speedup and efficiency and state their limits
  • 5Explain the significance of the fill time
  • 6Identify a structural hazard and state the duplication that removes it
  • 7Distinguish RAW, WAR and WAW dependences
  • 8Explain why only RAW matters in an in-order pipeline
  • 9Explain how forwarding resolves a RAW hazard
  • 10Explain why the load-use hazard needs exactly one stall
  • 11Compute the branch penalty from the resolution stage
  • 12Compare stalling, early resolution, delayed branching and prediction
  • 13Describe static prediction strategies and their rationale
  • 14Explain why a one-bit predictor mispredicts twice per loop
  • 15Explain how a two-bit saturating counter halves that
  • 16State the role of a branch target buffer
  • 17Compute the CPI contribution of stalls and mispredictions
  • 18Explain why deeper pipelines demand better prediction
  • 19Distinguish superscalar issue from VLIW
  • 20Explain how register renaming removes WAR and WAW hazards
💡
Why this chapter matters in GATE
Pipelining is the single largest source of performance in a modern processor and also the topic where intuition most reliably misleads. A pipeline does not make any individual instruction faster; an instruction still passes through every stage and usually takes slightly longer than in an unpipelined machine, because each stage boundary costs a register's setup and clock-to-output delay. What a pipeline improves is throughput: by overlapping the stages of different instructions, one completes every cycle instead of every k cycles, and it is that completion rate that decides how long a program takes. The second organising fact is that every hazard is a case where the overlap is not safe — a structural hazard means two instructions want the same hardware in one cycle, a data hazard means a value is not ready yet, and a control hazard means the next instruction is not yet known. So the way to answer a pipelining question is to draw the stage-by-stage diagram and find the cycle where two instructions collide.

Before you start — revise these

🔗
ALU, Data-path & Control Unit
The five pipeline stages are the phases of the instruction cycle developed there, separated by registers instead of executed sequentially.
🔗
Machine Instructions & Addressing Modes
Load-store architecture and fixed-length encoding exist precisely to make the pipeline regular, and the execution-time identity is what pipelining optimises.
🔗
Sequential Circuits
The clock-period constraint and the setup-time overhead of a pipeline register are the timing analysis from that chapter applied here.

Instruction Pipelining & Hazards

Pipelining is the single largest source of performance in a modern processor, and it is also the topic where intuition most reliably misleads.

A pipeline does not make any individual instruction faster. An instruction still passes through every stage and, in a pipelined machine, usually takes slightly longer than it would in an unpipelined one, because each stage must be separated by a register whose setup and clock-to-output delays are pure overhead.

What a pipeline improves is throughput. By overlapping the stages of different instructions, a new instruction completes every cycle instead of every cycles, and it is that completion rate that determines how long a program takes.

The second organising fact is that every hazard is a case where the overlap is not safe. A structural hazard means two instructions want the same hardware in the same cycle. A data hazard means an instruction needs a value that an earlier instruction has not produced yet. A control hazard means the machine does not yet know which instruction comes next.

So the way to answer a pipelining question is to draw the stage-by-stage diagram and find the cycle where two instructions collide. Everything else — speedup formulas, forwarding paths, branch penalties — follows from that picture.

1. The Pipeline Model

Divide instruction execution into stages of roughly equal delay, and place a register between each pair.

A classic five-stage pipeline uses instruction fetch, instruction decode with register read, execute, memory access and writeback.

The clock period is set by the slowest stage plus the pipeline register overhead, not by the average stage. Balancing stages therefore matters more than shortening any one of them.

For instructions on a -stage pipeline with no hazards, the first instruction takes cycles to emerge and each subsequent one takes a single further cycle:

The term is the fill time, the cycles spent before the pipeline reaches steady state, and it is why pipelining pays only when is large compared with .

2. Speedup and Efficiency

Compare against an unpipelined machine that takes cycles per instruction.

As grows, the speedup approaches , so a -stage pipeline can at best make the machine times faster — and only in the limit of infinitely many instructions with no hazards.

Efficiency is the fraction of that ideal achieved:

Throughput is instructions completed per unit time, which in steady state is one per clock cycle.

These formulas assume the unpipelined machine has the same clock period, which is a simplification. In reality, splitting into stages allows a shorter clock period, and that is where most of the real gain comes from. Exam questions usually state which assumption applies, and it must be read rather than assumed.

3. Structural Hazards

A structural hazard occurs when two instructions in different stages need the same hardware resource in the same cycle.

The classic case is a single memory port. In a five-stage pipeline, one instruction is fetching while another is accessing memory, and a unified memory serving both cannot satisfy them simultaneously.

The standard fix is duplication: separate instruction and data caches remove this conflict entirely, which is one of the main reasons the split cache design exists.

A second common case is a register file with too few ports. Decode reads two registers while writeback writes one, so the register file needs two read ports and one write port to avoid stalling.

Where duplication is too expensive — a single divider unit, for instance — the hazard is resolved by stalling, and the cost appears directly in the cycles-per-instruction figure.

4. Data Hazards

A data hazard arises when an instruction depends on a value that an earlier, still-executing instruction has not yet made available.

Three dependence patterns exist, named by the order of the accesses.

TypePatternCalled
RAWRead after writeTrue dependence
WARWrite after readAnti-dependence
WAWWrite after writeOutput dependence

In an in-order pipeline, only RAW causes a real hazard. WAR and WAW require an instruction to complete out of order relative to an earlier one, which an in-order pipeline never does. They become genuine hazards only in out-of-order machines, where register renaming eliminates them.

Consider ADD R1, R2, R3 followed immediately by SUB R4, R1, R5. The subtract reads R1 during its decode stage, while the add writes R1 in its writeback stage, three cycles later. Without intervention the subtract reads a stale value.

Forwarding, also called bypassing, solves most RAW hazards without stalling. The result is available at the output of the execute stage long before it reaches the register file, so a bypass path routes it directly to the next instruction's execute input.

The one case forwarding cannot fix is the load-use hazard. A load produces its value at the end of the memory stage, but the following instruction needs it at the start of its execute stage — which is the same cycle. There is no way to send a value backwards in time, so one stall cycle is unavoidable.

That single cycle is why compilers schedule an independent instruction into the slot after a load whenever one is available.

5. Control Hazards

A control hazard arises because the machine fetches the next instruction before knowing whether a branch will be taken.

The penalty is the number of cycles between fetching an instruction and resolving the branch. If the branch outcome and target are known at the end of the execute stage in a five-stage pipeline, two instructions have already been fetched incorrectly and must be discarded.

Four mitigations appear, and they are cumulative rather than alternative.

Stalling simply freezes fetch until the branch resolves, paying the full penalty on every branch. It is correct and slow.

Early resolution moves the branch comparison and target computation into the decode stage, reducing the penalty from two cycles to one. The cost is extra comparison hardware in decode and a tighter timing path.

Delayed branching redefines the instruction set so that the instructions immediately after a branch always execute, whatever the outcome. The compiler fills those delay slots with useful work if it can, and with no-operations if it cannot.

Branch prediction guesses the outcome and fetches accordingly, paying the penalty only when wrong.

Static prediction uses a fixed rule: always not-taken is simplest, while backward-taken-forward-not-taken exploits the fact that loop branches jump backwards and are usually taken.

Dynamic prediction keeps history in a branch prediction buffer indexed by the branch address. A one-bit predictor remembers the last outcome and mispredicts twice per loop — once on the final iteration and once on the first iteration of the next execution.

A two-bit predictor fixes that by requiring two consecutive mispredictions before changing its guess, so a loop that is taken many times and not taken once mispredicts only on the exit.

A branch target buffer caches the target address alongside the prediction, so a predicted-taken branch can redirect fetch without waiting for the target to be computed.

6. Computing the Cost of Stalls

Every stall adds cycles, and the effect on average cycles per instruction is additive.

For branches specifically, the contribution is the branch frequency times the misprediction rate times the penalty.

A pipeline with a 20 per cent branch frequency, a 10 per cent misprediction rate and a 3-cycle penalty adds to the CPI, raising it from 1.00 to 1.06.

The same structure applies to load-use stalls: frequency of loads, times fraction followed immediately by a dependent instruction, times one cycle.

Deeper pipelines raise the branch penalty, which is why very deep pipelines require correspondingly better prediction. The clock period falls, but the misprediction cost in cycles rises, and beyond some depth the two cancel.

7. Beyond the Basic Pipeline

Two extensions appear in questions.

A superscalar processor issues more than one instruction per cycle, using duplicated functional units. Its ideal CPI falls below 1, and the reciprocal measure — instructions per cycle — becomes the natural one.

An out-of-order processor executes instructions as their operands become available, rather than in program order, and commits results in order so that exceptions remain precise.

Out-of-order execution is what makes WAR and WAW hazards real, and register renaming is what removes them: giving each write a fresh physical register means two writes to the same architectural register never collide.

A VLIW processor takes the opposite approach to superscalar issue. It packs several independent operations into one wide instruction word at compile time, so the hardware performs no dependence checking at all.

The trade is where the scheduling intelligence lives. Superscalar hardware discovers parallelism at run time and adapts to unpredictable latencies such as cache misses; VLIW pushes that work onto the compiler and keeps the hardware simple, at the cost of code that is tied to one pipeline configuration.

8. Worked Examples

Example 1. A 5-stage pipeline with a 2 ns clock executes 100 instructions with no hazards. How long does it take, and what is the speedup over a non-pipelined machine taking 5 cycles per instruction at the same clock?

Total cycles for the pipeline are .

The non-pipelined machine takes cycles, which is 1000 ns.

The speedup is .

Check against the formula: . They agree.

Note that the speedup is below the theoretical maximum of 5 because of the 4-cycle fill time. With 10,000 instructions the speedup would be , essentially the ideal.

Example 2. In a 5-stage pipeline, a LOAD R1, 0(R2) is immediately followed by ADD R3, R1, R4. How many stall cycles are needed with full forwarding, and what if the two instructions were separated by one independent instruction?

The load produces its value at the end of the memory stage, which is cycle 4 of its own execution.

The add needs that value at the start of its execute stage. If the add issues one cycle behind the load, its execute stage is cycle 3 relative to the load's cycle 1 — that is, cycle 3 overall while the value appears at the end of cycle 4.

The value is needed before it exists, and no forwarding path can send a value backwards in time.

One stall cycle is required. After the stall, the add's execute stage aligns with the end of the load's memory stage, and a forwarding path from memory output to execute input supplies the value.

If one independent instruction sits between them, the add's execute stage moves one cycle later and the forwarding path suffices with no stall at all.

This is exactly why compilers schedule an independent instruction into the load delay slot, and why the instruction immediately after a load is the most valuable scheduling opportunity in a simple pipeline.

Example 3. A processor has 20 per cent branches with a 4-cycle misprediction penalty. Compare the CPI under always-not-taken static prediction with a 60 per cent accuracy against a two-bit dynamic predictor with 92 per cent accuracy.

Under static prediction, the misprediction rate is .

Added CPI , so the CPI is .

Under dynamic prediction, the misprediction rate is .

Added CPI , so the CPI is .

The speedup from better prediction is , about 24 per cent.

The arithmetic shows why prediction accuracy matters more as pipelines deepen. With a 10-cycle penalty instead of 4, the static case would give a CPI of 1.80 while the dynamic case gives 1.16, and the gap widens to 55 per cent.

Example 4. Why does a one-bit branch predictor mispredict twice for a loop executed repeatedly, and how does a two-bit predictor fix it?

Consider a loop whose branch is taken nine times and not taken once, repeated many times.

A one-bit predictor stores the last outcome. During the nine taken iterations it predicts taken and is right. On the tenth iteration the branch is not taken, so it mispredicts and flips its stored bit to not-taken.

When the loop is entered again, the first iteration is taken, but the predictor still says not-taken from last time, so it mispredicts a second time and flips back.

Two mispredictions per execution of the loop, one at the exit and one at the re-entry.

A two-bit predictor uses a saturating counter with four states, and it changes its prediction only after two consecutive mispredictions.

At the loop exit it mispredicts once and moves from strongly-taken to weakly-taken, but its prediction is still taken. On re-entry the branch is taken, which is correct, and the counter returns to strongly-taken.

One misprediction per loop execution instead of two, which halves the branch penalty for the single commonest branch pattern in real code.

Example 5. A 4-stage pipeline has stage delays of 6, 8, 5 and 7 ns, with a 1 ns pipeline register overhead. Find the clock period, the throughput, and the effect of splitting the 8 ns stage into two 4 ns stages.

The clock period is set by the slowest stage plus the register overhead.

Throughput in steady state is one instruction per clock, which is ns, or approximately 111 million instructions per second.

Now split the 8 ns stage into two 4 ns stages, giving a 5-stage pipeline with delays 6, 4, 4, 5, 7.

The new slowest stage is the 7 ns one, so the clock period becomes ns.

Throughput rises to ns, about 125 million instructions per second — a 12.5 per cent gain.

Note that the gain is limited by the new bottleneck at 7 ns, not by how finely the 8 ns stage was split. Splitting it further would achieve nothing until the 7 ns stage is also split, which is the general lesson that balancing matters more than depth.

The added stage also raises the branch penalty by one cycle, which the throughput gain must outweigh.

Example 6. Why are WAR and WAW hazards absent from a simple in-order pipeline?

A WAR hazard means a later instruction writes a register before an earlier instruction has read it. A WAW hazard means two instructions write the same register in the wrong order.

Both require an instruction to reach its write stage before an earlier instruction reaches an earlier stage — that is, they require reordering.

In a simple in-order pipeline, instructions enter in program order, pass through stages in lockstep, and reach any given stage in the same order. The earlier instruction always reads before the later one writes, and always writes before the later one writes.

So neither hazard can occur, and only RAW — where a later instruction genuinely needs a value the earlier one has not yet produced — remains.

The picture changes in an out-of-order machine, where instructions execute as their operands become ready. There a later instruction can write a register before an earlier one reads it, and both anti- and output dependences become real.

Register renaming removes them. Giving every write a fresh physical register means two writes never target the same location, and a read always refers to the specific physical register its producer wrote. Only the true RAW dependence survives, which is exactly the dependence that carries actual information.

Summary

A pipeline does not speed up any instruction; it raises throughput by overlapping stages so that one instruction completes per cycle in steady state.

The clock period is the slowest stage plus register overhead, so balancing stages matters more than shortening one.

For instructions on stages, total cycles are , speedup is approaching , and efficiency is .

Structural hazards come from shared hardware and are fixed by duplication — split caches and multi-ported register files — or by stalling when duplication is too expensive.

Only RAW hazards occur in an in-order pipeline. Forwarding removes most of them by routing a result from a stage output directly to the next instruction's input.

The load-use hazard cannot be forwarded away and costs exactly one stall cycle, which is why the slot after a load is the most valuable scheduling opportunity.

Control hazards cost the number of cycles until the branch resolves. Early resolution, delayed branching and prediction reduce that, and a two-bit predictor mispredicts once per loop where a one-bit predictor mispredicts twice.

Stall cost adds to CPI as frequency times rate times penalty, and deeper pipelines raise the penalty, which is why depth and prediction quality must advance together.

Superscalar issue pushes CPI below 1; out-of-order execution makes WAR and WAW real, and register renaming removes them again.

Key formulas & results

Everything to memorise for the exam hall, in one card. Screenshot this for revision.

The organising tool
A PIPELINE MAKES NO SINGLE INSTRUCTION FASTER. IT RAISES THROUGHPUT BY OVERLAPPING, AND EVERY HAZARD IS A CASE WHERE THE OVERLAP IS NOT SAFE.
DRAW THE STAGE-BY-STAGE DIAGRAM AND FIND THE CYCLE WHERE TWO INSTRUCTIONS COLLIDE. EVERYTHING ELSE FOLLOWS FROM THAT PICTURE.
Clock period
T_clock = THE MAXIMUM STAGE DELAY PLUS THE PIPELINE REGISTER OVERHEAD.
IT IS SET BY THE SLOWEST STAGE, NOT THE AVERAGE, SO BALANCING STAGES MATTERS MORE THAN SHORTENING ANY ONE OF THEM.
Total time
T_total = (k + n - 1) TIMES T_clock, FOR n INSTRUCTIONS ON A k-STAGE PIPELINE WITH NO HAZARDS.
THE k MINUS 1 TERM IS THE FILL TIME, THE CYCLES BEFORE STEADY STATE, WHICH IS WHY PIPELINING PAYS ONLY WHEN n IS LARGE COMPARED WITH k.
Speedup
S = n TIMES k, DIVIDED BY (k + n - 1).
AS n GROWS THE SPEEDUP APPROACHES k, SO A k-STAGE PIPELINE CAN AT BEST BE k TIMES FASTER, AND ONLY WITH NO HAZARDS AND INFINITELY MANY INSTRUCTIONS.
Efficiency
E = S DIVIDED BY k, WHICH EQUALS n DIVIDED BY (k + n - 1).
THROUGHPUT IN STEADY STATE IS ONE INSTRUCTION PER CLOCK CYCLE. THESE FORMULAS ASSUME THE UNPIPELINED MACHINE HAS THE SAME CLOCK PERIOD, WHICH IS A SIMPLIFICATION.
Structural hazards
TWO INSTRUCTIONS IN DIFFERENT STAGES NEED THE SAME HARDWARE IN THE SAME CYCLE.
THE CLASSIC CASE IS A UNIFIED MEMORY SERVING BOTH FETCH AND DATA ACCESS, WHICH IS WHY SPLIT INSTRUCTION AND DATA CACHES EXIST.
Register file ports
DECODE READS TWO REGISTERS WHILE WRITEBACK WRITES ONE, SO THE REGISTER FILE NEEDS TWO READ PORTS AND ONE WRITE PORT TO AVOID STALLING.
WHERE DUPLICATION IS TOO EXPENSIVE, SUCH AS A SINGLE DIVIDER, THE HAZARD IS RESOLVED BY STALLING AND THE COST APPEARS IN THE CPI.
The three dependences
RAW IS READ AFTER WRITE, A TRUE DEPENDENCE. WAR IS WRITE AFTER READ, AN ANTI-DEPENDENCE. WAW IS WRITE AFTER WRITE, AN OUTPUT DEPENDENCE.
IN AN IN-ORDER PIPELINE ONLY RAW CAUSES A REAL HAZARD, BECAUSE WAR AND WAW REQUIRE REORDERING THAT AN IN-ORDER PIPELINE NEVER PERFORMS.
Forwarding
A RESULT IS AVAILABLE AT THE EXECUTE STAGE OUTPUT LONG BEFORE IT REACHES THE REGISTER FILE, SO A BYPASS PATH ROUTES IT DIRECTLY TO THE NEXT INSTRUCTION'S EXECUTE INPUT.
THIS RESOLVES MOST RAW HAZARDS WITHOUT ANY STALL, WHICH IS WHY BYPASS NETWORKS ARE A STANDARD FEATURE OF EVERY PIPELINED DESIGN.
The load-use hazard
A LOAD PRODUCES ITS VALUE AT THE END OF THE MEMORY STAGE, BUT THE FOLLOWING INSTRUCTION NEEDS IT AT THE START OF ITS EXECUTE STAGE, WHICH IS THE SAME CYCLE.
NO FORWARDING PATH CAN SEND A VALUE BACKWARDS IN TIME, SO EXACTLY ONE STALL CYCLE IS UNAVOIDABLE. THE SLOT AFTER A LOAD IS THE MOST VALUABLE SCHEDULING OPPORTUNITY.
Branch penalty
THE PENALTY IS THE NUMBER OF CYCLES BETWEEN FETCHING AN INSTRUCTION AND RESOLVING THE BRANCH.
IF A FIVE-STAGE PIPELINE RESOLVES AT THE END OF EXECUTE, TWO WRONGLY FETCHED INSTRUCTIONS MUST BE DISCARDED. EARLY RESOLUTION IN DECODE CUTS THAT TO ONE.
The four mitigations
STALLING PAYS THE FULL PENALTY. EARLY RESOLUTION MOVES THE COMPARISON INTO DECODE. DELAYED BRANCHING ALWAYS EXECUTES THE FOLLOWING SLOTS. PREDICTION GUESSES AND PAYS ONLY WHEN WRONG.
THEY ARE CUMULATIVE RATHER THAN ALTERNATIVE, AND A REAL DESIGN USES SEVERAL AT ONCE.
Static prediction
ALWAYS NOT-TAKEN IS SIMPLEST. BACKWARD-TAKEN-FORWARD-NOT-TAKEN EXPLOITS THE FACT THAT LOOP BRANCHES JUMP BACKWARDS AND ARE USUALLY TAKEN.
STATIC PREDICTION NEEDS NO STORAGE AT ALL, WHICH IS WHY IT SURVIVES AS A FALLBACK WHEN A DYNAMIC PREDICTOR HAS NO HISTORY FOR A BRANCH.
One-bit prediction
A ONE-BIT PREDICTOR REMEMBERS THE LAST OUTCOME AND MISPREDICTS TWICE PER LOOP: ONCE ON THE FINAL ITERATION AND ONCE ON THE FIRST ITERATION OF THE NEXT EXECUTION.
THE SECOND MISPREDICTION IS THE COSTLY ONE, BECAUSE IT AFFECTS EVERY RE-ENTRY OF EVERY LOOP IN THE PROGRAM.
Two-bit prediction
A TWO-BIT SATURATING COUNTER REQUIRES TWO CONSECUTIVE MISPREDICTIONS BEFORE CHANGING ITS GUESS.
A LOOP TAKEN MANY TIMES AND NOT TAKEN ONCE MISPREDICTS ONLY ON THE EXIT, HALVING THE PENALTY FOR THE COMMONEST BRANCH PATTERN IN REAL CODE.
Branch target buffer
A BRANCH TARGET BUFFER CACHES THE TARGET ADDRESS ALONGSIDE THE PREDICTION.
A PREDICTED-TAKEN BRANCH CAN THEN REDIRECT FETCH IMMEDIATELY WITHOUT WAITING FOR THE TARGET TO BE COMPUTED.
Cost of stalls
CPI = 1 PLUS STALLS PER INSTRUCTION. THE BRANCH CONTRIBUTION IS BRANCH FREQUENCY TIMES MISPREDICTION RATE TIMES PENALTY.
A 20 PER CENT BRANCH FREQUENCY, 10 PER CENT MISPREDICTION RATE AND 3-CYCLE PENALTY ADDS 0.06 TO THE CPI, RAISING IT FROM 1.00 TO 1.06.
Depth versus prediction
DEEPER PIPELINES RAISE THE BRANCH PENALTY IN CYCLES EVEN AS THEY SHORTEN THE CLOCK PERIOD.
BEYOND SOME DEPTH THE TWO EFFECTS CANCEL, WHICH IS WHY DEPTH AND PREDICTION QUALITY MUST ADVANCE TOGETHER.
Superscalar and VLIW
A SUPERSCALAR PROCESSOR ISSUES MORE THAN ONE INSTRUCTION PER CYCLE USING DUPLICATED UNITS, PUSHING IDEAL CPI BELOW 1. A VLIW PACKS INDEPENDENT OPERATIONS INTO ONE WIDE WORD AT COMPILE TIME.
SUPERSCALAR HARDWARE DISCOVERS PARALLELISM AT RUN TIME AND ADAPTS TO CACHE MISSES; VLIW PUSHES THAT ONTO THE COMPILER AND TIES CODE TO ONE PIPELINE CONFIGURATION.
Register renaming
GIVING EVERY WRITE A FRESH PHYSICAL REGISTER MEANS TWO WRITES NEVER TARGET THE SAME LOCATION, AND A READ ALWAYS REFERS TO THE PHYSICAL REGISTER ITS PRODUCER WROTE.
THIS REMOVES WAR AND WAW ENTIRELY, LEAVING ONLY THE TRUE RAW DEPENDENCE, WHICH IS THE ONE THAT CARRIES ACTUAL INFORMATION.
⚠️

Traps GATE sets — and how to dodge them

These are the exact option-traps and misreads that cost marks under negative marking.

WATCH OUT
Claiming a pipeline makes each instruction faster
An individual instruction takes at least as long, and usually slightly longer because of pipeline register overhead. What improves is the completion rate, which is one instruction per cycle in steady state rather than one every k cycles.
WATCH OUT
Computing total cycles as n times k
That is the unpipelined figure. A pipelined machine takes k plus n minus 1 cycles, where the k minus 1 fill time is the cost of getting the first instruction through before the steady rate begins.
WATCH OUT
Expecting a k-stage pipeline to give exactly k times speedup
The speedup n k divided by (k + n - 1) only approaches k as n grows. For 100 instructions on 5 stages it is 4.81, and any hazards reduce it further.
WATCH OUT
Setting the clock period from the average stage delay
It is the maximum stage delay plus the register overhead. Splitting a fast stage achieves nothing; only splitting the current bottleneck shortens the period, and then the next-slowest stage becomes the limit.
WATCH OUT
Treating WAR and WAW as hazards in a simple pipeline
Both require an instruction to reach a stage before an earlier one, which an in-order pipeline never permits. They become real only with out-of-order execution, and register renaming then removes them.
WATCH OUT
Assuming forwarding eliminates every data hazard
It cannot fix the load-use case, where the value is produced at the end of the memory stage and needed at the start of the same cycle's execute stage. Exactly one stall is unavoidable there.
WATCH OUT
Counting two stalls for a load-use hazard
One stall suffices. After a single bubble, the dependent instruction's execute stage aligns with the end of the load's memory stage, and a memory-to-execute forwarding path supplies the value.
WATCH OUT
Computing the branch penalty from the pipeline depth
The penalty is the number of cycles until the branch resolves, not the total number of stages. Resolving in decode gives a one-cycle penalty in a five-stage pipeline, while resolving in execute gives two.
WATCH OUT
Assuming a one-bit predictor mispredicts once per loop
It mispredicts twice: once when the loop exits and flips the bit, and once when the loop is re-entered and the stale bit says not-taken. The two-bit counter is what reduces this to one.
WATCH OUT
Adding the misprediction penalty to every branch
The penalty applies only to mispredicted branches. The CPI contribution is branch frequency times misprediction rate times penalty, and omitting the rate overstates the cost by an order of magnitude.
WATCH OUT
Assuming a deeper pipeline is always faster
Depth shortens the clock period but lengthens the branch penalty in cycles and adds register overhead per stage. Beyond some depth the effects cancel, which is why prediction quality must improve alongside depth.
WATCH OUT
Confusing superscalar with a deeper pipeline
Depth divides one instruction into more stages; superscalar width issues several instructions per cycle through duplicated units. Only the latter can push CPI below 1.

Exam-pattern practice

PYQ-style questions with full solutions. Work through them as a readiness check — mark yourself honestly and get your gap report at the end.

Readiness check

Are you exam-ready for Instruction Pipelining & Hazards?

9 problems from this chapter. Try each one, reveal the worked solution, mark yourself honestly — get your gap report at the end.

9 questions~6 min

5-minute revision

The whole chapter, distilled. Read this the night before the exam.

  • A pipeline raises throughput, not per-instruction speed.
  • The clock period is the slowest stage plus register overhead.
  • Balancing stages beats shortening one.
  • Total cycles are k plus n minus 1.
  • The k minus 1 term is fill time.
  • Speedup is nk over (k + n - 1).
  • Speedup approaches k but never reaches it.
  • Efficiency is n over (k + n - 1).
  • Steady-state throughput is one instruction per cycle.
  • Structural hazards come from shared hardware.
  • A unified memory conflicts fetch with data access.
  • Split caches remove that conflict.
  • The register file needs two read ports and one write port.
  • RAW is a true dependence.
  • WAR and WAW need reordering to occur.
  • Only RAW matters in an in-order pipeline.
  • Forwarding routes a result from a stage output directly.
  • Forwarding cannot fix the load-use hazard.
  • The load-use hazard costs exactly one stall.
  • Schedule an independent instruction after a load.
  • The branch penalty is cycles until resolution.
  • Early resolution in decode halves the penalty.
  • Delayed branching always executes the slots after a branch.
  • Static prediction needs no storage.
  • Backward-taken exploits loop structure.
  • A one-bit predictor mispredicts twice per loop.
  • A two-bit predictor mispredicts once per loop.
  • A branch target buffer caches the target address.
  • CPI is 1 plus stalls per instruction.
  • Branch cost is frequency times rate times penalty.
  • Deeper pipelines raise the branch penalty.
  • Superscalar issue pushes CPI below 1.
  • VLIW moves scheduling to the compiler.
  • Out-of-order execution makes WAR and WAW real.
  • Register renaming removes them again.

GATE question blueprint

How this topic is asked, tier by tier — so you can prep to the pattern.

Typical weightage: Computer Organization contributes roughly 7-9 of the 72 core-CS marks; pipelining supplies 2-3 of those across 1-2 questions

Question styleMarks eachTypical countWhat it tests
Pipeline speedup2~1Cycle counts, speedup, efficiency and the effect of register overhead
Clock period1~1Setting the period from the slowest stage and the effect of splitting stages
Data hazards1~1Distinguishing RAW, WAR and WAW and why only RAW matters in order
Load-use hazard2~1Counting stalls with full forwarding and the scheduling remedy
Branch prediction2~1One-bit versus two-bit behaviour on loops and CPI computation
Structural hazards2~1Identifying the shared resource, quantifying the stall cost and the duplication fix
Pipeline design2~1Balancing stages, choosing which to split and weighing depth against branch penalty

Exam-hall strategy

Battle-tested tips from mentors and toppers for this topic under the sectional clock.

  1. Draw the stage-by-stage diagram before computing anything.
  2. Use k plus n minus 1 for pipelined cycle counts, never n times k.
  3. Take the clock period from the slowest stage plus register overhead.
  4. For hazard questions, identify which stage produces the value and which needs it.
  5. Apply the misprediction rate, not the branch frequency alone, to the penalty.
  6. Check whether the question assumes equal clock periods for the two machines.
  7. Speedup and stall counts are commonly set as NAT, which carries no negative marking, so never leave one blank.
  8. For 1-mark and 2-mark MCQs, negative marking is -1/3 and -2/3, so guess only after eliminating an option.
  9. GATE gives a single freely-navigable 180-minute window, so flag a long pipeline diagram and return to it.

Beyond the exam

Where this skill shows up in the job you're competing for — and in life.

Reading a processor's pipeline depth in a datasheet

Depth and branch penalty are quoted together because the second follows from the first, and both determine how much a mispredicted branch costs in practice.

Scheduling instructions in a compiler backend

Moving an independent instruction into the slot after a load is a standard compiler optimisation that exists solely because forwarding cannot cover the load-use hazard.

Writing branch-friendly code

Replacing an unpredictable branch with arithmetic or a conditional move avoids the misprediction penalty, which is why branchless techniques appear in performance-critical loops.

Choosing between split and unified caches

The structural hazard between fetch and data access is the main architectural reason first-level caches are split into instruction and data halves.

Where else this topic is tested

Prepare once, score in every exam that asks it.

GATE ECModerate overlap — pipelining appears in the context of processor architecture with less emphasis on hazard analysis
UGC NET Computer ScienceHigh overlap — pipeline speedup, hazard types and branch prediction are examined as direct recall and short calculation
ISRO / BARC / DRDO computer science papersVery high overlap — speedup formulas, forwarding and stall counting are recurring MCQ and numerical topics

Questions aspirants ask

Pulled from the Q&A community and mentor sessions.

From the completion rate. An individual instruction still passes through every stage, and in a pipelined machine it takes slightly longer than in an unpipelined one, because each stage boundary costs a register's setup and clock-to-output time. What changes is that the stages of different instructions overlap, so once the pipeline is full a new instruction completes every clock cycle instead of every k cycles. For a program of a million instructions, that is the difference between a million cycles and five million on a five-stage machine. The second, larger source of gain is one the simple speedup formula hides. Splitting the work into stages allows a shorter clock period, because the period is set by the slowest stage rather than by the whole instruction. An instruction that took 15 nanoseconds unpipelined can, split into five stages of 3 nanoseconds each plus 1 nanosecond of register overhead, run on a 4-nanosecond clock. The completion rate is then one instruction per 4 nanoseconds rather than one per 15. The standard exam formula assumes both machines share a clock period, which understates the benefit but keeps the arithmetic clean; questions usually state which assumption applies, and it is worth reading carefully because the two give noticeably different numbers.

Because of where in the pipeline each value becomes available relative to where it is needed. An arithmetic instruction computes its result during the execute stage, so the value exists at the end of that stage. The following instruction needs its operands at the start of its own execute stage, which is exactly one cycle later. A bypass path from the execute output to the execute input therefore delivers the value just in time, and no stall is needed. A load is one stage later. Its value comes out of the data memory at the end of the memory stage, which is one cycle after the execute stage. The following instruction still needs its operands at the start of its execute stage, and that stage falls in the same cycle as the load's memory stage. The value is needed at the start of a cycle in which it will not exist until the end. No forwarding path can send a value backwards in time, so exactly one bubble must be inserted. After that bubble the dependent instruction's execute stage aligns with the cycle after the load's memory stage, and a memory-to-execute bypass supplies the value. This is why the instruction slot immediately after a load is the single most valuable scheduling opportunity in a simple pipeline: moving any independent instruction into it converts a guaranteed stall into free work.

Because it stores only the most recent outcome, and a loop has two boundaries where the outcome changes. Take a loop whose closing branch is taken on every iteration except the last. During the taken iterations the predictor stores taken and predicts correctly. On the final iteration the branch is not taken, so the prediction is wrong and the stored bit flips to not-taken. That is the first misprediction, and it is unavoidable for any predictor without knowledge of the trip count. The second is the avoidable one. The next time the loop is entered, its first iteration is taken, but the predictor still holds not-taken from the previous exit, so it mispredicts again and flips back. Every entry to every loop in the program therefore costs an extra misprediction. A two-bit saturating counter fixes this by adding hysteresis. It has four states and changes its prediction only after two consecutive wrong guesses. At the loop exit it mispredicts once and moves from strongly-taken to weakly-taken, but weakly-taken still predicts taken, so the re-entry is predicted correctly and the counter saturates again. One misprediction per loop execution instead of two. Since loops dominate the branches in real programs, this single change roughly halves the branch penalty, which is why two-bit schemes became the baseline against which more elaborate predictors are measured.

Deep enough that the clock period is dominated by real work rather than register overhead, and shallow enough that the branch penalty does not overwhelm the gain. Two forces oppose each other. Deeper stages mean a shorter clock period, since the period is the slowest stage plus a fixed register overhead, and a shorter period means faster completion in the absence of hazards. But every stage boundary adds that fixed overhead, so as stages shrink the overhead becomes a larger fraction of the period, and the return on further splitting diminishes. Splitting a 3-nanosecond stage into two 1.5-nanosecond halves takes the period from 4 to 2.5 nanoseconds rather than from 3 to 1.5. The second force is the branch penalty, which is measured in cycles and grows with depth. A branch resolved in the fourth of five stages costs three cycles; the same branch in a twenty-stage pipeline may cost fifteen. Since the misprediction cost in time is penalty times period times frequency times misprediction rate, and the period is falling while the penalty rises, the two partially cancel, and beyond some depth the net effect turns negative. The practical resolution is that depth and prediction accuracy must advance together: very deep pipelines are viable only with predictors accurate enough that the penalty is rarely paid. There is also a third limit worth knowing: deeper pipelines need more forwarding paths and more complex hazard detection, and that logic itself eventually lengthens a stage.

Because they are properties of the program, not of the pipeline, and they become real as soon as a machine reorders execution. A WAR hazard exists whenever a later instruction writes a register that an earlier instruction reads; a WAW hazard exists whenever two instructions write the same register. Both are present in the instruction stream regardless of the hardware. What determines whether they cause a problem is whether the hardware can execute the later instruction's write before the earlier instruction's read or write. A simple in-order pipeline cannot: instructions enter in program order and traverse the stages in lockstep, so the earlier instruction always reaches any given stage first. Only RAW remains, because that is the one case where the ordering is correct and the value is still not ready. An out-of-order machine issues instructions as their operands become available, so a later instruction whose inputs are ready can execute and write while an earlier one waits on a cache miss. Now both anti- and output dependences can be violated. The fix is register renaming, which observes that these are not real dependences at all but artefacts of reusing a limited set of architectural register names. Giving each write a fresh physical register means no two writes ever target the same location and every read refers unambiguously to the physical register its producer wrote. Only RAW survives, which is exactly the dependence that carries genuine information from one instruction to another.
Header Logo