Branch Prediction — Everything you need to know.

Harshal Parekh
The Startup
Published in
9 min readJun 23, 2019

--

In computer science, predication is an architectural feature that provides an alternative to conditional transfer of control, implemented by machine instructions such as conditional branch, conditional call, conditional return, and branch tables. Predication works by executing instructions from both paths of the branch and only permitting those instructions from the taken path to modify architectural state. [1]

To better understand the concept, let’s take an example:
“Processing a sorted array is faster than processing an unsorted array”

The code above takes ~12 seconds to run. But on commenting line 15, not touching the rest, the same code takes ~33 seconds to run.
(running time may wary on different machines, but the proportion will stay the same).

This is very peculiar yet intriguing, why would processing a unsorted array take almost 3 times as the time taken to process a sorted array?

Let’s travel back to 1700s to consider a real-life scenario, and you are the operator…

--

--