lkml.org 
[lkml]   [2010]   [Jan]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 2/6] bitops: compile time optimization for hweight_long(CONSTANT)
This allows use of hweight_long() in BUILD_BUG_ON().
Suggested by Jamie.

CC: Jamie Lokier <jamie@shareable.org>
CC: Roland Dreier <rdreier@cisco.com>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
include/linux/bitops.h | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
--- linux.orig/include/linux/bitops.h 2010-01-09 12:13:00.000000000 +0800
+++ linux/include/linux/bitops.h 2010-01-09 12:21:50.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



\
 
 \ /
  Last update: 2010-01-15 02:53    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site