Frederic Weisbecker | 5a116dd | 2009-10-17 17:12:33 +0200 | [diff] [blame] | 1 | #ifndef _PERF_LINUX_BITOPS_H_ |
| 2 | #define _PERF_LINUX_BITOPS_H_ |
| 3 | |
Arnaldo Carvalho de Melo | fb72014 | 2010-04-30 19:31:12 -0300 | [diff] [blame^] | 4 | #include <linux/kernel.h> |
| 5 | #include <asm/hweight.h> |
Frederic Weisbecker | 5a116dd | 2009-10-17 17:12:33 +0200 | [diff] [blame] | 6 | |
Arnaldo Carvalho de Melo | fb72014 | 2010-04-30 19:31:12 -0300 | [diff] [blame^] | 7 | #define BITS_PER_LONG __WORDSIZE |
| 8 | #define BITS_PER_BYTE 8 |
| 9 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) |
Paul Mackerras | ee3d250 | 2009-11-24 15:19:43 +1100 | [diff] [blame] | 10 | |
Frederic Weisbecker | 5a116dd | 2009-10-17 17:12:33 +0200 | [diff] [blame] | 11 | static inline void set_bit(int nr, unsigned long *addr) |
| 12 | { |
| 13 | addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG); |
| 14 | } |
| 15 | |
| 16 | static __always_inline int test_bit(unsigned int nr, const unsigned long *addr) |
| 17 | { |
| 18 | return ((1UL << (nr % BITS_PER_LONG)) & |
| 19 | (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0; |
| 20 | } |
| 21 | |
Arnaldo Carvalho de Melo | fb72014 | 2010-04-30 19:31:12 -0300 | [diff] [blame^] | 22 | static inline unsigned long hweight_long(unsigned long w) |
| 23 | { |
| 24 | return sizeof(w) == 4 ? hweight32(w) : hweight64(w); |
| 25 | } |
Frederic Weisbecker | 5a116dd | 2009-10-17 17:12:33 +0200 | [diff] [blame] | 26 | |
| 27 | #endif |