codeyaruj/branch-predictor-simulator — explained in plain English
Analysis updated 2026-05-18
Simulate and compare five different branch prediction algorithms on a trace file.
Study how one bit, two bit, and GShare predictors differ in behavior.
Run verbose mode to inspect every prediction and state change step by step.
Write custom trace files to test predictor behavior on specific branch patterns.
| codeyaruj/branch-predictor-simulator | allentdan/shape_based_matching | amu2mod/radeonmon | |
|---|---|---|---|
| Stars | 1 | 1 | 1 |
| Language | C++ | C++ | C++ |
| Last pushed | — | 2019-03-01 | — |
| Maintenance | — | Dormant | — |
| Setup difficulty | easy | moderate | moderate |
| Complexity | 2/5 | 3/5 | 3/5 |
| Audience | researcher | developer | vibe coder |
Figures from each repo's GitHub metadata at analysis time.
Requires a C++17 compiler and Make, only intended for small learning traces since the whole trace loads into memory.
This is a small educational tool the author built to understand how CPUs guess the outcome of branching instructions before they actually run, a technique real processors use to keep their pipelines full and run faster. The simulator implements five different prediction strategies: always predicting taken, always predicting not taken, a simple one bit predictor, a more forgiving two bit predictor, and a more advanced GShare predictor that factors in recent branch history. To build it you need a C++17 compiler and the Make build tool, and building is a single command. You run the resulting program against a trace file, which is a plain text list of program counter addresses paired with whether that branch was actually taken or not. By default it uses the two bit predictor, but you can pick any of the five by name, tune GShare's internal table and history sizes, compare all five predictors against each other on the same trace at once, or turn on verbose mode to see every individual prediction and state change as it happens. The project includes its own test suite you can run with a single command. In the README, the author explains in plain terms what they learned: a one bit predictor flips its guess the moment it sees one different result, while a two bit predictor needs to be wrong more than once in a row before it changes its mind, and GShare improves on both by mixing the branch's address with a short history of recent branch outcomes to pick which prediction table entry to use. The author is upfront about its limits. It only models the direction of a branch, not real CPU timing or pipeline behavior, so it does not aim to be cycle accurate. It loads an entire trace into memory before running, so it is meant for small traces used for learning rather than large real world workloads, and its indexing into the prediction table uses the raw address bits without first removing the bits that come from instruction alignment.
An educational C++ simulator that compares five different CPU branch prediction strategies against text based instruction traces.
Mainly C++. The stack also includes C++, Make.
The README does not state a license for this project.
Setup difficulty is rated easy, with roughly 5min to a first successful run.
Mainly researcher.
This repo across BitVibe Labs
Verify against the repo before relying on details.