Lukas' Notes

computer-architecture

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.

Examples

1-Bit Branch Prediction

Consider the same nested loop as in the global predictor example, but now with a 1-bit local predictor: each branch has its own BHT entry, indexed by its PC.

li s0, 1024
xloop: 
	li s1, 4
yloop: 
	mv a0, s0
	mv a1, s1
	jal ra, do_something
	addi s1, s1, -1
	bnez s1, yloop        # L09
	addi s0, s0, -1
	bnez s0, xloop        # L11

The inner loop (L09) has pattern . At start, both BHT entries are PNT.

BranchStartL09L09L09L09L11
BTB entry L09Y
BTB entry L11Y
BHT L09PNT
BHT L11PNT
PredictionNT
Direction-
Correct?-

First L09. BHT PNT predict NT. Taken () — misprediction. BHT PT.

BranchStartL09L09L09L09L11
BTB entry L09YY
BTB entry L11YY
BHT L09PNTPNT
BHT L11PNTPNT
PredictionNTNT
Direction-T
Correct?-N

Second L09. BHT PT predict T. Taken () — correct.

BranchStartL09L09L09L09L11
BTB entry L09YYY
BTB entry L11YYY
BHT L09PNTPNTPT
BHT L11PNTPNTPNT
PredictionNTNTT
Direction-TT
Correct?-NY

Third L09. BHT PT predict T. Taken () — correct.

BranchStartL09L09L09L09L11
BTB entry L09YYYY
BTB entry L11YYYY
BHT L09PNTPNTPTPT
BHT L11PNTPNTPNTPNT
PredictionNTNTTT
Direction-TTT
Correct?-NYY

Fourth L09. BHT PT predict T. Not taken () — misprediction. BHT PNT.

BranchStartL09L09L09L09L11
BTB entry L09YYYYY
BTB entry L11YYYYY
BHT L09PNTPNTPTPTPT
BHT L11PNTPNTPNTPNTPNT
PredictionNTNTTTT
Direction-TTTNT
Correct?-NYYN

L11 (outer loop). BHT PNT predict NT. Taken () — misprediction. BHT PT.

BranchStartL09L09L09L09L11
BTB entry L09YYYYYY
BTB entry L11YYYYYY
BHT L09PNTPNTPTPTPTPNT
BHT L11PNTPNTPNTPNTPNTPNT
PredictionNTNTTTTNT
Direction-TTTNTT
Correct?-NYYNN

Comparison with global predictor mispredictions as the global case. But the local predictor has separate counters: L11's counter stays PNT throughout the inner loop and only trains after L11 executes. In subsequent outer loops, L11 predicts correctly, dropping the misprediction rate below the global case. The local predictor isolates each branch's history — L09's exit behaviour never corrupts L11's counter.

The first outer loop gives the same