From mboxrd@z Thu Jan 1 00:00:00 1970 From: ilikepie420@live.com (bob) Date: Mon, 10 Oct 2011 03:29:03 -0400 Subject: Re Likely and Unlikely Macro In-Reply-To: References: Message-ID: <20111010072903.GA14410@thinkpad> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org It's a shorter way of casting a pointer to an integer with boolean values. On Mon, Oct 10, 2011 at 11:49:54AM +0530, Asutosh Das wrote: > Hi > In lxr, I saw the likely and unlikely macro defined as (compiler.h) > > # define likely(x) (__builtin_constant_p(x) ? !!(x) : > __branch_check__(x, 1)) > 116# endif > 117# ifndef unlikely > 118# define unlikely(x) (__builtin_constant_p(x) ? !!(x) : > __branch_check__(x, 0)) > 119# endif > 120 > ..... some other defines > > #else > 146# define likely(x) __builtin_expect(!!(x), 1) > 147# define unlikely(x) __builtin_expect(!!(x), 0) > 148#endif > > I cannot understand the intention behind !!(x). > Please can you let me know why !!(x) is required here. > > TIA > -- > ~/asd > > _______________________________________________ > Kernelnewbies mailing list > Kernelnewbies at kernelnewbies.org > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies >