Thread (16 messages) 16 messages, 4 authors, 2021-01-29

Re: [PATCH 6/6] lib: add fast path for find_first_*_bit() and find_last_bit()

From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Date: 2021-01-21 10:44:27
Also in: linux-arch, linux-m68k, lkml

On Wed, Jan 20, 2021 at 04:06:30PM -0800, Yury Norov wrote:
Similarly to bitmap functions, users will 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.
...
+static inline
+unsigned long find_first_bit(const unsigned long *addr, unsigned long size)
+{
+	if (small_const_nbits(size)) {
+		unsigned long idx;
+
+		if (!*addr)
+			return size;
+
+		idx = __ffs(*addr);
+		return idx < size ? idx : size;
But can't we mask it first, then check for 0 (no bit set) otherwise return the
result of __ffs directly?

Same comment for other similar places.
+	}
+
+	return _find_first_bit(addr, size);
+}

-- 
With Best Regards,
Andy Shevchenko

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help