If the function is called often enough not to leave the branch predictor, then the predictor will take care of everything for you, as it will learn very quickly, which is a likely branch.
Some compilers allow you to decorate legend with prediction tips. Check your supplier’s documentation and add a hint if you can.
Specific platforms document the default behavior of the predictor (for example, see Intel Optimization Guide for x86), but it is best to leave it to the compiler to implement this using the above tips. In fact, you really have no choice, since you still do not control the generation of compiler code, so the only last step left to you would be to write the code in machine code yourself and implement the default forecasting platform advice.
source share