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

Jim Thompson jim at netgate.com
Mon Nov 20 18:21:47 CET 2017


> On Nov 20, 2017, at 7:36 AM, Wiles, Keith <keith.wiles at intel.com> wrote:
> 
>> On Nov 19, 2017, at 4:16 PM, Aleksey Baulin <aleksey.baulin at gmail.com> wrote:
>> 
>> #ifndef unlikely
>> -#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) ?
> 
>> #endif /* unlikely */
>> 
>> #endif /* _RTE_BRANCH_PREDICTION_H_ */
>> -- 
>> 2.7.4
>> 
> 
> Regards,
> Keith
> 

With no ‘-O’, you get an extra cmpl instruction with the double negated unlikely() .vs the one without the ‘!!’.
The same assembly is generated with ‘-O’ as a compiler switch.

Tested on:
[jim at blackbox-1 ~]$ uname -a
Linux blackbox-1.netgate.com 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[jim at blackbox-1 ~]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Jim


More information about the dev mailing list