Seyed Masoud Hosseini · Overview · Study log · Ideas · Transcript · RSS feed
Digital Design & Computer Architecture · Lecture 20 of 37 · 1:50:47
Lecture 16: Advanced Branch Prediction
Study guide
What this lecture covers
This lecture continues the course's treatment of guessing the next fetch address, focusing specifically on predicting whether a conditional branch is taken. It picks up from an earlier lecture that showed even 90% prediction accuracy badly underutilizes a deep, wide pipeline, and asks how real processors get closer to 100%.
The lecture works through static (compile-time) prediction methods, then dynamic (runtime, hardware-based) predictors of increasing sophistication: last-time prediction, two-bit saturating counters, two-level global and local history prediction, G-share, hybrid predictors as used in the Alpha 21264, and modern perceptron and TAGE predictors used in commercial chips. After watching, you should be able to explain why history-based prediction outperforms static heuristics and describe the mechanism behind each major predictor family.
Key ideas
- Static prediction methods: always-not-taken, always-taken, backward-taken, profile-based, program-analysis-based, and programmer-supplied pragma hints, none of which adapt to a branch's changing behavior at runtime.
- Last-time predictor: predicts a branch will do what it did the previous time; accurate for long loops but always mispredicts the first and last iteration.
- Two-bit saturating counter: adds hysteresis so a single unexpected outcome doesn't immediately flip the prediction, improving accuracy over a single bit.
- Global history correlation: a branch's outcome is often correlated with the recent outcomes of other branches, captured in a global history register that indexes a pattern history table.
- G-share: indexes the pattern history table with the branch address XORed with global history, improving table utilization and accuracy.
- Local history correlation: a branch's outcome can correlate with its own past outcomes beyond just the last execution, useful for identifying loop iterations.
- Hybrid predictors: combine multiple predictor types (for example local and global) with a meta-predictor that chooses which one to trust, as in the Alpha 21264.
- Perceptron and TAGE predictors: perceptron predictors learn per-bit correlation weights with simple machine learning; TAGE combines multiple history lengths in tagged tables, and both are used in modern commercial processors.
Walkthrough
Static branch prediction techniques (10:21)
The lecture reviews compile-time methods that require no history hardware: always-not-taken (30-40% accurate, since loop branches are usually taken), always-taken, and backward-taken (better, since backward branches often close loops). It then covers profile-based prediction, where a compiler encodes a single hint bit per branch based on running the program on sample inputs, and shows with examples that this only reaches 50% accuracy on branches that alternate or split evenly, and can fail badly if the profiling input isn't representative. Program-analysis heuristics (such as predicting error-checking branches as not taken) and programmer-supplied pragmas are also covered as ways to set that hint bit without profiling, each with its own limitations. All static methods share the same weakness: they cannot adapt when a branch's behavior changes while the program runs.
The last-time and two-bit saturating counter predictors (26:30)
The simplest dynamic predictor stores one bit per branch recording its outcome last time and predicts the same outcome again. For a loop of n iterations this gets (n-2)/n accuracy, good for long loops but poor for short or alternating ones, since it always mispredicts on loop entry and exit. The lecture then introduces the two-bit saturating counter (from a 1981 paper), using an air-conditioner analogy for hysteresis: a single unexpected outcome moves the counter to a "weakly" predicted state rather than flipping the prediction outright, so two consecutive opposite outcomes are needed to change the prediction. This recovers much of the accuracy lost on short loops and was adopted quickly by industry, though even 85-90% accuracy is shown to be insufficient for deep, wide modern pipelines.
Two-level global history prediction (40:40)
To go further, the lecture introduces two-level prediction based on a 1991 paper: the idea that a branch's outcome correlates with the recent outcomes of other branches (global correlation) or with its own history beyond the last execution (local correlation). A global history register, a shift register of recent taken/not-taken outcomes, indexes a pattern history table of saturating counters recording what happened the last time that same history pattern was seen. Code examples show how testing related conditions in sequence makes later branches highly predictable once earlier outcomes are known. The Pentium Pro's implementation, a 4-bit global history register with multiple pattern history tables, is presented as the first commercially successful use of this idea.
G-share and local history prediction (1:06:22)
The G-share predictor improves on plain global history by indexing the pattern history table with the branch's program counter XORed with the global history register, adding context about which branch is being predicted and spreading table usage more evenly, at the cost of an extra XOR on the critical path. The lecture then covers local history prediction, where each branch gets its own history register tracking its own past outcomes, useful for distinguishing which iteration of a loop is executing since the ending iteration produces a distinct history pattern.
Hybrid predictors and the Alpha 21264 (1:19:32)
Since different branches predict better with different techniques, no single predictor is best for all branches. The lecture presents hybrid predictors that combine multiple predictor types with a meta-predictor (or choice predictor) that learns which one to trust for a given branch, illustrated with the Alpha 21264's design: a 12-bit global predictor, a 1,024-entry local history table feeding a local predictor, and a choice predictor that selects between them based on global history.
Perceptron and TAGE predictors (1:26:36)
The lecture introduces the perceptron predictor, a single-layer neural network that learns a weight per global history bit representing how strongly that bit correlates with the branch's outcome, computing a prediction as the sign of the dot product between history bits (encoded as +1/-1) and weights. This allows longer history lengths without table sizes exploding, at the cost of needing multiplier hardware, and is used in AMD processors. The lecture closes with TAGE, which combines multiple pattern history tables indexed by different, geometrically increasing history lengths with tag matching, letting the predictor choose the history length that works best for each branch; TAGE and perceptron variants are both used in modern commercial designs, alongside confidence estimation techniques that decide how much to trust a given prediction.
Before you watch
- Review the previous lecture's introduction of the branch target buffer and the basic fetch-stage prediction flow, which this lecture builds on directly.
- Be familiar with saturating counters and cache-style indexed table structures, referenced throughout.
Check your understanding
- Why does profile-based static prediction fail on a branch that alternates taken and not-taken every execution?
- How does the two-bit saturating counter avoid the last-time predictor's worst-case mistakes on short loops?
- What problem does G-share's XOR of program counter and global history solve compared to using either alone?
- Why might a hybrid predictor need a separate meta-predictor, and what tradeoff does that introduce?
- What advantage does a perceptron predictor have over a fixed-length global history table when using very long histories?
From the YouTube description
Digital Design and Computer Architecture, ETH Zürich, Spring 2025 (https://safari.ethz.ch/ddca/spring2025/)
Lecture 16: Advanced Branch Prediction
Lecturer: Prof. Onur Mutlu
Date: 11 April 2025
Lecture 16 Slides (pptx): https://safari.ethz.ch/ddca/spring2025/lib/exe/fetch.php?media=onur-ddca-2025-lecture16-advanced-branch-prediction-beforelecture.pptx
Lecture 16 Slides (pdf): https://safari.ethz.ch/ddca/spring2025/lib/exe/fetch.php?media=onur-ddca-2025-lecture16-advanced-branch-prediction-beforelecture.pdf
Recommended Reading:
====================
Intelligent Architectures for Intelligent Computing Systems
https://people.inf.ethz.ch/omutlu/pub/intelligent-architectures-for-intelligent-computingsystems-invited_paper_DATE21.pdf
A Modern Primer on Processing in Memory
https://people.inf.ethz.ch/omutlu/pub/ModernPrimerOnPIM_springer-emerging-computing-bookchapter21.pdf
RowHammer: A Retrospective
https://people.inf.ethz.ch/omutlu/pub/RowHammer-Retrospective_ieee_tcad19.pdf
RECOMMENDED LECTURE VIDEOS & PLAYLISTS:
========================================
Computer Architecture Fall 2021 Lectures Playlist:
https://www.youtube.com/watch?v=4yfkM_5EFgo&list=PL5Q2soXY2Zi-Mnk1PxjEIG32HAGILkTOF
Computer Architecture Fall 2022 Lectures Playlist:
https://www.youtube.com/watch?v=BIpPTqHK-Lc&list=PL5Q2soXY2Zi-cAls3cyauNzM7-74Eq31O
Digital Design and Computer Architecture Spring 2022 Livestream Lectures Playlist:
https://www.youtube.com/watch?v=cpXdE3HwvK0&list=PL5Q2soXY2Zi97Ya5DEUpMpO2bbAoaG7c6
Digital Design and Computer Architecture Spring 2021 Livestream Lectures Playlist:
https://www.youtube.com/watch?v=LbC0EZY8yw4&list=PL5Q2soXY2Zi_uej3aY39YB5pfW4SJ7LlN
Featured Lectures:
https://www.youtube.com/watch?v=jVYCchBGNVc&list=PL5Q2soXY2Zi8VrmOTz44l2WupethSdh-M&index=1
Interview with Professor Onur Mutlu:
https://www.youtube.com/watch?v=8ffSEKZhmvo&list=PL5Q2soXY2Zi8VrmOTz44l2WupethSdh-M&index=9
The Story of RowHammer Lecture:
https://www.youtube.com/watch?v=sgd7PHQQ1AI&list=PL5Q2soXY2Zi8D_5MGV6EnXEJHnV2YFBJl&index=39
Accelerating Genome Analysis Lecture:
https://www.youtube.com/watch?v=r7sn41lH-4A&list=PL5Q2soXY2Zi8D_5MGV6EnXEJHnV2YFBJl&index=41
Memory-Centric Computing Systems Tutorial at IEDM 2021:
https://www.youtube.com/watch?v=H3sEaINPBOE&list=PL5Q2soXY2Zi8D_5MGV6EnXEJHnV2YFBJl&index=35
Intelligent Architectures for Intelligent Machines Lecture:
https://www.youtube.com/watch?v=GTieZPY4Wmc&list=PL5Q2soXY2Zi8D_5MGV6EnXEJHnV2YFBJl&index=38
Computer Architecture Fall 2020 Lectures Playlist:
https://www.youtube.com/watch?v=c3mPdZA-Fmc&list=PL5Q2soXY2Zi9xidyIgBxUz7xRPS-wisBN
Digital Design and Computer Architecture Spring 2020 Lectures Playlist:
https://www.youtube.com/watch?v=AJBmIaUneB0&list=PL5Q2soXY2Zi_FRrloMa2fUYWPGiZUBQo2
Public Lectures by Onur Mutlu, Playlist:
https://www.youtube.com/watch?v=kgiZlSOcGFM&list=PL5Q2soXY2Zi8D_5MGV6EnXEJHnV2YFBJl
Computer Architecture at Carnegie Mellon Spring 2015 Lectures Playlist:
https://www.youtube.com/watch?v=zLP_X4wyHbY&list=PL5PHm2jkkXmi5CxxI7b3JCL1TWybTDtKq
Rethinking Memory System Design Lecture @stanfordonline :
https://www.youtube.com/watch?v=F7xZLNMIY1E&list=PL5Q2soXY2Zi8D_5MGV6EnXEJHnV2YFBJl&index=4
← Lecture 15c: Load-Store Handling in Out-of-Order Execution · Lecture 17: VLIW and Systolic Array Architectures →
