5.3.7 · D5Advanced Microarchitecture
Question bank — Branch prediction (static and dynamic)
True or false — justify
A "true/false" answer with no reason is worth nothing here — the judge is the reasoning.
Predict-Not-Taken hardware needs no state, so it can never be wrong.
False. It needs no state, but it is wrong every time a branch is actually taken (e.g. loops), so it's simple, not accurate.
A 2-bit saturating counter is always at least as accurate as a 1-bit predictor.
False. On a short loop (3 iterations) the 2-bit counter can score worse on the first pass because its hysteresis makes it slow to trust "taken"; it wins only over many repetitions.
Static prediction happens before the program runs; dynamic prediction happens while it runs.
True. Static uses a rule fixed at design/compile time; dynamic updates a hardware table from the branch's actual runtime outcomes.
Backwards-Taken-Forward-Not-Taken (BTFNT) works because loops jump backward and usually iterate.
True. A loop's back-edge points to a lower address (target < PC) and is taken almost every iteration, so "backward ⇒ taken" is correct 90%+ of the time.
A correct branch prediction costs zero penalty cycles.
True. On a correct guess the speculatively fetched instructions were the right ones, so the pipeline never stalls or flushes — that's the whole point of predicting.
The 1-bit predictor mispredicts a long loop only once.
False. It mispredicts twice per loop entry-to-exit: once on the first iteration (cold start) and once on the exit — because a single not-taken flips its bit, so re-entry starts wrong again.
Increasing the branch penalty (deeper pipeline) makes prediction accuracy matter more.
True. In , a bigger Penalty multiplies every mistake, so the same mispredict rate costs more cycles.
A correlating predictor can beat a bimodal predictor even when each branch alone looks random.
True. A branch can be individually unpredictable but correlated with recent branches; the global history register captures that pattern a per-address counter cannot see.
If a branch is always taken, a 1-bit predictor gets 100% accuracy after the first time.
True. There's no exit event to flip the bit back, so after the first (cold) miss the bit stays at 1 and stays correct forever.
Spot the error
Each statement below hides one wrong claim. Name it and fix it.
"With prediction, mispredictions are free because the CPU already guessed."
Wrong — a miss is the expensive case: the speculatively fetched instructions are flushed and the pipeline restarts, costing the full ~5–10 cycle penalty. Only correct guesses are free.
"The 2-bit counter predicts Taken when the counter equals 01 (Weakly Not-Taken)."
Wrong — the rule is predict Taken only when the counter is .
01 is still in the Not-Taken half, so it predicts Not-Taken."We index the Branch History Table with the full PC including the bottom 2 bits."
Wrong — the bottom 2 bits are dropped because instructions are 4-byte aligned and would always be
00; we use , wasting no index bits."Static BTFNT learns over time and improves as the program runs."
Wrong — static schemes have no learning; BTFNT's ~84% is a fixed ceiling set by the target-address rule, unchanged run to run.
"A loop that runs 100 times gives the 1-bit predictor ~100% accuracy since it's almost all taken."
Wrong — it oscillates: the exit flips the bit to Not-Taken, so the next entry mispredicts again. It reaches ~98%, and it re-loses the entry cycle every re-entry, unlike a 2-bit counter which holds "Strongly Taken."
"Correlating predictors need only the current branch's address to work."
Wrong — they also need the global history register (recent outcomes of other branches); using only the address makes it a plain bimodal predictor.
"Predict-Taken is best for forward branches like error checks."
Wrong — forward branches (error checks, early returns) are usually not taken, so Predict-Not-Taken fits them; Predict-Taken suits backward loop branches.
Why questions
Why does a 2-bit counter add hysteresis instead of just tracking the last outcome?
So a single anomalous outcome (like a loop's one exit) can't flip the prediction — it takes two consecutive misses to switch, letting the predictor stay right on the dominant behaviour.
Why does the 1-bit predictor score only 50% on a 3-iteration loop?
The loop is too short to amortise its two guaranteed misses (cold start + exit) over few iterations — 2 wrong out of 4 branch events is exactly 50%.
Why do we speculatively fetch at all, instead of just stalling until the branch resolves?
Because the branch outcome isn't known for ~10–20 cycles, and stalling starves the pipeline — an educated guess keeps it full and only occasionally wastes work, which on average is far faster. This underpins Speculative Execution and Instruction-Level Parallelism (ILP).
Why does deeper pipelining (more stages) make good branch prediction more urgent?
More stages means more in-flight instructions to flush on a miss, so the misprediction penalty grows — the cost of a bad guess scales with pipeline depth.
Why can a compiler help static prediction?
The compiler can arrange code and emit branch hints (likely/unlikely) using knowledge of loop structure and profiling, feeding the fixed hardware rule. See Compiler Optimizations.
Why does a correlating predictor help nested if statements?
The inner branch may only execute (or resolve a certain way) because the outer branch went a specific way; the global history encodes "outer was taken," letting the inner prediction condition on it.
Why does branch misprediction indirectly hurt cache performance?
A wrong guess fetches instructions and data from the wrong path, polluting the cache with lines the program never uses and possibly evicting useful ones — connecting to Cache Performance.
Why do Superscalar Processors care even more about prediction than scalar ones?
They issue several instructions per cycle, so a flush wastes multiple instructions' worth of work per cycle across the whole pipeline width — the penalty is multiplied by the issue width.
Edge cases
The boundaries are where predictors reveal their true character.
What happens on the very first time any branch is seen (cold start)?
The BHT entry holds its initial state (often
00 / Not-Taken), so the first prediction is essentially a blind guess and is often wrong regardless of how good the predictor is.What does a 2-bit counter predict at the boundary state 10 (Weakly Taken)?
Taken — the rule is Taken, so
10 predicts Taken but a single not-taken drops it to 01 and flips the prediction.What happens when two different branches map to the same BHT index (aliasing)?
They share one counter and interfere ("destructive aliasing"), so one branch's outcomes corrupt the other's prediction — accuracy drops even though each branch alone is predictable.
What is the accuracy of any predictor on a truly random branch (50/50, no pattern)?
About 50% — no history or rule can beat a fair coin, so this is the theoretical worst case where prediction adds cost (flushes) with no benefit.
How does a 2-bit predictor behave on an alternating T, NT, T, NT, ... branch?
Poorly — it never saturates, hovering around the weak states and mispredicting frequently, because the pattern flips faster than the hysteresis can settle. This is exactly the case correlating predictors are built to catch.
What is the accuracy limit of BTFNT no matter how "nice" the code is?
It's fixed by the target-address rule (~84% typical), so even perfectly loop-heavy code can't push it higher — because it can't learn per-branch behaviour.
At loop exit, why does even a strongly taken 2-bit counter mispredict once?
The exit is genuinely not-taken while the counter says Strongly Taken, so that one branch resolves against the prediction — but it only drops the counter to
10, so re-entry is still correct. That single unavoidable exit miss is the "one per loop" cost.