2009-10-17 23:12:33 +08:00
|
|
|
#ifndef _PERF_LINUX_BITOPS_H_
|
|
|
|
#define _PERF_LINUX_BITOPS_H_
|
|
|
|
|
2010-05-01 06:31:12 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <asm/hweight.h>
|
2009-10-17 23:12:33 +08:00
|
|
|
|
2010-05-01 06:31:12 +08:00
|
|
|
#define BITS_PER_LONG __WORDSIZE
|
|
|
|
#define BITS_PER_BYTE 8
|
|
|
|
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
|
2009-11-24 12:19:43 +08:00
|
|
|
|
2009-10-17 23:12:33 +08:00
|
|
|
static inline void set_bit(int nr, unsigned long *addr)
|
|
|
|
{
|
|
|
|
addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);
|
|
|
|
}
|
|
|
|
|
2010-11-27 05:39:15 +08:00
|
|
|
static inline void clear_bit(int nr, unsigned long *addr)
|
|
|
|
{
|
|
|
|
addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG));
|
|
|
|
}
|
|
|
|
|
2009-10-17 23:12:33 +08:00
|
|
|
static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
|
|
|
|
{
|
|
|
|
return ((1UL << (nr % BITS_PER_LONG)) &
|
|
|
|
(((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
|
|
|
|
}
|
|
|
|
|
2010-05-01 06:31:12 +08:00
|
|
|
static inline unsigned long hweight_long(unsigned long w)
|
|
|
|
{
|
|
|
|
return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
|
|
|
|
}
|
2009-10-17 23:12:33 +08:00
|
|
|
|
|
|
|
#endif
|