Hint the likely branch in GCC
If you are using GCC and working with code where one branch is very likely than the other, the builtin __builtin_expect
can be very handy.
As is often the case with optimizations, the effects can be counter productive when applied without profiling and confirming the expectation.
A safe version of this is defined as a macro in folly [1]. It is a no-op when the builtin is not supported. This builtin is also often used in the linux kernel source [2]
[1] https://github.com/facebook/folly/blob/master/folly/Likely.h
Written by akhilravidas
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Cplusplus
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#