1 #ifndef _LINUX_BITOPS_H
2 #define _LINUX_BITOPS_H
6 * ffs: find first bit set. This is defined the same way as
7 * the libc and compiler builtin ffs routines, therefore
8 * differs in spirit from the above ffz (man ffs).
11 static inline int generic_ffs(int x)
41 * hweightN: returns the hamming weight (i.e. the number
42 * of bits set) of a N-bit word
45 static inline unsigned int generic_hweight32(unsigned int w)
47 unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
48 res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
49 res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
50 res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
51 return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
54 static inline unsigned int generic_hweight16(unsigned int w)
56 unsigned int res = (w & 0x5555) + ((w >> 1) & 0x5555);
57 res = (res & 0x3333) + ((res >> 2) & 0x3333);
58 res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F);
59 return (res & 0x00FF) + ((res >> 8) & 0x00FF);
62 static inline unsigned int generic_hweight8(unsigned int w)
64 unsigned int res = (w & 0x55) + ((w >> 1) & 0x55);
65 res = (res & 0x33) + ((res >> 2) & 0x33);
66 return (res & 0x0F) + ((res >> 4) & 0x0F);
69 #include <asm/bitops.h>