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?
If you are using GCC you can use the macros `likely()/unlikely()':
likely()/unlikely() macros in the Linux kernel - how do they work? What's their benefit?
Theoretically, yes. Effectively speaking NO. You won't really get any benefit, try it out yourself.
With the way modern hardware works your CPU will still grind out all of the branches no matter what you do. But it doesn't really matter because they will do it concurrently.
To attempt to do it yourself you would need to use assembly language. Compiler hints like shown above will not do much.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With