lkml.org 
[lkml]   [2021]   [Jan]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 6/6] lib: add fast path for find_first_*_bit() and find_last_bit()
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


\
 
 \ /
  Last update: 2021-01-21 11:45    [W:0.115 / U:0.116 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site