c++cbranch-prediction

Is it possible to aid branch prediction?


Can you intentionally write code in a specific way so that the branch predictor will choose the option that will be the case most of the times. For example error checks whether a resource was loaded. If this is possible how can you use this to your advantage?


Solution

  • If you are using GCC you can use the macros likely()/unlikely().