Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 21994

How do the likely/unlikely macros in the Linux kernel work and what is their benefit?

$
0
0

I've been digging through some parts of the Linux kernel, and found calls like this:

if (unlikely(fd < 0)){    /* Do something */}

or

if (likely(!err)){    /* Do something */}

I've found the definition of them:

#define likely(x)       __builtin_expect((x),1)#define unlikely(x)     __builtin_expect((x),0)

I know that they are for optimization, but how do they work? And how much performance/size decrease can be expected from using them? And is it worth the hassle (and losing the portability probably) at least in bottleneck code (in userspace, of course).


Viewing all articles
Browse latest Browse all 21994

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>