Conditional branch: BEQ/BNE
Direct jump: accuracy high
Indirect jump: accuracy low (must access register file)
After ID stage
How do we predict a branch?
Track history of previous branch targets
If a branch was visited before, reuse its previous target
Chance will execute the same path
Branch Target Buffer (BTB)
If found a match, use BTB entry
Else, use PC + 4
BTB accessed at every IF stage
Could update every ID stage
Or, update in EX stage for timing
Use lower bits of PC to lookup with multiplexer.
PC address is 4 byte aligned, so lower two are zero
index_bits = log2(btb_size)
pc_index = (pc >> 2) & (index_bits << 1) - 1
pc_tag = (pc >> 2) >> index_bits