2.5Control hazard
The idea
A control hazard arises because a branch changes which instruction comes next, but the pipeline has already fetched the ones after it.
Think of it like this: Driving past a junction before you find out you should have turned.
Why it exists
Branches are about 15–20% of instructions, so their penalty adds up quickly.
How it works
- A branch is only resolved late (EX or MEM).
- Meanwhile the next instructions are fetched on a guess (usually "not taken").
- If the guess was wrong, those instructions are flushed: the lost cycles are the branch penalty.
- Reduce it with branch prediction, early resolution or delayed branches.
Worked example: Branch resolved after EX (cycle 3)
Two wrong-path instructions were fetched, so the penalty is 2 cycles. If the prediction was right, penalty is 0.
Now play with it
- →Switch between "Branch taken" and "Prediction correct" and compare total cycles.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | |
|---|---|---|---|---|---|---|---|---|
| BEQ | IF | ID | EX | MEM | WB | |||
| I2 (wrong path) | IF | ID | flush | |||||
| I3 (wrong path) | IF | flush | ||||||
| Target | IF | ID | EX | MEM | WB |
Outcome known after EX (cycle 3). Two wrongly fetched instructions are flushed: 2 cycle branch penalty.
Check yourself
Which technique directly reduces the cost of control hazards?
Exam notes (the dense version)
Branch outcome known late → wrong-path fetches. Fix: stall, predict (static/dynamic), delayed branch, branch target buffer.
Previous year questions: Instruction Pipelining & Hazards (15)
PYQs are grouped by topic, so this is the full set for Instruction Pipelining & Hazards; try the ones that match this subtopic. Open all 15 on the topic page.