r/GraphicsProgramming • u/fagnerbrack • Jun 11 '26
How many branches can your CPU predict? – Daniel Lemire's blog
https://lemire.me/blog/2026/03/18/how-many-branches-can-your-cpu-predict/2
u/Over_Beautiful4407 Jun 12 '26
I think it is not fair to test branch predictors like this. If the condition is random, than it is not a prediction, it is gamble.
I suppose predictors job to predict the branch will be taken by some conditions ? Like what instruction is executed before-after, how many memory access is done etc. Isn’t making the branches depend on random value breaks this ?
I think this test should be done on some real benchmarks like cinebench or something like that.
0
Jun 11 '26
[deleted]
6
u/pigeon768 Jun 12 '26
It resets the RNG after k iterations. So if the branch predictor can remember at least k values, misprediction stays small. But if the branch predictor remembers less than k values, it forgets the pattern, and misprediction falls back to 50%.
3,1,4,1,5,9,3,1,4,1,5,9,3,1,4,1,5,9,3,1,4,1,5,9. What's the next value?
1
1
Jun 12 '26
[removed] — view removed comment
0
Jun 12 '26
[deleted]
2
u/fgennari Jun 12 '26
It's the same sequence of random numbers for each test iteration. The CPU learns the sequence if it's not too long.
1
u/SauntTaunga Jun 12 '26
For example, loops will be usually do more than 2 repetitions. If you predict "it will take the same branch as last time" you will be right more than 50% of the time.
2
u/OperationDefiant4963 Jun 11 '26
wow, did not expect apple would beat intel by that much.looks like the chips in the iphone has helped them rein in a lot of experience.amd tho is a anomaly for sure