5.3.8 · D5Advanced Microarchitecture

Question bank — 2-bit saturating counter predictors

1,465 words7 min readBack to topic

Before the traps, a one-line reminder so every symbol below is earned:

Recall The four states and their names

00=Strongly Not-Taken (SNT), 01=Weakly Not-Taken (WNT), 10=Weakly Taken (WT), 11=Strongly Taken (ST). Prediction = the most significant bit (MSB): MSB 1 → predict TAKEN, MSB 0 → predict NOT-TAKEN.


True or false — justify

True or false: A 2-bit counter always predicts more accurately than a 1-bit counter.
False. For an alternating pattern like TNTNTN... both predictors sit at ~50% because neither can track period-2 behaviour; the 2-bit only wins on biased or loopy branches.
True or false: "Saturating" means the counter wraps from 11 back to 00 on an extra increment.
False. Saturating means clipping: 11 + 1 = 11 (stays), never 00. Wrapping would destroy the very hysteresis the design exists to provide.
True or false: The MSB alone determines the prediction; the low bit is irrelevant to the guess.
True for the guess itself (T vs NT), but the low bit is the "strength" that stores hysteresis — it decides whether one wrong outcome flips the prediction or merely weakens it.
True or false: Starting all counters at 00 (SNT) is the safest, most neutral initialization.
False. Real branches are ~60–70% taken, so 00 mispredicts most cold starts; commercial designs init to 10 (Weakly Taken) to warm-start toward the common case.
True or false: A 2-bit predictor eliminates the loop re-entry misprediction that plagues 1-bit predictors.
True. On loop exit the counter only drops from 1110 (still predicts TAKEN), so the next loop entry is predicted correctly — the re-entry miss disappears.
True or false: Moving from 2-bit to 3-bit counters gives roughly the same accuracy jump that 1-bit→2-bit gave.
False. Returns diminish sharply; 2-bit captures ~95% of the benefit. Extra bits add hysteresis that delays adaptation on phase changes and doubles storage per entry.
True or false: In steady state a well-behaved loop of length costs exactly one misprediction per iteration of the outer program.
False. The steady-state cost is one miss per loop instance (the unavoidable exit), not per iteration — the body iterations are all correct once the counter saturates at 11.
True or false: Dropping the low 2 bits of the PC when indexing loses information about which branch you are looking at.
False for aligned instructions. Those bits are always 00 (4-byte alignment), so they carry no discriminating information; keeping them would waste table space.

Spot the error

"From state ST (11), a single not-taken outcome makes the predictor guess not-taken." — what's wrong?
One not-taken moves 1110 (WT), whose MSB is still 1, so it still predicts taken. You need two consecutive not-takens to reach 01 and flip the guess.
"A 4K-entry bimodal table costs 4 KB because each entry is a byte." — what's wrong?
Each entry is 2 bits, not 8. Cost is , four times smaller than the claim.
"Two branches mapping to the same index is harmless as long as the table is big enough." — what's wrong?
Even one collision between an NT-biased and a T-biased branch causes destructive interference: the shared counter thrashes and both mispredict. Bigger tables reduce the probability, not the effect, of a collision.
"The counter increments on a correct prediction and decrements on a wrong one." — what's wrong?
Updates depend on the actual outcome, not on correctness: taken → increment, not-taken → decrement, regardless of what was predicted.
"A 1-bit predictor mispredicts a clean loop once per instance, same worst case as 2-bit." — what's wrong?
The 1-bit predictor mispredicts twice per steady-state instance (exit flips it to NT, re-entry flips it back to T). The 2-bit costs only the single unavoidable exit miss.
"Because loops are usually taken, we should skip the 'weak' states and use just SNT and ST." — what's wrong?
That collapses to a 1-bit predictor. The weak states are the hysteresis buffer; removing them reinstates ping-ponging on every anomaly.
"Indexing with PC mod 2^k needs a hardware divider." — what's wrong?
Modulo a power of two is just a bit-slice (bitwise AND with ) — no divider, one wire cut, essentially free in hardware.

Why questions

Why does a 2-bit counter tolerate one anomaly but not a permanent behaviour change?
One anomaly nudges the counter one step within the same half (e.g. 1110), so the MSB and thus the prediction survive; a genuine, repeated change eventually pushes it across the 10/01 boundary.
Why do the "strongly" states act like momentum reservoirs?
They are the extreme cells 00/11; a confirming outcome that keeps you there costs nothing, and a single contrary outcome only spends one "unit" of that stored momentum without changing the guess.
Why is initializing to Weakly Taken (10) a compromise rather than a clear best choice?
It bets on the common case (branches lean taken) while staying one step from flipping, so a genuinely not-taken branch corrects quickly — balancing warm-start benefit against over-commitment.
Why does the alternating pattern TNTN... defeat a 2-bit counter completely?
The counter tracks a majority direction, but TNTN has no majority within any short window; each outcome cancels the previous update, so it oscillates around the middle and predicts wrong every time.
Why does more hysteresis (more bits) hurt on phase changes?
A phase change means the branch's true behaviour has genuinely reversed; deep counters need many outcomes (e.g. 4 for 3-bit) to cross the middle, so they keep mispredicting throughout the transition — hysteresis becomes stubbornness.
Why do we index the counter table by PC rather than by outcome history?
Bimodal prediction assumes each branch has its own bias captured at its own address; correlating with history is a different, more powerful scheme — see Two-Level Adaptive Predictors and Gshare Predictor.
Why doesn't the bimodal predictor also tell the CPU where the branch goes?
It only predicts direction (T/NT); the target address comes from a separate BTB (Branch Target Buffer). Direction + target together let the pipeline avoid Pipeline Hazards.

Edge cases

What happens if a branch is taken 100 times in a row?
The counter climbs to 11 and stays there (saturation) — no overflow, no wrap, prediction remains strongly taken.
A branch executes exactly once in the whole program. What does the 2-bit predictor cost?
It's pure cold-start: the outcome is a single miss or hit depending only on the initialization versus the actual direction; hysteresis never engages because there is no second occurrence.
Two counters, both currently reading 10 (WT). One just came up from 01, the other just came down from 11. Do they behave identically from now on?
Yes. The counter is memoryless beyond its current 2 bits — history of how you arrived at 10 is gone; both predict taken and both respond identically to future outcomes.
A branch alternates in long runs: TTTT...NNNN...TTTT.... How does the 2-bit fare versus TNTN?
Very well. Long runs let the counter saturate and it only mispredicts at the two boundaries of each run, unlike TNTN where every step is a boundary.
What is the maximum number of consecutive mispredictions a 2-bit counter can suffer before its prediction changes?
Two. From a saturated state (11 or 00) it takes two contrary outcomes to cross the MSB boundary and flip the guess — so at most two straight misses before the prediction adapts.
If a table entry is shared by a never-taken branch and an always-taken branch that alternate calls, what state does the counter settle into?
It never settles — it is driven up by the taken branch and down by the not-taken branch, oscillating around the middle and mispredicting both frequently: classic destructive aliasing.