From: Aleksey Baulin <Aleksey.Baulin@gmail.com>
To: "Wiles, Keith" <keith.wiles@intel.com>
Cc: Thomas Monjalon <thomas@monjalon.net>, "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH] eal/common: better likely() and unlikely()
Date: Tue, 21 Nov 2017 10:05:28 +0300 [thread overview]
Message-ID: <CAJ+OjZkv24B=aVthrj8EepX-jpXtx+Pc1KBuyuTpJ3stMUd3jg@mail.gmail.com> (raw)
In-Reply-To: <D3302FD6-A529-497E-A470-5EBC1729EDF5@intel.com>
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@intel.com> wrote:
>
>
> > On Nov 19, 2017, at 4:16 PM, Aleksey Baulin <aleksey.baulin@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@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
next prev parent reply other threads:[~2017-11-21 7:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-19 22:16 Aleksey Baulin
2017-11-20 13:36 ` Wiles, Keith
2017-11-20 17:21 ` Jim Thompson
2017-11-21 7:05 ` Aleksey Baulin [this message]
2018-01-12 15:35 ` Thomas Monjalon
2018-01-13 22:05 ` Aleksey Baulin
2018-01-13 22:24 ` Thomas Monjalon
2018-01-13 22:45 ` Aleksey Baulin
2018-01-14 17:17 ` Stephen Hemminger
2018-01-20 16:28 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJ+OjZkv24B=aVthrj8EepX-jpXtx+Pc1KBuyuTpJ3stMUd3jg@mail.gmail.com' \
--to=aleksey.baulin@gmail.com \
--cc=dev@dpdk.org \
--cc=keith.wiles@intel.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).