IT lexicon › Hardware › Branch prediction

Branch prediction

Hardware På svenska → Updated: 2026-05-24

Modern CPUs guess which branch of an if is taken and start executing it speculatively. On misprediction, the work is thrown out.

Pipelines of 15+ stages need to keep working even when branch instructions are stalled waiting for the condition. A misprediction costs 15–20 cycles. Predictors: 2-bit saturating counter, tournament predictor, neural perceptron (AMD Zen). Branchless code (cmov, bit twiddling) skips branches entirely — faster when the predictor is bad on the data. The Spectre attack (2018) exploited speculative execution to leak data through cache side effects.

← Back to the lexicon