, 3 min read
Adding a (predictable) branch to existing code can increase branch mispredictions
5 thoughts on “Adding a (predictable) branch to existing code can increase branch mispredictions”
, 3 min read
5 thoughts on “Adding a (predictable) branch to existing code can increase branch mispredictions”
How did you measure the predicts/mispredicts?
Using the processor’s counters.
Wow that’s a low baseline mispredict rate on Intel.
Does that rng function result in an easily predictable even/odd pattern?
What matters is that these are always the same pseudo-random integers from run to run.
Yes this is kind of obvious since adding the 3rd branch adds useless entries in the branch history, reducing its effective length and thus the number of unique patterns it can remember.
Unrolling it 4x or 8x will have the opposite effect since it removes the always taken loop branch which has the same effect.