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


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