CPU - Branch

> Computer System > Computer - Central processing unit (CPU)

1 - 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).
Advertising

3 - 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

4 - Documentation / Reference

computer/cpu/branch.txt · Last modified: 2019/01/11 17:30 by gerardnico