[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <4B460F98.9000208@s5r6.in-berlin.de>
Date: Thu, 07 Jan 2010 17:45:12 +0100
From: Stefan Richter <stefanr@...6.in-berlin.de>
To: "Robert P. J. Day" <rpjday@...shcourse.ca>
CC: Roland Dreier <rdreier@...co.com>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org,
Bart Van Assche <bart.vanassche@...il.com>,
David Dillow <dave@...dillows.org>
Subject: Re: [PATCH] Add BUILD_BUG_ON_NOT_POWER_OF_2()
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/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists