bitops.h 684 B

123456789101112131415161718192021222324252627
  1. #ifndef _PERF_LINUX_BITOPS_H_
  2. #define _PERF_LINUX_BITOPS_H_
  3. #include <linux/kernel.h>
  4. #include <asm/hweight.h>
  5. #define BITS_PER_LONG __WORDSIZE
  6. #define BITS_PER_BYTE 8
  7. #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
  8. static inline void set_bit(int nr, unsigned long *addr)
  9. {
  10. addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);
  11. }
  12. static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
  13. {
  14. return ((1UL << (nr % BITS_PER_LONG)) &
  15. (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
  16. }
  17. static inline unsigned long hweight_long(unsigned long w)
  18. {
  19. return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
  20. }
  21. #endif