summaryrefslogtreecommitdiffstats
path: root/tools/include
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2016-10-10 03:26:33 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-10-24 10:07:33 -0400
commit02bc11de567273da8ab25c54336ddbb71986f38f (patch)
tree2356fcbb1ad8571a14e61ca58575a752c3de6c2c /tools/include
parentfe316723a8106c7527710ae7085a1dc6a9c1ab05 (diff)
tools lib: Add for_each_clear_bit macro
Adding for_each_clear_bit macro plus all its the necessary backbone functions. Taken from related kernel code. It will be used in following patch. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-cayv2zbqi0nlmg5sjjxs1775@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/asm-generic/bitops.h1
-rw-r--r--tools/include/asm-generic/bitops/__ffz.h12
-rw-r--r--tools/include/asm-generic/bitops/find.h28
-rw-r--r--tools/include/linux/bitops.h5
4 files changed, 46 insertions, 0 deletions
diff --git a/tools/include/asm-generic/bitops.h b/tools/include/asm-generic/bitops.h
index 653d1bad77de..0304600121da 100644
--- a/tools/include/asm-generic/bitops.h
+++ b/tools/include/asm-generic/bitops.h
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <asm-generic/bitops/__ffs.h> 15#include <asm-generic/bitops/__ffs.h>
16#include <asm-generic/bitops/__ffz.h>
16#include <asm-generic/bitops/fls.h> 17#include <asm-generic/bitops/fls.h>
17#include <asm-generic/bitops/__fls.h> 18#include <asm-generic/bitops/__fls.h>
18#include <asm-generic/bitops/fls64.h> 19#include <asm-generic/bitops/fls64.h>
diff --git a/tools/include/asm-generic/bitops/__ffz.h b/tools/include/asm-generic/bitops/__ffz.h
new file mode 100644
index 000000000000..6744bd4cdf46
--- /dev/null
+++ b/tools/include/asm-generic/bitops/__ffz.h
@@ -0,0 +1,12 @@
1#ifndef _ASM_GENERIC_BITOPS_FFZ_H_
2#define _ASM_GENERIC_BITOPS_FFZ_H_
3
4/*
5 * ffz - find first zero in word.
6 * @word: The word to search
7 *
8 * Undefined if no zero exists, so code should check against ~0UL first.
9 */
10#define ffz(x) __ffs(~(x))
11
12#endif /* _ASM_GENERIC_BITOPS_FFZ_H_ */
diff --git a/tools/include/asm-generic/bitops/find.h b/tools/include/asm-generic/bitops/find.h
index 31f51547fcd4..5538ecdc964a 100644
--- a/tools/include/asm-generic/bitops/find.h
+++ b/tools/include/asm-generic/bitops/find.h
@@ -15,6 +15,21 @@ extern unsigned long find_next_bit(const unsigned long *addr, unsigned long
15 size, unsigned long offset); 15 size, unsigned long offset);
16#endif 16#endif
17 17
18#ifndef find_next_zero_bit
19
20/**
21 * find_next_zero_bit - find the next cleared bit in a memory region
22 * @addr: The address to base the search on
23 * @offset: The bitnumber to start searching at
24 * @size: The bitmap size in bits
25 *
26 * Returns the bit number of the next zero bit
27 * If no bits are zero, returns @size.
28 */
29unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
30 unsigned long offset);
31#endif
32
18#ifndef find_first_bit 33#ifndef find_first_bit
19 34
20/** 35/**
@@ -30,4 +45,17 @@ extern unsigned long find_first_bit(const unsigned long *addr,
30 45
31#endif /* find_first_bit */ 46#endif /* find_first_bit */
32 47
48#ifndef find_first_zero_bit
49
50/**
51 * find_first_zero_bit - find the first cleared bit in a memory region
52 * @addr: The address to start the search at
53 * @size: The maximum number of bits to search
54 *
55 * Returns the bit number of the first cleared bit.
56 * If no bits are zero, returns @size.
57 */
58unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size);
59#endif
60
33#endif /*_TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ */ 61#endif /*_TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ */
diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
index 49c929a104ee..fc446343ff41 100644
--- a/tools/include/linux/bitops.h
+++ b/tools/include/linux/bitops.h
@@ -39,6 +39,11 @@ extern unsigned long __sw_hweight64(__u64 w);
39 (bit) < (size); \ 39 (bit) < (size); \
40 (bit) = find_next_bit((addr), (size), (bit) + 1)) 40 (bit) = find_next_bit((addr), (size), (bit) + 1))
41 41
42#define for_each_clear_bit(bit, addr, size) \
43 for ((bit) = find_first_zero_bit((addr), (size)); \
44 (bit) < (size); \
45 (bit) = find_next_zero_bit((addr), (size), (bit) + 1))
46
42/* same as for_each_set_bit() but use bit as value to start with */ 47/* same as for_each_set_bit() but use bit as value to start with */
43#define for_each_set_bit_from(bit, addr, size) \ 48#define for_each_set_bit_from(bit, addr, size) \
44 for ((bit) = find_next_bit((addr), (size), (bit)); \ 49 for ((bit) = find_next_bit((addr), (size), (bit)); \