Course contentsShow
← Computer Science
Lesson 1180 of 2,87227. Pipelining and PerformanceFree lesson

Branch Target Buffer (BTB)

Cache storing target addresses of branches to enable fetching from predicted path without decode delay.

Branch Target Buffer (BTB)

What you'll learn: How modern processors cache branch target addresses to eliminate decode delays when predicting branches.

The Problem with Branch Prediction

You've learned that processors predict whether branches will be taken or not using two-bit saturating counters. But there's a subtle timing problem: even when you correctly predict a branch will be taken, you still have to wait for the instruction to reach the decode stage to find out where it's jumping to. That delay wastes cycles.

What is a Branch Target Buffer?

A Branch Target Buffer (BTB) is a small, fast cache that stores the target addresses of recently executed branch instructions. It's indexed by the branch instruction's address (its Program Counter value).

Think of it like a phone's speed-dial list. Instead of looking up a contact every time you want to call them (decode stage), you've saved their number for instant access. Similarly, the BTB saves where branches jump to.

How It Works

When the processor fetches an instruction:

  1. It checks the BTB using that instruction's address
  2. BTB hit: The BTB contains an entry → the processor immediately knows this is a branch and where it goes, so it can fetch from the predicted target address right away
  3. BTB miss: No entry found → proceed normally through fetch and decode

The BTB works alongside your branch predictor. The predictor says "yes, take this branch," and the BTB says "here's where to jump—go fetch that instruction now!"

Impact on Performance

Without a BTB, correctly predicting a taken branch still requires waiting through decode. With a BTB, the processor can start fetching from the target immediately, eliminating that delay and keeping the pipeline full.

Key Takeaway: The Branch Target Buffer caches branch destination addresses, allowing the processor to fetch from the predicted path immediately without waiting for decode, significantly reducing control hazard penalties.