From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wu Fengguang Subject: [PATCH 2/5] bitops: compile time optimization for hweight_long(CONSTANT) Date: Sat, 30 Jan 2010 17:45:17 +0800 Message-ID: <20100130094957.692671259@intel.com> References: <20100130094515.475881280@intel.com> Cc: Wu Fengguang , LKML , Jamie Lokier , Roland Dreier To: Andrew Morton Return-path: cc: Al Viro cc: Content-Disposition: inline; filename=constant-hweight32.patch Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org 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