Master the fundamental concepts of pipelining & out-of-order execution through this focused micro-challenge.
A 2-bit saturating branch predictor keeps four states per branch: strongly not-taken (00), weakly not-taken (01), weakly taken (10), strongly taken (11). Correct predictions nudge one step toward taken/not-taken; mispredictions snap or reverse.
cLoading…
A single bit thrashes on loops: the final backward branch looks not-taken once, causing a mispredict every iteration. Two bits remember "usually taken" after warm-up.
For example, a for (i=0; i<1000; i++) back-edge transitions from SNT to ST over the first handful of iterations, then stays correct.
For this exercise, you will simulate a table of 2-bit counters keyed by PC and report accuracy on traces. This task asks you to beat a static always-taken baseline on mixed branch workloads.
Keep the relevant datasheet, ISA manual, or architecture textbook chapter open while you implement. When your output disagrees with the reference trace on the same program, the bug is usually a mis-decoded opcode, a stale register read, or a flag bit left unchanged after arithmetic.
For this exercise, you will use those habits while implementing the requirement in the starter code. Microarchitectural product names change across CPU generations, but the control ideas (fetch, bypass, cache lines, vector lanes) stay stable enough to debug from first principles.
Implement 2-bit saturating counter branch predictor.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github