About
- forward branches (used to implement conditional operations like if statements)
- backward branches (used to implement loops).
Branches may be:
- unconditional (always taken),
- or conditional (taken or not, depending on a computed value).
To avoid a stall, the processor must guess which instruction to fetch next:
- the next one in memory order (corresponding to an untaken branch),
- or the one at the branch target (corresponding to a taken branch).
Articles Related
Prediction
A branch predictor helps the processor make an intelligent guess about whether a branch will be taken or not. It does this by gathering statistics about how often particular branches have been taken in the past.
The performance of an if-statement depends on whether its condition has a predictable pattern. branch prediction fail