git://ftp.safe.ca
/
safe
/
jmp
/
linux-2.6
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bitmap: use for_each_set_bit()
[safe/jmp/linux-2.6]
/
lib
/
hweight.c
diff --git
a/lib/hweight.c
b/lib/hweight.c
index
360556a
..
63ee4eb
100644
(file)
--- a/
lib/hweight.c
+++ b/
lib/hweight.c
@@
-1,6
+1,6
@@
#include <linux/module.h>
#include <linux/module.h>
+#include <linux/bitops.h>
#include <asm/types.h>
#include <asm/types.h>
-#include <asm/bitops.h>
/**
* hweightN - returns the hamming weight of a N-bit word
/**
* hweightN - returns the hamming weight of a N-bit word
@@
-11,11
+11,18
@@
unsigned int hweight32(unsigned int w)
{
unsigned int hweight32(unsigned int w)
{
+#ifdef ARCH_HAS_FAST_MULTIPLIER
+ w -= (w >> 1) & 0x55555555;
+ w = (w & 0x33333333) + ((w >> 2) & 0x33333333);
+ w = (w + (w >> 4)) & 0x0f0f0f0f;
+ return (w * 0x01010101) >> 24;
+#else
unsigned int res = w - ((w >> 1) & 0x55555555);
res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
res = (res + (res >> 4)) & 0x0F0F0F0F;
res = res + (res >> 8);
return (res + (res >> 16)) & 0x000000FF;
unsigned int res = w - ((w >> 1) & 0x55555555);
res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
res = (res + (res >> 4)) & 0x0F0F0F0F;
res = res + (res >> 8);
return (res + (res >> 16)) & 0x000000FF;
+#endif
}
EXPORT_SYMBOL(hweight32);
}
EXPORT_SYMBOL(hweight32);