How many branches can your CPU predict?
Summary
Daniel Lemire analyzes how many branches modern CPUs can predict by benchmarking AMD Zen 5, Apple M4, and Intel Emerald Rapids with a simple loop. He shows that when using fixed inputs the processor can learn and predict thousands of branches, but using random values leads to mispredictions, highlighting how benchmarking choices influence results. The post includes a code sample and a link to the source code, and notes that AMD performs better on this benchmark.