From: Andrew Morton <akpm@linux-foundation.org>
To: Roland Dreier <rdreier@cisco.com>
Cc: linux-kernel@vger.kernel.org,
Bart Van Assche <bart.vanassche@gmail.com>,
David Dillow <dave@thedillows.org>
Subject: Re: [PATCH] log2.h: Macro-ize is_power_of_2() for use in BUILD_BUG_ON
Date: Wed, 6 Jan 2010 13:42:32 -0800 [thread overview]
Message-ID: <20100106134232.0025e818.akpm@linux-foundation.org> (raw)
In-Reply-To: <aday6kbt14a.fsf@roland-alpha.cisco.com>
On Wed, 06 Jan 2010 12:44:05 -0800
Roland Dreier <rdreier@cisco.com> wrote:
>
> > Perhaps we can avoid worrying about that via
>
> > #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \
> > BUILD_BUG_ON((n != 0 && ((n & (n - 1)) == 0)))
>
> Having something so specific to this particular case makes me feel like
> maybe it's just not worth it.
mm.. I think _something_ is worth it. The requirement that a constant
be a power of two is a very common one in the kernel.
If you feel strongly about it and think the incremental benefit of your
version is worth the effort of screening out gcc warts then ho hum, go
for it I guess.
> At least in the case I'm looking at, we
> could just have:
>
> /*
> * The code relies on FOO being a power of 2. If you break this,
> * you're dumb.
> */
> #define FOO_SHIFT 6
> #define FOO (1 << FOO_SHIFT)
>
> Your thoughts?
Given the probably-hundreds of sites which could utilise this assertion,
that approach will be a bit of a PITA.
next prev parent reply other threads:[~2010-01-06 21:43 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-06 20:21 [PATCH] log2.h: Macro-ize is_power_of_2() for use in BUILD_BUG_ON Roland Dreier
2010-01-06 20:33 ` Andrew Morton
2010-01-06 20:44 ` Roland Dreier
2010-01-06 21:15 ` David Dillow
2010-01-06 21:42 ` Andrew Morton [this message]
2010-01-06 23:02 ` [PATCH] Add BUILD_BUG_ON_NOT_POWER_OF_2() Roland Dreier
2010-01-06 23:09 ` Andrew Morton
2010-01-07 7:33 ` Bart Van Assche
2010-01-07 7:51 ` Roland Dreier
2010-01-07 8:36 ` Robert P. J. Day
2010-01-07 16:45 ` Stefan Richter
2010-01-06 21:23 ` [PATCH] log2.h: Macro-ize is_power_of_2() for use in BUILD_BUG_ON Roland Dreier
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=20100106134232.0025e818.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=bart.vanassche@gmail.com \
--cc=dave@thedillows.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rdreier@cisco.com \
/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