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

Aleksey Baulin Aleksey.Baulin at gmail.com
Tue Nov 21 08:05:28 CET 2017


Sorry for late response. Jim had given the correct answer already.
You won't get an extra instruction with compiler optimization turned on.

Aleksey.

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:
> >
> > A warning is issued when using an argument to likely() or unlikely()
> > builtins which is evaluated to a pointer value, as __builtin_expect()
> > expects a 'long int' type for its first argument. With this fix
> > a pointer value is converted to an integer with the value of 0 or 1.
> >
> > Signed-off-by: Aleksey Baulin <Aleksey.Baulin at gmail.com>
> > ---
> > lib/librte_eal/common/include/rte_branch_prediction.h | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/librte_eal/common/include/rte_branch_prediction.h
> b/lib/librte_eal/common/include/rte_branch_prediction.h
> > index a6a56d1..2e7dc69 100644
> > --- a/lib/librte_eal/common/include/rte_branch_prediction.h
> > +++ b/lib/librte_eal/common/include/rte_branch_prediction.h
> > @@ -50,7 +50,7 @@
> >  *
> >  */
> > #ifndef likely
> > -#define likely(x)  __builtin_expect((x),1)
> > +#define likely(x)    __builtin_expect(!!(x), 1)
> > #endif /* likely */
> >
> > /**
> > @@ -64,7 +64,7 @@
> >  *
> >  */
> > #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
>
>
-- 
Aleksey Baulin


More information about the dev mailing list