Just see this construction in the linux kernel, and I can't get what does it mean.
110 return unlikely(sl->sequence != start);
I know that likely
/unlikely
are made with __builtin_expect
function described here:
http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
You may use __builtin_expect to provide the compiler with branch prediction information.
But what kind of branch prediction hints is possible for unconditional branch??
A look at the Linux kernel code will show many if conditions enclosed in likely and unlikely macros. These macros invoke compiler directives that give the compiler a hint on the code leg that should be optimized for performance.
You can use the __builtin_expect built-in function to indicate that an expression is likely to evaluate to a specified value. The compiler can use this knowledge to direct optimizations. This built-in function is portable with the GNU C/C++ __builtin_expect function.
Just guessing here, but imagine the function is inlined by the compiler, and you have this in the calling code:
if (functionUsingUnlikelyForReturn()) {
// Do something
} else {
// Do something different
}
then it's entirely reasonable for the branch prediction to take note of the hint.
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