1 #ifndef _LINUX_BITOPS_H
2 #define _LINUX_BITOPS_H
7 #define BIT(_x) (1 << (_x))
8 #define BITS(_start, _bits) (((1 << (_bits)) - 1) << _start)
9 #define CHECK_BIT(_var, _pos) ((_var) & (1 << (_pos)))
13 * ffs: find first bit set. This is defined the same way as
14 * the libc and compiler builtin ffs routines, therefore
15 * differs in spirit from the above ffz (man ffs).
17 static inline int generic_ffs(int x)
47 * hweightN: returns the hamming weight (i.e. the number
48 * of bits set) of a N-bit word
50 static inline unsigned int generic_hweight32(unsigned int w)
52 unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
53 res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
54 res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F);
55 res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF);
56 return (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF);
59 static inline unsigned int generic_hweight16(unsigned int w)
61 unsigned int res = (w & 0x5555) + ((w >> 1) & 0x5555);
62 res = (res & 0x3333) + ((res >> 2) & 0x3333);
63 res = (res & 0x0F0F) + ((res >> 4) & 0x0F0F);
64 return (res & 0x00FF) + ((res >> 8) & 0x00FF);
67 static inline unsigned int generic_hweight8(unsigned int w)
69 unsigned int res = (w & 0x55) + ((w >> 1) & 0x55);
70 res = (res & 0x33) + ((res >> 2) & 0x33);
71 return (res & 0x0F) + ((res >> 4) & 0x0F);
74 #include <asm/bitops.h>
76 #endif /* !__ASSEMBLY__ */