From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752357Ab0HVTiZ (ORCPT ); Sun, 22 Aug 2010 15:38:25 -0400 Received: from mail.openrapids.net ([64.15.138.104]:40890 "EHLO blackscsi.openrapids.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751485Ab0HVTiW (ORCPT ); Sun, 22 Aug 2010 15:38:22 -0400 Date: Sun, 22 Aug 2010 15:38:20 -0400 From: Mathieu Desnoyers To: Andi Kleen Cc: LKML , ltt-dev@lists.casi.polymtl.ca, Linus Torvalds , Andrew Morton , Ingo Molnar , Peter Zijlstra , Steven Rostedt , Frederic Weisbecker , Thomas Gleixner , Christoph Hellwig , Li Zefan , Lai Jiangshan , Johannes Berg , Masami Hiramatsu , Arnaldo Carvalho de Melo , Tom Zanussi , KOSAKI Motohiro , Alexander Shishkin , Russell King - ARM Linux , linux-arm-kernel@lists.infradead.org, Imre Deak , Jamie Lokier , Alexey Dobriyan , "Kirill A. Shutemov" Subject: Re: [PATCH for -tip 1/2] kernel.h: add MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2 Message-ID: <20100822193819.GA23299@Krystal> References: <20100821141750.770348530@efficios.com> <20100821142215.023431313@efficios.com> <20100822192705.GE1771@one.firstfloor.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100822192705.GE1771@one.firstfloor.org> X-Editor: vi X-Info: http://www.efficios.com X-Operating-System: Linux/2.6.26-2-686 (i686) X-Uptime: 15:35:09 up 211 days, 22:11, 3 users, load average: 0.33, 0.21, 0.13 User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Andi Kleen (andi@firstfloor.org) wrote: > > +/* Force a compilation error if condition is constant and not a power of 2 */ > > +#define MAYBE_BUILD_BUG_ON_NOT_POWER_OF_2(n) \ > > + MAYBE_BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) > > Looks super-ugly. IMHO just writing MAYBE_BUILD_BUG_ON(!n || n & (n - 1)) directly > would be clear enough. If you really think that's unclear define a generic > is_power_of_two() macro. There is already a is_power_of_two macro in log2.h, but I fear it might incorrectly interact with "MAYBE_BUILD_BUG_ON" (for some reason passing the constant result of a static inline is not treated as a constant by the macro, and thus it always "passes" the test). So if everyone object to this new macro, I'd be tempted to just go with your suggestion. However the fact that we already have BUILD_BUG_ON_NOT_POWER_OF_2(n) made me think that some people prefer to have it done as a macro. Other opinions ? Thanks, Mathieu -- Mathieu Desnoyers Operating System Efficiency R&D Consultant EfficiOS Inc. http://www.efficios.com