5.3.8 · D1Advanced Microarchitecture

Foundations — 2-bit saturating counter predictors

2,180 words10 min readBack to topic

Before you can read the parent note 2-bit saturating counter predictors, every symbol it throws at you must already be a picture in your head. This page builds each one from nothing, in the order they depend on each other. (We deliberately avoid the words bit and pipeline above — they get defined below, in sections 4 and 2, before we lean on them.)


1. What is a "branch"?

A branch is any instruction that can change which instruction runs next. Normally the CPU runs line 1, then 2, then 3 — straight down. A branch is a fork: "if some condition is true, jump somewhere else; otherwise keep going straight."

Figure — 2-bit saturating counter predictors

The picture: a road that splits. Look at the fork in figure s01 — the green road is "Taken" (we jump up to the loop top), the red road is "Not-Taken" (we fall through and exit). Every branch is one of these forks. This is the thing predictors predict. See Branch Prediction Fundamentals for the wider view.

Why the topic needs it: the whole counter exists to answer one yes/no question — which road? — over and over for the same fork.


2. Why does guessing matter? The pipeline

Modern CPUs don't finish one instruction before starting the next. They work like an assembly line — a pipeline — with several instructions in flight at once, each at a different stage.

The fix: guess the road, and keep the line moving down that road. If the guess was right, we lost nothing. If wrong, we throw away the wrongly-fetched instructions (a misprediction penalty) and restart. See Pipeline Hazards.

Why the topic needs it: this is the motive. Without pipelines, prediction would be pointless.


3. The symbols T, N, and the outcome string

The parent writes things like TTTN and "iterations 0–9 taken". Let's pin these down.

The picture: a row of traffic lights, green = , red = , read like a sentence. A loop that runs 10 times then exits produces — ten greens then one red.

Why the topic needs it: the counter's job is to look at the history so far and predict the next letter.


4. Bits, and reading a 2-bit number

A bit is a single 0 or 1 — one light switch, off or on. Two bits side by side make a 2-bit number.

Why the MSB matters here: the parent's prediction rule is "if MSB = 1, predict Taken". So the left bit alone decides the guess; the right bit only records how sure we are. Hold that thought — figure s02 makes it visual.

Why the topic needs it: the counter is a 2-bit number. You cannot read a single line of the note without reading these four patterns.


5. A counter that can go up and down

A counter here is just that 2-bit number, but with rules for changing it.

Figure — 2-bit saturating counter predictors

The picture: a slider with four notches, shown in figure s02. Taken pushes the slider right; Not-Taken pushes it left; the walls at both ends stop it from falling off. The two right notches are painted "predict Taken", the two left notches "predict Not-Taken".

Why the topic needs it: "saturating counter" is literally the name of the topic. Increment, decrement, the walls, and a defined starting notch are its entire mechanism.


6. Hysteresis — the "grudge" in one word

The picture: think of a heavy door on a spring. One tap doesn't open it; you need to keep pushing. The strong states ( and ) are that heavy door. From (Strongly Taken), a single only drops you to — still on the "Taken" side. You need two 's in a row to actually flip the prediction.

Why the topic needs it: this single word explains why 2 bits beats 1 bit. A 1-bit predictor has zero hysteresis — one surprise flips it, and loops make it flip twice per pass.


7. Program-counter, indexing, and modulo

The parent stores many counters — one per branch — in a table. To find the right one it uses the branch's address.

The picture: a wall of mailboxes. The PC is a long name; we shorten it (drop 2 bits, keep bits) to a box number, and that box holds this branch's 2-bit counter.

Why the topic needs it: without indexing there is only one counter for the whole program, which is useless. The BTB (Branch Target Buffer) does the parallel job of remembering where the taken branch jumps to.


8. Putting the four states together

Now every piece exists, so the parent's state names finally read as plain English:

Figure — 2-bit saturating counter predictors

Figure s03 is the finished state machine: four boxes, each with a -arrow (increment, move right) and an -arrow (decrement, move left), with the walls looping back at the ends. The dashed line down the middle is the prediction boundary — right of it we guess Taken, left we guess Not-Taken. Everything the parent note derives is a walk along these arrows, starting from the cold-start notch .

Why the topic needs it: this diagram is the predictor. The whole note is just tracing paths through it for loops, nested loops, and cold starts.


Prerequisite map

Branch = fork with two outcomes

Pipeline needs a guess to avoid stalls

Outcome string T and N

Bit and the four patterns 00 01 10 11

Counter increment decrement saturate

Hysteresis the grudge

Cold start state weakly taken 10

2-bit saturating counter predictor

PC width n index and mod table lookup


Equipment checklist

Cover the right side and test yourself. If any line surprises you, re-read its section above.

A branch has how many possible outcomes, and what are they?
Two — Taken (jump happens) and Not-Taken (fall through).
Why does a pipelined CPU need to guess branch outcomes?
Because the branch's condition isn't known yet; waiting stalls the assembly line, so it guesses to keep moving and only pays a penalty when wrong.
Read the 2-bit number 10 as an ordinary binary value.
(MSB worth 2 is 1, LSB worth 1 is 0).
Which bit decides the prediction, and what does the other bit record?
The MSB (left bit) decides T vs NT; the LSB records how strong/sure the prediction is.
What does "saturate" mean when incrementing 11?
It stays at 11 — it clips, it does NOT wrap around to 00.
What state does a fresh (never-seen) counter start in on this page, and why?
Weakly Taken (10) — most branches are taken, so guessing T first is right more often, and being only weakly so lets one surprise pull it back.
Define hysteresis in one sentence.
Resistance to change — the counter needs more than one contrary outcome before it flips its prediction.
In PC[n:2], what is and what does the slice keep?
is the PC's bit-width (e.g. 32); the slice keeps bits 2 through — every bit except the lowest two.
What is in binary terms?
Keep only the lowest bits of (drop the rest).
Two different branches landing in the same table entry is called what?
Aliasing (destructive interference) — they share and fight over one counter.
Name the four states from left to right.
Strongly Not-Taken (00), Weakly Not-Taken (01), Weakly Taken (10), Strongly Taken (11).