lkml.org 
[lkml]   [2023]   [Sep]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v1 2/5] lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers
> > +unsigned int bitmap_gather(unsigned long *dst, const unsigned long *src,
> > + const unsigned long *mask, unsigned int nbits)
> > +{
> > + unsigned int bit;
> > + int n = 0;
> > +
> > + bitmap_zero(dst, nbits);
> > +
> > + for_each_set_bit(bit, mask, nbits)
> > + __assign_bit(n++, dst, test_bit(bit, src));
> > +
> > + return n;
> > +}
> > +EXPORT_SYMBOL(bitmap_gather);

So, if mask is 0b01, and src is 0b10, the output will be 0b00.
To me it sounds like you've gathered nothing, while the intention
was to gather all source bits to bit #0. This is my understanding
of the word 'gather', and this is how bitmap_remap() works.

bitmap_remap() handles it by wrapping around 0:
set_bit(find_nth_bit(new, nbits, n % w), dst);

In your case, it may look like:
n = off = 0;
while (1) {
off += n;
n = 0;
for_each_set_bit(bit, mask, nbits) {
if (bit + off >= nbits)
return;
__assign_bit(n++, dst, test_bit(bit + off, src));
}
}

(Not tested, except that on piece of paper.)

If you claim you're replacing bitmap_remap(), you should correctly handle
the above case; when src == dst; when mask is empty, and probably more...

Thanks,
Yury

\
 
 \ /
  Last update: 2023-09-27 18:54    [W:0.107 / U:0.104 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site