Skip to contentSkip to conversation

hpfs: Use hweight32

PATCH In review Akinobu Mita 3 participants 3 messages Nov 13, 2009 – Nov 15, 2009 Hpfs filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hpfs: Use hweight32

Use hweight32 instead of counting for each bit

Cc Mikulas Patocka <[email protected]>
Cc Al Viro <[email protected]>
---
 fs/hpfs/super.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
fs/hpfs/super.c +2 -5
index f2feaa0..cf6fe4a 100644
@@ -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;
 }
Signature · 1 line
1.6.5.1
#1 lore raw
Quoted 16 lines · On Fri, 13 Nov 2009 16:07:08 +0900 Akinobu Mita <[email protected]> wrote:

Use hweight32 instead of counting for each bit

Cc Mikulas Patocka <[email protected]>
Cc Al Viro <[email protected]>
---
 fs/hpfs/super.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
fs/hpfs/super.c +0 -0
index f2feaa0..cf6fe4a 100644
@@ -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;

fs/hpfs/super.c unsigned hpfs_count_one_bitmap(struct super_block *s, secno secno) · line 125

Quoted 10 lines
fs/hpfs/super.c +2 -5
 	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.

maintainer
#2 lore raw
Quoted 32 lines · Andrew Morton
Quoted 16 lines · On Fri, 13 Nov 2009 16:07:08 +0900 Akinobu Mita <[email protected]> wrote:

Use hweight32 instead of counting for each bit

Cc Mikulas Patocka <[email protected]>
Cc Al Viro <[email protected]>
---
 fs/hpfs/super.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
fs/hpfs/super.c +0 -0
index f2feaa0..cf6fe4a 100644
@@ -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;

fs/hpfs/super.c unsigned hpfs_count_one_bitmap(struct super_block *s, secno secno) · line 125

Quoted 10 lines
fs/hpfs/super.c +2 -5
 	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.

Quoted 4 lines

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