Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751861Ab0AGROv (ORCPT ); Thu, 7 Jan 2010 12:14:51 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751191Ab0AGROu (ORCPT ); Thu, 7 Jan 2010 12:14:50 -0500 Received: from hp3.statik.tu-cottbus.de ([141.43.120.68]:49978 "EHLO hp3.statik.tu-cottbus.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751179Ab0AGROu (ORCPT ); Thu, 7 Jan 2010 12:14:50 -0500 X-Greylist: delayed 1687 seconds by postgrey-1.27 at vger.kernel.org; Thu, 07 Jan 2010 12:14:50 EST Message-ID: <4B460F98.9000208@s5r6.in-berlin.de> Date: Thu, 07 Jan 2010 17:45:12 +0100 From: Stefan Richter User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.23) Gecko/20090825 SeaMonkey/1.1.18 MIME-Version: 1.0 To: "Robert P. J. Day" CC: Roland Dreier , Andrew Morton , linux-kernel@vger.kernel.org, Bart Van Assche , David Dillow Subject: Re: [PATCH] Add BUILD_BUG_ON_NOT_POWER_OF_2() References: <20100106123306.ac85e557.akpm@linux-foundation.org> <20100106134232.0025e818.akpm@linux-foundation.org> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1339 Lines: 32 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@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/