Branch prediction & speculation
Guess where execution goes next so the front end keeps moving.
An unpredictable branch can waste work that was already halfway through the core.
Recent branch patterns.
Follow an instruction
Overlap improves throughput. Dependencies introduce bubbles unless the implementation can forward or do independent work.
What this model includes
Five-stage, single-issue teaching model. Dependent mode inserts two idle issue cycles per instruction; real forwarding and hazards vary.
What happens inside
Predict direction and target
A predictor uses instruction addresses and execution history to guess whether a conditional branch is taken. Target predictors supply destination addresses; return predictors track call/return patterns. These structures learn patterns, but capacity, aliasing, and changing data can defeat them.
Recover from a wrong guess
The core executes speculatively before the condition resolves. If wrong, it squashes younger work and restarts at the correct address. Architecturally discarded work may still affect microarchitectural timing. This distinction underlies speculative side channels; mitigation is a platform and software concern.
What this means for your code
Low-level engineer
Measure branch misses along with cycles. Predication can replace a branch, but may execute both sides or extend a dependency chain.
Software developer
Random data-dependent branches can be expensive. Sorting or partitioning work can improve predictability when its own cost is justified.
Read the actual specifications
These references supply the underlying contracts and implementation details. The diagrams here are simplified teaching models.