3 ms·
Naive question but is the architecture trying so much to optimize branch prediction because software is more and more dominated by conditional logic(if statemen
by whinvik 4y ago
Naive question but is the architecture trying so much to optimize branch prediction because software is more and more dominated by conditional logic(if statements)?
- gary_0 4y agoNo, the amount of conditional logic in code is more or less the same. But memory is as slow as ever relative to the CPU, which means the CPU wants to start reading in the instructions it will need as soon as possible. Without good branch prediction, the CPU would spend too much time waiting for memory to give it more instructions after a branch. Modern CPUs also don't execute one instruction at a time, they have a long and complex pipeline that they want to keep full to maximize the amount of work per clock tick. If a branch prediction fails, a lot of work in the pipeline will need to be discarded. Branch predictors also require balancing a lot of trade-offs in the silicon, so their design has evolved considerably over the years. More in-depth info about branch prediction can be found here: https://danluu.com/branch-prediction/ https://danluu.com/branch-prediction/