1 #ifndef _KVM_LINUX_BITOPS_H_ 2 #define _KVM_LINUX_BITOPS_H_ 3 4 #include <bits/wordsize.h> 5 6 #include <linux/kernel.h> 7 #include <linux/compiler.h> 8 #include <asm/hweight.h> 9 10 #define BITS_PER_LONG __WORDSIZE 11 #define BITS_PER_BYTE 8 12 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) 13 14 #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) 15 16 static inline void set_bit(int nr, unsigned long *addr) 17 { 18 addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG); 19 } 20 21 static inline void clear_bit(int nr, unsigned long *addr) 22 { 23 addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG)); 24 } 25 26 static __always_inline int test_bit(unsigned int nr, const unsigned long *addr) 27 { 28 return ((1UL << (nr % BITS_PER_LONG)) & 29 (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0; 30 } 31 32 static inline unsigned long hweight_long(unsigned long w) 33 { 34 return sizeof(w) == 4 ? hweight32(w) : hweight64(w); 35 } 36 37 #endif 38