Skip to main content...
S1 · Computer Organization & the RISC-V ISA
30 min

Day 46: Control hazards: branch resolution and static prediction

Branches are decided late in the pipeline, but the fetch stage has to guess what comes next. Static prediction is ChipX's simple, honest guess.

Control hazards and branch handling

A control hazard arises because a branch's outcome isn't known until it's resolved (in EX, for ChipX), but the pipeline has already fetched the next instruction(s) speculatively. If the branch is taken and those fetches were wrong, they must be flushed (turned into bubbles). The number of wasted cycles is the branch penalty.

ChipX uses static branch prediction: always predict *not taken*, fetch the fall-through, and flush if the branch turns out taken. Simple and adequate for a first core. Resolving branches *earlier* (moving the comparison into ID) shrinks the penalty. Real high-end cores use dynamic prediction (history tables, gshare) — awareness only for ChipX (Day 52), implementation is v2.0.

Predict-not-taken is honest

For ChipX, always-not-taken costs a small flush penalty only on taken branches and needs zero prediction hardware. Stating that trade clearly — 'I chose static prediction; here's the penalty; here's how dynamic prediction would cut it' — is exactly the kind of engineering judgment interviewers want to hear, and it keeps the frozen scope intact.

Key terms

Control hazard
Uncertainty about the next PC because a branch/jump is not yet resolved.
Flush
Converting wrongly-fetched instructions into bubbles when a branch is mispredicted.
Branch penalty
The cycles lost to flushing on a misprediction; smaller if branches resolve earlier.
Static prediction
A fixed guess (e.g. always not-taken) needing no history hardware.
Dynamic prediction
History-based prediction (2-bit counters, gshare) — high-end, awareness-level for ChipX.

Before moving on, you should be able to

With predict-not-taken, when does ChipX incur a branch penalty?

We use cookies

We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Learn more

    Day 46: Control hazards: branch resolution and static prediction | RBTechIconX