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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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





[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux