lkml.org 
[lkml]   [2022]   [Sep]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v3 3/4] lib/find_bit: optimize find_next_bit() functions
On Wed, Sep 07, 2022 at 05:27:08PM +0100, Valentin Schneider wrote:
> On 27/08/22 10:58, Yury Norov wrote:
> > +#define FIND_NEXT_BIT(FETCH, MUNGE, size, start) \
> > +({ \
> > + unsigned long mask, idx, tmp, sz = (size), __start = (start); \
> > + \
> > + if (unlikely(__start >= sz)) \
> > + goto out; \
> > + \
> > + mask = MUNGE(BITMAP_FIRST_WORD_MASK(__start)); \
> > + idx = __start / BITS_PER_LONG; \
> > + \
> > + for (tmp = (FETCH) & mask; !tmp; tmp = (FETCH)) { \
> > + if (idx > sz / BITS_PER_LONG) \
>
> Does that want to be

Yes, I already fixed this.

> if (idx + 1 >= sz / BITS_PER_LONG)
>
> ?
>
> Consider this as used in _find_next_bit() for an all-zero 128-bit wide
> bitmap (two ULL's), providing the memory contiguous to the bitmap is also
> zero then this will only stop at idx=3, so that's fetching two ULLs too
> far.
>
> > + goto out; \
> > + idx++; \
> > + } \
> > + \
> > + sz = min(idx * BITS_PER_LONG + __ffs(MUNGE(tmp)), sz); \
> > +out: \
> > + sz; \
> > +})

\
 
 \ /
  Last update: 2022-09-07 18:58    [W:0.124 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site