Scrive Borislav Petkov <petkov@uni-muenster.de>: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Thursday 01 July 2004 09:35, Borislav Petkov wrote: > > Hi there people, > > first of all i would like to thank everybody for their help in figuring > out > > the yesterday's asm oneliner. I have another q, though :) > > The kernel extensively uses these macros. > <snip> > > Forget it, i found it in the gcc manual. It uses a builtin function in gcc to > > do better branch prediction, so when we do likely(x), we actually do > __builtin_expect(!!(x),1) which means that it is likely that x is true, i.e., > > x == 1 and the code after it is (more :)) likely to get executed so that the > > branch prediction algorithm in the processor runs faster. > > However, what's with the double negation of x - !!(x)? The signature of __builtin_expect (http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html) is: long __builtin_expect (long exp, long c) Note that the exp parameter should be an integral expression, thus no pointers or floating point types there. The double negation handles the conversion from these types to integral expressions automatically. This way, you can simply write: likely(ptr) instead of likely(ptr != NULL). Marco -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/