Branch prediction: Why CPUs can't wait?

namvdo.ai

47 points by signa11 5 days ago


Izmaki - 2 days ago

My favourite explanation of how Branch Prediction works: https://stackoverflow.com/a/11227902/1150676

zzo38computer - a day ago

MMIX instruction set specifies the branch prediction explicitly.

If you also have a "branch always" and "branch never" and the compiler can generate a code to modify that instruction during the initialization of the program, then for some programs where some of the branches are known during initialization, it might modify the code when it is initialized before it is executed.

zenolijo - 2 days ago

I do wonder how branch prediction actually works in the CPU, predicting which branch to take also seems like it should be expensive, but I guess something clever is going on.

I've also found G_LIKELY and G_UNLIKELY in glib to be useful when writing some types of performance-critical code. Would be a fun experiment to compare the assembly when using it and not using it.

whitten - 2 days ago

I know branch prediction is essential if you have instruction pipelining in actual CPU hardware.

It is an interesting thought experiment re instruction pipelining in a virtual machine or interpreter design. What would you change in a design to allow it ? Would an asynchronous architecture be necessary ? How would you merge control flow together efficiently to take advantage of it ?

bob1029 - a day ago

Branch prediction is getting pretty crazy with the latest hardware generation.

https://hackaday.com/2024/07/28/amd-returns-to-1996-with-zen...