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

Dynamic Branch Prediction Basics

Runtime prediction using branch history to adapt to actual program behavior and improve accuracy.

Dynamic Branch Prediction Basics

What you'll learn: How processors learn from actual branch behavior at runtime to make smarter predictions than static strategies alone.

The Limitation of Static Prediction

Remember static branch prediction? It uses fixed rules—like "always predict backward branches as taken" or "always predict forward branches as not taken." These rules never change during program execution, which means they can't adapt when a program's actual branching pattern differs from the rule.

What is Dynamic Branch Prediction?

Dynamic branch prediction tracks the history of what each branch instruction actually did in the past and uses that history to predict what it will do next time. Instead of a one-size-fits-all rule, the processor maintains a small table that records recent outcomes for branches it has seen before.

Think of it like a weather forecaster who doesn't just say "it usually rains on Tuesdays"—instead, they track what happened the last several Tuesdays and notice patterns like "when it rained the previous two Tuesdays, it rained 80% of the time on the third."

How It Works in Practice

When a branch instruction executes:

  1. The processor looks up that branch's address in a Branch History Table (BHT)
  2. The table shows whether this particular branch was recently taken or not taken
  3. The processor predicts based on that recent history
  4. After the branch resolves, the table is updated with the actual outcome

This adaptive approach performs much better than static prediction because real programs have consistent patterns—loops repeat, conditionals often evaluate the same way consecutively, and dynamic prediction learns these patterns.

Key Takeaway: Dynamic branch prediction tracks runtime history of individual branches to adapt predictions to actual program behavior, achieving significantly higher accuracy than fixed static rules.