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

tools: sync find_next_bit implementation

Sync the implementation with recent kernel changes.

Link: https://lkml.kernel.org/r/20210401003153.97325-9-yury.norov@gmail.com
Signed-off-by: Yury Norov <yury.norov@gmail.com>
Acked-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Alexey Klimov <aklimov@redhat.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Sterba <dsterba@suse.com>
Cc: Dennis Zhou <dennis@kernel.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Jianpeng Ma <jianpeng.ma@intel.com>
Cc: Joe Perches <joe@perches.com>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Rich Felker <dalias@libc.org>
Cc: Stefano Brivio <sbrivio@redhat.com>
Cc: Wei Yang <richard.weiyang@linux.alibaba.com>
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>
Cc: Yoshinori Sato <ysato@users.osdn.me>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Yury Norov and committed by
Linus Torvalds
ea81c1ef 5c88af59

+42 -37
+21 -6
tools/include/asm-generic/bitops/find.h
··· 2 2 #ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ 3 3 #define _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ 4 4 5 + extern unsigned long _find_next_bit(const unsigned long *addr1, 6 + const unsigned long *addr2, unsigned long nbits, 7 + unsigned long start, unsigned long invert, unsigned long le); 8 + 5 9 #ifndef find_next_bit 6 10 /** 7 11 * find_next_bit - find the next set bit in a memory region ··· 16 12 * Returns the bit number for the next set bit 17 13 * If no bits are set, returns @size. 18 14 */ 19 - extern unsigned long find_next_bit(const unsigned long *addr, unsigned long 20 - size, unsigned long offset); 15 + static inline 16 + unsigned long find_next_bit(const unsigned long *addr, unsigned long size, 17 + unsigned long offset) 18 + { 19 + return _find_next_bit(addr, NULL, size, offset, 0UL, 0); 20 + } 21 21 #endif 22 22 23 23 #ifndef find_next_and_bit ··· 35 27 * Returns the bit number for the next set bit 36 28 * If no bits are set, returns @size. 37 29 */ 38 - extern unsigned long find_next_and_bit(const unsigned long *addr1, 30 + static inline 31 + unsigned long find_next_and_bit(const unsigned long *addr1, 39 32 const unsigned long *addr2, unsigned long size, 40 - unsigned long offset); 33 + unsigned long offset) 34 + { 35 + return _find_next_bit(addr1, addr2, size, offset, 0UL, 0); 36 + } 41 37 #endif 42 38 43 39 #ifndef find_next_zero_bit 44 - 45 40 /** 46 41 * find_next_zero_bit - find the next cleared bit in a memory region 47 42 * @addr: The address to base the search on ··· 54 43 * Returns the bit number of the next zero bit 55 44 * If no bits are zero, returns @size. 56 45 */ 46 + static inline 57 47 unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, 58 - unsigned long offset); 48 + unsigned long offset) 49 + { 50 + return _find_next_bit(addr, NULL, size, offset, ~0UL, 0); 51 + } 59 52 #endif 60 53 61 54 #ifndef find_first_bit
+21 -31
tools/lib/find_bit.c
··· 28 28 * searching it for one bits. 29 29 * - The optional "addr2", which is anded with "addr1" if present. 30 30 */ 31 - static inline unsigned long _find_next_bit(const unsigned long *addr1, 31 + unsigned long _find_next_bit(const unsigned long *addr1, 32 32 const unsigned long *addr2, unsigned long nbits, 33 - unsigned long start, unsigned long invert) 33 + unsigned long start, unsigned long invert, unsigned long le) 34 34 { 35 - unsigned long tmp; 35 + unsigned long tmp, mask; 36 + (void) le; 36 37 37 38 if (unlikely(start >= nbits)) 38 39 return nbits; ··· 44 43 tmp ^= invert; 45 44 46 45 /* Handle 1st word. */ 47 - tmp &= BITMAP_FIRST_WORD_MASK(start); 46 + mask = BITMAP_FIRST_WORD_MASK(start); 47 + 48 + /* 49 + * Due to the lack of swab() in tools, and the fact that it doesn't 50 + * need little-endian support, just comment it out 51 + */ 52 + #if (0) 53 + if (le) 54 + mask = swab(mask); 55 + #endif 56 + 57 + tmp &= mask; 58 + 48 59 start = round_down(start, BITS_PER_LONG); 49 60 50 61 while (!tmp) { ··· 70 57 tmp ^= invert; 71 58 } 72 59 73 - return min(start + __ffs(tmp), nbits); 74 - } 60 + #if (0) 61 + if (le) 62 + tmp = swab(tmp); 75 63 #endif 76 64 77 - #ifndef find_next_bit 78 - /* 79 - * Find the next set bit in a memory region. 80 - */ 81 - unsigned long find_next_bit(const unsigned long *addr, unsigned long size, 82 - unsigned long offset) 83 - { 84 - return _find_next_bit(addr, NULL, size, offset, 0UL); 65 + return min(start + __ffs(tmp), nbits); 85 66 } 86 67 #endif 87 68 ··· 110 103 } 111 104 112 105 return size; 113 - } 114 - #endif 115 - 116 - #ifndef find_next_zero_bit 117 - unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, 118 - unsigned long offset) 119 - { 120 - return _find_next_bit(addr, NULL, size, offset, ~0UL); 121 - } 122 - #endif 123 - 124 - #ifndef find_next_and_bit 125 - unsigned long find_next_and_bit(const unsigned long *addr1, 126 - const unsigned long *addr2, unsigned long size, 127 - unsigned long offset) 128 - { 129 - return _find_next_bit(addr1, addr2, size, offset, 0UL); 130 106 } 131 107 #endif