mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: "Robert P. J. Day" <rpjday@crashcourse.ca>
Cc: Roland Dreier <rdreier@cisco.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	Bart Van Assche <bart.vanassche@gmail.com>,
	David Dillow <dave@thedillows.org>
Subject: Re: [PATCH] Add BUILD_BUG_ON_NOT_POWER_OF_2()
Date: Thu, 07 Jan 2010 17:45:12 +0100	[thread overview]
Message-ID: <4B460F98.9000208@s5r6.in-berlin.de> (raw)
In-Reply-To: <alpine.LFD.2.00.1001070332060.16874@localhost>

Robert P. J. Day wrote:
>   my normal pedantry coming to the surface, but can we at least assume
> that people will use this test to *legitimately* test whether or not
> something is a power of two, and not that there is a single bit set
> (in the case of mask bits where all settings must be mutually
> exclusive)?
> 
>   there's a lot of this sort of thing throughout the kernel:
> 
>     (n) != 0 && (((n) & ((n) - 1))
> 
> but it's sometimes unclear whether someone is testing for a) power of
> two, or b) single bit set.  if you're going to introduce that kind of
> BUILD BUG (which is a good idea), let's try to not immediately abuse
> it semantically. :-)

It's merely about math, not about semantics.  Plus, its application is
restricted to build-time checks (of defined constants) anyway.

Hence I would argue that "check at build time whether a defined
bitmask's Hamming weight is 1; abort build if it isn't" can be
legitimately and sufficiently readably implemented by means of the new
BUILD_BUG_ON_NOT_POWER_OF_2().
-- 
Stefan Richter
-=====-==-=- ---= --===
http://arcgraph.de/sr/

  reply	other threads:[~2010-01-07 17:14 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
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 [this message]
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=4B460F98.9000208@s5r6.in-berlin.de \
    --to=stefanr@s5r6.in-berlin.de \
    --cc=akpm@linux-foundation.org \
    --cc=bart.vanassche@gmail.com \
    --cc=dave@thedillows.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdreier@cisco.com \
    --cc=rpjday@crashcourse.ca \
    /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

all inboxes | Powered by JetHome®