Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753063Ab0BAUtQ (ORCPT ); Mon, 1 Feb 2010 15:49:16 -0500 Received: from smtp1.linux-foundation.org ([140.211.169.13]:37776 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752711Ab0BAUtO (ORCPT ); Mon, 1 Feb 2010 15:49:14 -0500 Date: Mon, 1 Feb 2010 12:48:25 -0800 From: Andrew Morton To: Wu Fengguang Cc: LKML , Jamie Lokier , Roland Dreier , Al Viro , , Ingo Molnar , Peter Zijlstra Subject: Re: [PATCH 2/5] bitops: compile time optimization for hweight_long(CONSTANT) Message-Id: <20100201124825.cc024f2a.akpm@linux-foundation.org> In-Reply-To: <20100130094957.692671259@intel.com> References: <20100130094515.475881280@intel.com> <20100130094957.692671259@intel.com> X-Mailer: Sylpheed 2.4.8 (GTK+ 2.12.9; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1562 Lines: 49 On Sat, 30 Jan 2010 17:45:17 +0800 Wu Fengguang wrote: > This allows use of hweight_long() in BUILD_BUG_ON(). > Suggested by Jamie. > > CC: Jamie Lokier > CC: Roland Dreier > Signed-off-by: Wu Fengguang > --- > include/linux/bitops.h | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > --- linux-mm.orig/include/linux/bitops.h 2009-07-20 20:10:19.000000000 +0800 > +++ linux-mm/include/linux/bitops.h 2010-01-30 17:41:15.000000000 +0800 > @@ -40,10 +40,14 @@ static __inline__ int get_count_order(un > return order; > } > > -static inline unsigned long hweight_long(unsigned long w) > -{ > - return sizeof(w) == 4 ? hweight32(w) : hweight64(w); > -} > +#define hweight_long(x) \ > +( \ > + __builtin_constant_p(x) ? \ > + __builtin_popcountl(x) : \ > + (sizeof(x) <= 4 ? \ > + hweight32(x) : \ > + hweight64(x)) \ > +) > > /** > * rol32 - rotate a 32-bit value left Peter's been mucking with a compile-time HWEIGHT(). An outdated version of that is presently in linux-next. (I wonder if it could have used __builtin_popcount) (I wonder which gcc versions support __builtin_popcount) Anyway, I suspect you should be using that rather than tweaking hweight_long(). -- 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/