diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-12-16 08:55:42 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-12-17 09:17:53 -0500 |
commit | 3967278496ffa69704b941745de393223406a83d (patch) | |
tree | 7ef32833134cee6362dc726d89c00d4e160cdfe2 /tools/include | |
parent | 88bcea43fdad515074f03aee75616f6562cb8b95 (diff) |
tools: Move bitops.h from tools/perf/util to tools/
So that we better mirror the kernel sources and make it available for
other tools.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-mvfu6x753tksnto3t6412m93@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/include')
-rw-r--r-- | tools/include/linux/bitops.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h new file mode 100644 index 000000000000..5237bc9f6266 --- /dev/null +++ b/tools/include/linux/bitops.h | |||
@@ -0,0 +1,46 @@ | |||
1 | #ifndef _TOOLS_LINUX_BITOPS_H_ | ||
2 | #define _TOOLS_LINUX_BITOPS_H_ | ||
3 | |||
4 | #include <linux/kernel.h> | ||
5 | #include <linux/compiler.h> | ||
6 | #include <asm/hweight.h> | ||
7 | |||
8 | #ifndef __WORDSIZE | ||
9 | #define __WORDSIZE (__SIZEOF_LONG__ * 8) | ||
10 | #endif | ||
11 | |||
12 | #define BITS_PER_LONG __WORDSIZE | ||
13 | |||
14 | #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) | ||
15 | #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) | ||
16 | #define BITS_PER_BYTE 8 | ||
17 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) | ||
18 | #define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64)) | ||
19 | #define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32)) | ||
20 | #define BITS_TO_BYTES(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE) | ||
21 | |||
22 | /* | ||
23 | * Include this here because some architectures need generic_ffs/fls in | ||
24 | * scope | ||
25 | * | ||
26 | * XXX: this needs to be asm/bitops.h, when we get to per arch optimizations | ||
27 | */ | ||
28 | #include <asm-generic/bitops.h> | ||
29 | |||
30 | #define for_each_set_bit(bit, addr, size) \ | ||
31 | for ((bit) = find_first_bit((addr), (size)); \ | ||
32 | (bit) < (size); \ | ||
33 | (bit) = find_next_bit((addr), (size), (bit) + 1)) | ||
34 | |||
35 | /* same as for_each_set_bit() but use bit as value to start with */ | ||
36 | #define for_each_set_bit_from(bit, addr, size) \ | ||
37 | for ((bit) = find_next_bit((addr), (size), (bit)); \ | ||
38 | (bit) < (size); \ | ||
39 | (bit) = find_next_bit((addr), (size), (bit) + 1)) | ||
40 | |||
41 | static inline unsigned long hweight_long(unsigned long w) | ||
42 | { | ||
43 | return sizeof(w) == 4 ? hweight32(w) : hweight64(w); | ||
44 | } | ||
45 | |||
46 | #endif | ||