blob: 305c8484f200c67eecff39369db873687bc8655c [file] [log] [blame]
Frederic Weisbecker5a116dd2009-10-17 17:12:33 +02001#ifndef _PERF_LINUX_BITOPS_H_
2#define _PERF_LINUX_BITOPS_H_
3
Arnaldo Carvalho de Melofb720142010-04-30 19:31:12 -03004#include <linux/kernel.h>
Arnaldo Carvalho de Meloa860a602011-01-22 19:07:36 -02005#include <linux/compiler.h>
Arnaldo Carvalho de Melofb720142010-04-30 19:31:12 -03006#include <asm/hweight.h>
Frederic Weisbecker5a116dd2009-10-17 17:12:33 +02007
Arnaldo Carvalho de Melofb720142010-04-30 19:31:12 -03008#define BITS_PER_LONG __WORDSIZE
9#define BITS_PER_BYTE 8
10#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
Paul Mackerrasee3d2502009-11-24 15:19:43 +110011
Frederic Weisbecker5a116dd2009-10-17 17:12:33 +020012static inline void set_bit(int nr, unsigned long *addr)
13{
14 addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);
15}
16
Arnaldo Carvalho de Melobaa2f6c2010-11-26 19:39:15 -020017static inline void clear_bit(int nr, unsigned long *addr)
18{
19 addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG));
20}
21
Frederic Weisbecker5a116dd2009-10-17 17:12:33 +020022static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
23{
24 return ((1UL << (nr % BITS_PER_LONG)) &
25 (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
26}
27
Arnaldo Carvalho de Melofb720142010-04-30 19:31:12 -030028static inline unsigned long hweight_long(unsigned long w)
29{
30 return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
31}
Frederic Weisbecker5a116dd2009-10-17 17:12:33 +020032
33#endif