Course: Computer Architectures
Professor: E. Sanchez, Politecnico di Torino, ASE 2026/27. Source: Branch Prediction Techniques, 39 PDF pages, local 09 - branch prediction.pdf. Number 09 follows the filename; no lecture date is inferred. The PDF remains local because redistribution permission is uncertain.
How to study this lecture
The central problem is a pipeline reaching a branch before it knows which instruction comes next. Prediction gives fetch a path to try; recovery discards wrong-path work if the guess fails. See Pipelining and Control Dependencies and Speculation for the execution context.
Follow the ideas in this order, using the full traces in Branch Prediction Fundamentals:
- Direction: taken means jump; not taken means continue sequentially. A loop often takes a backward branch repeatedly, then exits.
- Learning: a one-bit predictor remembers the last result. A two-bit counter adds weak and strong states, so one unusual outcome need not reverse a strong prediction.
- Storage: a BHT holds prediction state; different branch addresses may alias into one entry. A BTB helps supply the destination and may use tags to distinguish entries.
- Context: correlating predictors use history to select a counter. History bits describe past outcomes; counter bits describe prediction states.
- Cost: multiply branch frequency, misprediction rate and penalty to obtain extra cycles per instruction under a fixed-cost model. A BTB exercise can measure cycles per branch instead.
A short worked path
Start a two-bit counter at 11 (strongly taken). When a loop exits with a not-taken outcome, the prediction is wrong and the state moves one step to 10 (weakly taken). The next taken outcome is still predicted taken and returns the counter to 11. If instead the state had started at 10, a not-taken outcome would move it to 01 and change the next prediction. Weak and strong states therefore matter.
A correlating (3,2) predictor remembers three outcomes, giving 2³ = 8 history combinations. Each selected counter has two bits and four states; the branch itself still has only two direction outcomes. The address and history together help choose the table entry. Follow the counter-selection example.
For performance, if 20% of all instructions are branches, 5% of branches are mispredicted, and each mistake costs 4 cycles, the extra CPI is 0.20 × 0.05 × 4 = 0.04. This is averaged over all instructions. The source’s BTB exercise below has a different denominator and additional assumptions.
Recall route
Without notes, explain the path from branch address → direction prediction and target → actual outcome → update or recovery. Then explain why one counter may be shared, what additional information a correlating predictor uses, and why history bits and counter bits do different jobs.
PDF page map
| Pages | Topic |
|---|---|
| 2–10 | Control stalls; static always-taken, direction and profile-based prediction |
| 11–16 | Dynamic branch history table, one-bit predictor and loop example |
| 17–22 | Two-bit saturating counters and performance factors |
| 23–28 | Correlating predictors, global history and (m,n) notation |
| 29–35 | Branch-target buffer and penalty exercise |
| 36–39 | gselect, gshare and performance comparisons |
Source details and qualifications
The SPEC92 and SPEC89 results are historical measurements for the stated workloads and configurations, not present-day performance claims. Profile-based prediction depends on whether training inputs resemble later runs. Page 15’s lack of benefit for the described BHT applies to its particular five-stage timing model; predictor usefulness depends on when fetch, prediction and branch resolution occur.
The one-bit loop example on page 16 refers to steady state and assumes repeated loop invocations and no interfering alias. The first encounter depends on initial state. Page 17’s description of changing prediction after two misses is true from a strong state for consecutive contrary outcomes, not from a weak state. Page 18 uses bimodal for the saturating-counter design; naming conventions vary.
Branch-target buffer exercise (pages 34–35)
The slides compute 0.9 × 0.1 × 2 + 0.1 × 0.6 × 2 = 0.30 cycles per branch. The first term treats 10% as the incorrect-prediction probability conditional on a BTB hit; the second treats 60% as the taken probability conditional on a BTB miss. These conditional assumptions are needed for the multiplication, not established by unconditional rates alone.
Consistency limitation: The slide table predicts taken on every hit. If 90% of all branches hit and 90% of hits are correct, hits alone imply 81% of all branches are taken. That conflicts with the stated overall 60% taken rate. Thus the arithmetic illustrates a weighted-cost calculation but the stated figures cannot all describe one consistent population under that table. The 0.30 result is not a uniquely justified consequence of unconditional rates. The session’s hypothetical 95% calculation likewise follows the separate conditional assumptions, not a consistent population satisfying that overall rate.
Revision questions
- Why can branch prediction improve throughput despite occasional wrong guesses?
- Trace a one-bit and a two-bit predictor through repeated loop exits and entries.
- Why can different branch addresses interfere in an untagged BHT, and how does a tagged BTB distinguish entries?
- Distinguish history bits from counter bits in a (3,2) predictor.
- Compare gselect and gshare and calculate an XOR index.
- Compute added CPI from branch frequency, error rate and penalty; distinguish it from cycles per branch.