Lukas' Notes

computer-architecture

Definition

Dynamic Branch Prediction

Dynamic branch prediction is a branch prediction strategy in which the prediction depends on the execution history of the branch.

Unlike static branch prediction, the prediction can change at runtime as the processor observes whether previous instances of the same branch were taken or not.

Schemes

-Bit

Definition

-Bit Branch Predictor

An -bit branch predictor is a dynamic branch prediction scheme that uses an -bit saturating counter to predict the direction of a branch.

The counter implements a finite-state machine with states. A taken outcome increments the counter (up to the maximum), and a not taken outcome decrements it (down to the minimum). The branch is predicted taken when the counter is in the upper half of its range and not taken otherwise.

Because the counter saturates, a single anomalous outcome cannot immediately flip a prediction that has been consistently reinforced. This hysteresis is what distinguishes an -bit predictor () from a simple last-outcome predictor.

Link to original

Global

Definition

Global Branch Predictor

A global branch predictor is a dynamic branch prediction scheme that predicts a branch using the outcomes of all recent branches, not just the current one.

It maintains a global history register — a shift register of the last branch outcomes — and uses this history to index a pattern history table of 2-bit saturating counters. Because the history captures correlations between different branches, a global predictor can exploit patterns like if branch A is taken, branch B is likely not taken.

Link to original

Local

Definition

Local Branch Predictor

A local branch predictor is a dynamic branch prediction scheme that predicts a branch using only the history of that specific branch, indexed by its PC.

In its simplest form, a table of 2-bit saturating counters is indexed by the low bits of the PC. A two-level adaptive variant adds a local history table: the PC selects a per-branch shift register of recent outcomes, which then indexes a pattern history table of counters.

Unlike a global branch predictor, a local predictor cannot exploit correlations between different branches. It can, however, capture per-branch patterns — such as a single branch that alternates taken / not taken — which a global predictor may miss if that pattern is drowned out by other branches in the global history.

Link to original