▲ | moregrist 2 days ago | ||||||||||||||||
There’s ample information out there. There are quite a few text books, blogs, and YouTube videos covering computer architecture, including branch prediction. For example: - Dan Luu has a nice write-up: https://danluu.com/branch-prediction/ - Wikipedia’s page is decent: https://en.m.wikipedia.org/wiki/Branch_predictor > I've also found G_LIKELY and G_UNLIKELY in glib to be useful when writing some types of performance-critical code. A lot of the time this is a hint to the compiler on what the expected paths are so it can keep those paths linear. IIRC, this mainly helps instruction cache locality. | |||||||||||||||||
▲ | _chris_ 2 days ago | parent [-] | ||||||||||||||||
> A lot of the time this is a hint to the compiler on what the expected paths are so it can keep those paths linear. IIRC, this mainly helps instruction cache locality. The real value is that the easiest branch to predict is a never-taken branch. So if the compiler can turn a branch into a never-taken branch with the common path being straight line code, then you win big. And it takes no space or effort to predict never taken branches. | |||||||||||||||||
|