On Tue, Apr 06, 2021 at 09:03:27AM -0700, Guenter Roeck wrote:
On Mon, Mar 15, 2021 at 06:54:22PM -0700, Yury Norov wrote:
Similarly to bitmap functions, users would benefit if we'll handle
a case of small-size bitmaps that fit into a single word.
While here, move the find_last_bit() declaration to bitops/find.h
where other find_*_bit() functions sit.
Signed-off-by: Yury Norov <yury.norov@xxxxxxxxx>
---
include/asm-generic/bitops/find.h | 50 ++++++++++++++++++++++++++++---
include/linux/bitops.h | 12 --------
lib/find_bit.c | 12 ++++----
3 files changed, 52 insertions(+), 22 deletions(-)
diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h
index 4148c74a1e4d..8d818b304869 100644
--- a/include/asm-generic/bitops/find.h
+++ b/include/asm-generic/bitops/find.h
@@ -5,6 +5,9 @@
extern unsigned long _find_next_bit(const unsigned long *addr1,
const unsigned long *addr2, unsigned long nbits,
unsigned long start, unsigned long invert, unsigned long le);
+extern unsigned long _find_first_bit(const unsigned long *addr, unsigned long size);
+extern unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size);
+extern unsigned long _find_last_bit(const unsigned long *addr, unsigned long size);
#ifndef find_next_bit
/**
@@ -102,8 +105,17 @@ unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,
* Returns the bit number of the first set bit.
* If no bits are set, returns @size.
*/
-extern unsigned long find_first_bit(const unsigned long *addr,
- unsigned long size);
+static inline
+unsigned long find_first_bit(const unsigned long *addr, unsigned long size)
+{
+ if (small_const_nbits(size)) {
+ unsigned long val = *addr & BITS_FIRST(size - 1);
+
+ return val ? __ffs(val) : size;
This patch results in:
include/asm-generic/bitops/find.h: In function 'find_last_bit':
include/asm-generic/bitops/find.h:164:16: error: implicit declaration of function '__fls'; did you mean '__ffs'?
and:
./include/asm-generic/bitops/__fls.h: At top level:
./include/asm-generic/bitops/__fls.h:13:38: error: conflicting types for '__fls'
when building scripts/mod/devicetable-offsets.o.
Seen with h8300 builds.
Guenter
The patch is here:
https://lkml.org/lkml/2021/4/1/1184
Yury