Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools: sync tools/bitmap with mother linux

Remove tools/include/asm-generic/bitops/find.h and copy
include/linux/bitmap.h to tools. find_*_le() functions are not copied
because not needed in tools.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

+100 -11
+1 -1
MAINTAINERS
··· 3365 3365 F: lib/find_bit.c 3366 3366 F: lib/find_bit_benchmark.c 3367 3367 F: lib/test_bitmap.c 3368 - F: tools/include/asm-generic/bitops/find.h 3369 3368 F: tools/include/linux/bitmap.h 3369 + F: tools/include/linux/find.h 3370 3370 F: tools/lib/bitmap.c 3371 3371 F: tools/lib/find_bit.c 3372 3372
-1
tools/include/asm-generic/bitops.h
··· 18 18 #include <asm-generic/bitops/fls.h> 19 19 #include <asm-generic/bitops/__fls.h> 20 20 #include <asm-generic/bitops/fls64.h> 21 - #include <asm-generic/bitops/find.h> 22 21 23 22 #ifndef _TOOLS_LINUX_BITOPS_H_ 24 23 #error only <linux/bitops.h> can be included directly
+75 -6
tools/include/asm-generic/bitops/find.h tools/include/linux/find.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ 3 - #define _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ 2 + #ifndef _TOOLS_LINUX_FIND_H_ 3 + #define _TOOLS_LINUX_FIND_H_ 4 + 5 + #ifndef _TOOLS_LINUX_BITMAP_H 6 + #error tools: only <linux/bitmap.h> can be included directly 7 + #endif 8 + 9 + #include <linux/bitops.h> 4 10 5 11 extern unsigned long _find_next_bit(const unsigned long *addr1, 6 12 const unsigned long *addr2, unsigned long nbits, 7 13 unsigned long start, unsigned long invert, unsigned long le); 8 14 extern unsigned long _find_first_bit(const unsigned long *addr, unsigned long size); 15 + extern unsigned long _find_first_and_bit(const unsigned long *addr1, 16 + const unsigned long *addr2, unsigned long size); 9 17 extern unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size); 10 18 extern unsigned long _find_last_bit(const unsigned long *addr, unsigned long size); 11 19 ··· 104 96 #endif 105 97 106 98 #ifndef find_first_bit 107 - 108 99 /** 109 100 * find_first_bit - find the first set bit in a memory region 110 101 * @addr: The address to start the search at ··· 123 116 124 117 return _find_first_bit(addr, size); 125 118 } 119 + #endif 126 120 127 - #endif /* find_first_bit */ 121 + #ifndef find_first_and_bit 122 + /** 123 + * find_first_and_bit - find the first set bit in both memory regions 124 + * @addr1: The first address to base the search on 125 + * @addr2: The second address to base the search on 126 + * @size: The bitmap size in bits 127 + * 128 + * Returns the bit number for the next set bit 129 + * If no bits are set, returns @size. 130 + */ 131 + static inline 132 + unsigned long find_first_and_bit(const unsigned long *addr1, 133 + const unsigned long *addr2, 134 + unsigned long size) 135 + { 136 + if (small_const_nbits(size)) { 137 + unsigned long val = *addr1 & *addr2 & GENMASK(size - 1, 0); 138 + 139 + return val ? __ffs(val) : size; 140 + } 141 + 142 + return _find_first_and_bit(addr1, addr2, size); 143 + } 144 + #endif 128 145 129 146 #ifndef find_first_zero_bit 130 - 131 147 /** 132 148 * find_first_zero_bit - find the first cleared bit in a memory region 133 149 * @addr: The address to start the search at ··· 172 142 } 173 143 #endif 174 144 175 - #endif /*_TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ */ 145 + #ifndef find_last_bit 146 + /** 147 + * find_last_bit - find the last set bit in a memory region 148 + * @addr: The address to start the search at 149 + * @size: The number of bits to search 150 + * 151 + * Returns the bit number of the last set bit, or size. 152 + */ 153 + static inline 154 + unsigned long find_last_bit(const unsigned long *addr, unsigned long size) 155 + { 156 + if (small_const_nbits(size)) { 157 + unsigned long val = *addr & GENMASK(size - 1, 0); 158 + 159 + return val ? __fls(val) : size; 160 + } 161 + 162 + return _find_last_bit(addr, size); 163 + } 164 + #endif 165 + 166 + /** 167 + * find_next_clump8 - find next 8-bit clump with set bits in a memory region 168 + * @clump: location to store copy of found clump 169 + * @addr: address to base the search on 170 + * @size: bitmap size in number of bits 171 + * @offset: bit offset at which to start searching 172 + * 173 + * Returns the bit offset for the next set clump; the found clump value is 174 + * copied to the location pointed by @clump. If no bits are set, returns @size. 175 + */ 176 + extern unsigned long find_next_clump8(unsigned long *clump, 177 + const unsigned long *addr, 178 + unsigned long size, unsigned long offset); 179 + 180 + #define find_first_clump8(clump, bits, size) \ 181 + find_next_clump8((clump), (bits), (size), 0) 182 + 183 + 184 + #endif /*__LINUX_FIND_H_ */
+4 -3
tools/include/linux/bitmap.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _PERF_BITOPS_H 3 - #define _PERF_BITOPS_H 2 + #ifndef _TOOLS_LINUX_BITMAP_H 3 + #define _TOOLS_LINUX_BITMAP_H 4 4 5 5 #include <string.h> 6 6 #include <linux/bitops.h> 7 + #include <linux/find.h> 7 8 #include <stdlib.h> 8 9 #include <linux/kernel.h> 9 10 ··· 182 181 return __bitmap_intersects(src1, src2, nbits); 183 182 } 184 183 185 - #endif /* _PERF_BITOPS_H */ 184 + #endif /* _TOOLS_LINUX_BITMAP_H */
+20
tools/lib/find_bit.c
··· 96 96 } 97 97 #endif 98 98 99 + #ifndef find_first_and_bit 100 + /* 101 + * Find the first set bit in two memory regions. 102 + */ 103 + unsigned long _find_first_and_bit(const unsigned long *addr1, 104 + const unsigned long *addr2, 105 + unsigned long size) 106 + { 107 + unsigned long idx, val; 108 + 109 + for (idx = 0; idx * BITS_PER_LONG < size; idx++) { 110 + val = addr1[idx] & addr2[idx]; 111 + if (val) 112 + return min(idx * BITS_PER_LONG + __ffs(val), size); 113 + } 114 + 115 + return size; 116 + } 117 + #endif 118 + 99 119 #ifndef find_first_zero_bit 100 120 /* 101 121 * Find the first cleared bit in a memory region.