silicon atlasTHE HARDWARE REFERENCE
العربية
Reference/Inside the CPU
CPU & cores

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.
History

Recent branch patterns.

LIVE EXPERIMENT

Follow an instruction

Runs on your device
12345678910
I1
F
D
E
M
W
I2
F
D
E
M
W
I3
F
D
E
M
W
I4
F
D
E
M
W
I5
F
D
E
M
W
I6
F
D
E
M
W
F · FetchD · DecodeE · ExecuteM · MemoryW · Writeback
Instructions6
Total cycles10
Visible cycle1

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.

FOLLOW THE MECHANISM

What happens inside

1

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.

2

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.

PUT IT TO WORK

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.

GO TO THE SOURCE

Read the actual specifications

These references supply the underlying contracts and implementation details. The diagrams here are simplified teaching models.

Intel · Optimization reference manualsIntel

Keep following the connection

Understood the idea? Keep a note of your progress.