[dpdk-dev] [PATCH] eal/common: better likely() and unlikely()

Thomas Monjalon thomas at monjalon.net
Fri Jan 12 16:35:01 CET 2018


21/11/2017 08:05, Aleksey Baulin:
> On Mon, Nov 20, 2017 at 4:36 PM, Wiles, Keith <keith.wiles at intel.com> wrote:
> > > On Nov 19, 2017, at 4:16 PM, Aleksey Baulin <aleksey.baulin at gmail.com>
> > wrote:
> > > -#define unlikely(x)  __builtin_expect((x),0)
> > > +#define unlikely(x)  __builtin_expect(!!(x), 0)
> >
> > I have not looked at the generated code, but does this add some extra
> > instruction now to do the !!(x) ?
> 
> Sorry for late response. Jim had given the correct answer already.
> You won't get an extra instruction with compiler optimization turned on.

So this patch is adding an instruction in not optimized binary.
I don't understand the benefit.
Is it just to avoid to make pointer comparison explicit?
likely(pointer != NULL) looks better than likely(pointer).


More information about the dev mailing list