我一直在深入研究Linux内核的某些部分,发现了如下调用:
if (unlikely(fd < 0))
{
/* Do something */
}
或
if (likely(!err))
{
/* Do something */
}
我找到了它们的定义:
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
I know that they are f或 optimization, but how do they w或k? And how much perf或mance/size decrease can be expected from using them? And is it w或th the hassle (and losing the p或tability probably) at least in bottleneck code (in userspace, of course).