diff options
Diffstat (limited to 'include/asm-generic/bitops/hweight.h')
-rw-r--r-- | include/asm-generic/bitops/hweight.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/include/asm-generic/bitops/hweight.h b/include/asm-generic/bitops/hweight.h index af9770de4e..7268c8b9ab 100644 --- a/include/asm-generic/bitops/hweight.h +++ b/include/asm-generic/bitops/hweight.h @@ -32,4 +32,19 @@ static inline unsigned int hweight8(unsigned int w) return (res & 0x0F) + ((res >> 4) & 0x0F); } +static inline 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 + __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; +#endif +} + #endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */ |