Home › Practice › RTL Design › 2-bit branch predictor

2-bit branch predictor

EasyRTLsequentialarchitecture

A processor meets a branch (an if) long before it knows which way it will go. A guess lets it keep working instead of waiting.

Concept first. A branch predictor guesses whether a branch will be taken. The simplest one remembers only the last outcome. A loop branch that is taken nine times and then not taken once makes that predictor wrong twice per loop: at the exit, and again when the loop is entered next time. A 2-bit saturating counter fixes this by needing two wrong guesses in a row before it changes its mind. It has four states, 0 to 3. States 0 and 1 predict "not taken", states 2 and 3 predict "taken". "Saturating" means it stops at 0 and at 3 instead of wrapping around: a counter at 3 that sees another taken branch stays at 3. Trace a loop through the four states on paper to see why one odd outcome does not flip a strong prediction.

What to build.

Solve in your browser →

No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.

More in this track

← How many lights are on?Which way to evict? →