I am learning about branch prediction in C++
and have a fairly straightforward question.
It seems the __builtin_expect
term tells the compiler which clause to put first in the assembly code.
However if this is added manually by the programmer how is it any different than simply switching the if/else clauses in the C++
code?
The compiler's optimiser is allowed to reorder branches. The __builtin_expect is useful if the compiler gets (or is likely) to get it wrong.