On Wed, Jan 20, 2021 at 04:06:29PM -0800, Yury Norov wrote:
> Similarly to bitmap functions, find_next_*_bit() users will benefit
> if we'll handle a case of bitmaps that fit into a single word. In the
> very best case, the compiler may replace a function call with a
> single ffs or ffz instruction.

> +     if (small_const_nbits(size)) {
> +             unsigned long val;
> +
> +             if (unlikely(offset >= size))
> +                     return size;

> +             val = *addr & BITMAP_FIRST_WORD_MASK(offset)
> +                             & BITMAP_LAST_WORD_MASK(size);

Seems like a new helper can be introduced (BITS or BITMAP namespace depending
on the decision):

#define _OFFSET_SIZE_MASK(o,s)                                  \
        (BITMAP_FIRST_WORD_MASK(o) & BITMAP_LAST_WORD_MASK(s))

                val = *addr & BITMAP_OFFSET_SIZE_MASK(offset, size);

And so on below.

> +             return val ? __ffs(val) : size;
> +     }

-- 
With Best Regards,
Andy Shevchenko


Reply via email to