Skip to content
Sahithyan's S3
1
Sahithyan's S3 — Computer Architecture

Branch Prediction

The process of predicting whether a branch will be taken or not. Reduces control hazards. Better prediction means higher ILP.

Predict next PC. Improves branch prediction by storing target addresses.

A simple branch predictor that uses a small 2-bit state machine per branch.

Each branch has a 2-bit saturating counter with 4 states:

  • Strongly taken
  • Weakly taken
  • Weakly not-taken
  • Strongly not-taken

Prediction is taken if counter is in a “taken” state; otherwise not-taken. Counter moves toward taken/not-taken depending on the actual outcome.

Avoids flipping prediction due to single misprediction. Good for loops.

Uses global branch history to predict the next one. Maintains a history of outcomes of the last mm branches. Has 2m2^m number of nn-bit predictors.

Captures patterns where one branch correlates with previous branches.

Combines correlating predictor with per-branch predictors. Predictor with the best recent accuracy is chosen.

Adapts dynamically to different program behaviors.

Aka. TAGE. Advanced modern predictor using multiple predictor tables with different history lengths. Each table is indexed using a different history length.

Each entry contains:

  • A predicted direction,
  • A tag to verify that the entry actually matches this branch,
  • A usefulness counter.

Long-history tables capture long-range patterns; short-history tables handle simpler cases. If multiple tables match:

  • Longest matching history table = primary prediction.
  • Backup tables used if primary is weak.

High accuracy with controlled storage size using tags + multiple history depths.

When a branch is predicted taken, the branch target is fetched early as if the branch wasn’t there. Handled by using branch target buffer.

One unit does:

  • Prediction
  • Prefetch
  • Fetch-ahead
  • Cache line crossing handling

Predict return addresses of function calls.

Predict values instead of branches. Not widely used. But address alias prediction is used in stores.