A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Hazards in Pipelined Processors

College Depth 103 in the knowledge graph ☐ I know this ☆ Set as goal
3topics build on this
368prerequisites beneath it
See this on the map →
CPU PipeliningPipeline Hazards→→Branch Prediction and Speculative Execution
hazards data control pipeline

Core Idea

Data hazards occur when an instruction depends on results not yet written (read-after-write, write-after-read, write-after-write); control hazards arise from branches. Stalling, forwarding, and speculation resolve these conflicts.

How It's Best Learned

Identify hazards in a simple instruction sequence and trace how forwarding eliminates stalls.

Common Misconceptions

Not all data dependencies cause hazards—only those that cross pipeline stages. Forwarding can eliminate many hazards without stalling.

Explainer

From your study of instruction pipelining, you know that a pipelined processor overlaps the execution of multiple instructions — while one instruction is being executed, the next is being decoded, and the one after that is being fetched. This overlap is what gives pipelines their throughput advantage. But it also creates a fundamental problem: what happens when one instruction depends on the result of another instruction that has not finished yet? These situations are called hazards, and they fall into two main categories.

Data hazards arise from dependencies between instructions' operands. The most common type is read-after-write (RAW): instruction B reads a register that instruction A writes, but A has not yet reached the write-back stage when B needs the value in the decode or execute stage. Consider `ADD R1, R2, R3` followed immediately by `SUB R4, R1, R5`. The SUB needs R1, but ADD will not write its result to the register file for two more cycles. Without intervention, SUB would read the old, stale value of R1. Two other types exist: write-after-read (WAR), where a later instruction writes a register before an earlier instruction reads it, and write-after-write (WAW), where two instructions write the same register and their order must be preserved. WAR and WAW hazards are rare in simple in-order pipelines but become significant in out-of-order execution.

The simplest solution is stalling (inserting pipeline bubbles) — the processor pauses the dependent instruction until its operand is available. But stalling wastes cycles. A more efficient solution is data forwarding (also called bypassing): the result of ADD is available at the output of the ALU before it is written to the register file, so the hardware can route it directly to SUB's ALU input through a forwarding path. This eliminates the stall entirely for many RAW hazards. However, forwarding cannot solve every case — a load instruction, for instance, does not have its result until the end of the memory access stage, so a dependent instruction may still need to stall for one cycle (a load-use hazard).

Control hazards arise from branches. When the processor fetches a conditional branch, it does not know the outcome until the branch condition is evaluated, typically in the execute stage. By that time, the pipeline has already fetched one or more instructions after the branch — but if the branch is taken, those instructions are wrong and must be flushed. This penalty — wasted cycles from fetched-then-discarded instructions — is the control hazard. Simple solutions include always stalling until the branch resolves (costly), assuming the branch is not taken and flushing if wrong, or delayed branching (filling the slot after the branch with a useful instruction). More advanced processors use branch prediction to guess the outcome and speculatively execute the predicted path, recovering if the guess is wrong.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Boolean Algebra and Fundamental Laws → Logic Gates Fundamentals → Implementing Boolean Functions with Gates → Karnaugh Map Simplification → Combinational Circuit Design → Flip-Flops and Latches → Binary Counters: Design and Analysis → Binary Arithmetic → Fixed-Point Number Representation → Two's Complement Representation → Overflow and Underflow Detection → Binary Adders: Half-Adders and Full-Adders → Full Adder and Carry Propagation → Carry Lookahead Adder Design → Half Adder Circuit Design → Multiplication Circuit Design → Sequential Circuit Design → Registers and Register Files → Instruction Set Architecture (ISA) → Assembly Language Basics → CPU Datapath → Instruction Fetch-Decode-Execute Cycle → CPU Control Unit → Microinstruction Format and Control Signals → Hardwired vs. Microprogrammed Control → Processor Control Unit Design → Finite State Machines in Processor Control → Single-Cycle Processor Architecture → Multi-Cycle Processor Design and Execution States → CPU Pipelining → Pipeline Hazards → Hazards in Pipelined Processors

Longest path: 104 steps · 368 total prerequisite topics

Prerequisites (2)

Leads To (1)