Re: [PATCH] hpfs: Use hweight32

From: Mikulas Patocka
Date: Sun Nov 15 2009 - 02:16:41 EST




On Fri, 13 Nov 2009, Andrew Morton wrote:

> On Fri, 13 Nov 2009 16:07:08 +0900
> Akinobu Mita <akinobu.mita@xxxxxxxxx> wrote:
>
> > Use hweight32 instead of counting for each bit
> >
> > Signed-off-by: Akinobu Mita <akinobu.mita@xxxxxxxxx>
> > Cc: Mikulas Patocka <mikulas@xxxxxxxxxxxxxxxxxxxxxxxx>
> > Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
> > ---
> > fs/hpfs/super.c | 7 ++-----
> > 1 files changed, 2 insertions(+), 5 deletions(-)
> >
> > diff --git a/fs/hpfs/super.c b/fs/hpfs/super.c
> > index f2feaa0..cf6fe4a 100644
> > --- a/fs/hpfs/super.c
> > +++ b/fs/hpfs/super.c
> > @@ -119,11 +119,8 @@ unsigned hpfs_count_one_bitmap(struct super_block *s, secno secno)
> > unsigned i, count;
> > if (!(bits = hpfs_map_4sectors(s, secno, &qbh, 4))) return 0;
> > count = 0;
> > - for (i = 0; i < 2048 / sizeof(unsigned); i++) {
> > - unsigned b;
> > - if (!bits[i]) continue;
> > - for (b = bits[i]; b; b>>=1) count += b & 1;
> > - }
> > + for (i = 0; i < 2048 / sizeof(unsigned); i++)
> > + count += hweight32(bits[i]);
> > hpfs_brelse4(&qbh);
> > return count;
>
> Could actualy use bitmap_weight() here.
>
> It's a bit naughty, because bitmap_weight() operates on long*'s, but it
> will work OK.
>
> Shrug.

... and add support for popcnt, so that it's optimized on AMD CPUs.

Mikulas
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/