Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 35922
b: refs/heads/master
c: 0136611
h: refs/heads/master
v: v3
  • Loading branch information
Andi Kleen authored and Andi Kleen committed Sep 26, 2006
1 parent 7c06247 commit 215e5f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8380aabb99719af583447133f19a4d8074b5c337
refs/heads/master: 0136611c62e8650e354b95c76dff6d2ce6030eff
2 changes: 2 additions & 0 deletions trunk/include/asm-x86_64/bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ static __inline__ int fls(int x)
return r+1;
}

#define ARCH_HAS_FAST_MULTIPLIER 1

#include <asm-generic/bitops/hweight.h>

#endif /* __KERNEL__ */
Expand Down
10 changes: 8 additions & 2 deletions trunk/lib/hweight.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <linux/module.h>
#include <asm/types.h>
#include <asm/bitops.h>

/**
* hweightN - returns the hamming weight of a N-bit word
Expand Down Expand Up @@ -40,14 +41,19 @@ unsigned long hweight64(__u64 w)
#if BITS_PER_LONG == 32
return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
#elif BITS_PER_LONG == 64
#ifdef ARCH_HAS_FAST_MULTIPLIER
w -= (w >> 1) & 0x5555555555555555ul;
w = (w & 0x3333333333333333ul) + ((w >> 2) & 0x3333333333333333ul);
w = (w + (w >> 4)) & 0x0f0f0f0f0f0f0f0ful;
return (w * 0x0101010101010101ul) >> 56;
#else
__u64 res = w - ((w >> 1) & 0x5555555555555555ul);
res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
res = res + (res >> 8);
res = res + (res >> 16);
return (res + (res >> 32)) & 0x00000000000000FFul;
#else
#error BITS_PER_LONG not defined
#endif
#endif
}
EXPORT_SYMBOL(hweight64);

0 comments on commit 215e5f0

Please sign in to comment.