LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "David Laight" <David.Laight@ACULAB.COM>
To: "David Daney" <ddaney@caviumnetworks.com>,
"Coly Li" <bosong.ly@taobao.com>
Cc: "Wang Cong" <xiyou.wangcong@gmail.com>,
"Jeremy Fitzhardinge" <jeremy@goop.org>,
<linuxppc-dev@lists.ozlabs.org>, <linux-kernel@vger.kernel.org>,
"Yong Zhang" <yong.zhang0@gmail.com>
Subject: RE: [PATCH 2/7] PowerPC: add unlikely() to BUG_ON()
Date: Fri, 28 Jan 2011 09:05:59 -0000 [thread overview]
Message-ID: <AE90C24D6B3A694183C094C60CF0A2F6D8AC2D@saturn3.aculab.com> (raw)
In-Reply-To: <4D41B213.4070606@caviumnetworks.com>
> > +#define __BUG_ON(x) do { \
> > if (__builtin_constant_p(x)) { \
> > if (x) \
> > BUG(); \
> > @@ -85,6 +86,8 @@
> > } \
> > } while (0)
> >
> > +#define BUG_ON(x) __BUG_ON(unlikely(x))
> > +
>From my experiments, adding an 'unlikely' at that point isn't
enough for non-trivial conditions - so its presence will
give a false sense the the optimisation is present!
In particular 'if (unlikely(x && y))' needs to be
'if (unlikely(x) && unlikely(y))' in order to avoid
mispredicted branches when 'x' is false.
Also, as (I think) in some of the generated code quoted,
use of __builtin_expect() with a boolean expression can
force some versions of gcc to generate the integer
value of the expression - rather than just selecting the
branch instructions that statically predict the
normal code path.
Sometimes I've also also had to add an asm() statement
that generates no code in order to actually force a
forwards branch (so it has something to place at the
target).
(I've been counting clocks ....)
David
next prev parent reply other threads:[~2011-01-28 9:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-27 12:12 [PATCH 0/6] use BUG_ON correctly, v2 Coly Li
2011-01-27 12:12 ` [PATCH 1/7] MIPS: add unlikely() to BUG_ON() Coly Li
2011-01-27 17:50 ` David Daney
2011-01-28 10:41 ` Coly Li
2011-01-27 12:12 ` [PATCH 2/7] PowerPC: " Coly Li
2011-01-27 17:57 ` David Daney
2011-01-27 20:04 ` Scott Wood
2011-01-27 20:32 ` David Daney
2011-01-28 9:05 ` David Laight [this message]
[not found] ` <AE90C24D6B3A694183C094C60CF0A2F6D8AC2D__37237.0892241181$1296205746$gmane$org@saturn3.aculab.com>
2011-01-28 10:14 ` Andreas Schwab
2011-01-28 11:02 ` Coly Li
2011-01-27 12:12 ` [PATCH 3/7] dma: use BUG_ON correctly in iop-adma.c Coly Li
2011-01-27 12:12 ` [PATCH 4/7] dma: use BUG_ON correctly in mv_xor.c Coly Li
2011-01-27 12:12 ` [PATCH 5/7] dma: use BUG_ON correctly in ppc4xx/adam.c Coly Li
2011-01-27 12:12 ` [PATCH 6/7] wl_cfg80211.c: use BUG_ON correctly Coly Li
2011-01-27 12:12 ` [PATCH 7/7] scsi_lib.c: " Coly Li
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=AE90C24D6B3A694183C094C60CF0A2F6D8AC2D@saturn3.aculab.com \
--to=david.laight@aculab.com \
--cc=bosong.ly@taobao.com \
--cc=ddaney@caviumnetworks.com \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=xiyou.wangcong@gmail.com \
--cc=yong.zhang0@gmail.com \
--subject='RE: [PATCH 2/7] PowerPC: add unlikely() to BUG_ON()' \
/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
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).