diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2011-08-26 22:38:50 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2011-11-19 11:13:28 -0500 |
commit | f1fd306a91f875e65af0e04855b23adda6831ac9 (patch) | |
tree | 3b3c733133f76ff212f81c9b71ea977169cb4fee /fs/minix | |
parent | 016e8d44bc06dd3322f26712bdd3f3a6973592d0 (diff) |
minixfs: kill manual hweight(), simplify
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/minix')
-rw-r--r-- | fs/minix/bitmap.c | 41 | ||||
-rw-r--r-- | fs/minix/minix.h | 2 |
2 files changed, 15 insertions, 28 deletions
diff --git a/fs/minix/bitmap.c b/fs/minix/bitmap.c index 7c82c29429d7..ef175cb8cfd8 100644 --- a/fs/minix/bitmap.c +++ b/fs/minix/bitmap.c | |||
@@ -16,39 +16,26 @@ | |||
16 | #include <linux/bitops.h> | 16 | #include <linux/bitops.h> |
17 | #include <linux/sched.h> | 17 | #include <linux/sched.h> |
18 | 18 | ||
19 | static const int nibblemap[] = { 4,3,3,2,3,2,2,1,3,2,2,1,2,1,1,0 }; | ||
20 | |||
21 | static DEFINE_SPINLOCK(bitmap_lock); | 19 | static DEFINE_SPINLOCK(bitmap_lock); |
22 | 20 | ||
23 | static unsigned long count_free(struct buffer_head *map[], unsigned blocksize, __u32 numbits) | 21 | /* |
22 | * bitmap consists of blocks filled with 16bit words | ||
23 | * bit set == busy, bit clear == free | ||
24 | * endianness is a mess, but for counting zero bits it really doesn't matter... | ||
25 | */ | ||
26 | static __u32 count_free(struct buffer_head *map[], unsigned blocksize, __u32 numbits) | ||
24 | { | 27 | { |
25 | unsigned i, j, sum = 0; | 28 | __u32 sum = 0; |
26 | struct buffer_head *bh; | 29 | unsigned blocks = DIV_ROUND_UP(numbits, blocksize * 8); |
27 | unsigned numblocks = minix_blocks_needed(numbits, blocksize); | ||
28 | |||
29 | for (i=0; i<numblocks-1; i++) { | ||
30 | if (!(bh=map[i])) | ||
31 | return(0); | ||
32 | for (j=0; j<bh->b_size; j++) | ||
33 | sum += nibblemap[bh->b_data[j] & 0xf] | ||
34 | + nibblemap[(bh->b_data[j]>>4) & 0xf]; | ||
35 | } | ||
36 | 30 | ||
37 | if (numblocks==0 || !(bh=map[numblocks-1])) | 31 | while (blocks--) { |
38 | return(0); | 32 | unsigned words = blocksize / 2; |
39 | i = ((numbits - (numblocks-1) * bh->b_size * 8) / 16) * 2; | 33 | __u16 *p = (__u16 *)(*map++)->b_data; |
40 | for (j=0; j<i; j++) { | 34 | while (words--) |
41 | sum += nibblemap[bh->b_data[j] & 0xf] | 35 | sum += 16 - hweight16(*p++); |
42 | + nibblemap[(bh->b_data[j]>>4) & 0xf]; | ||
43 | } | 36 | } |
44 | 37 | ||
45 | i = numbits%16; | 38 | return sum; |
46 | if (i!=0) { | ||
47 | i = *(__u16 *)(&bh->b_data[j]) | ~((1<<i) - 1); | ||
48 | sum += nibblemap[i & 0xf] + nibblemap[(i>>4) & 0xf]; | ||
49 | sum += nibblemap[(i>>8) & 0xf] + nibblemap[(i>>12) & 0xf]; | ||
50 | } | ||
51 | return(sum); | ||
52 | } | 39 | } |
53 | 40 | ||
54 | void minix_free_block(struct inode *inode, unsigned long block) | 41 | void minix_free_block(struct inode *inode, unsigned long block) |
diff --git a/fs/minix/minix.h b/fs/minix/minix.h index 6415fe0d2385..26bbd55e82ea 100644 --- a/fs/minix/minix.h +++ b/fs/minix/minix.h | |||
@@ -130,7 +130,7 @@ static inline int minix_find_first_zero_bit(const void *vaddr, unsigned size) | |||
130 | if (!size) | 130 | if (!size) |
131 | return 0; | 131 | return 0; |
132 | 132 | ||
133 | size = (size >> 4) + ((size & 15) > 0); | 133 | size >>= 4; |
134 | while (*p++ == 0xffff) { | 134 | while (*p++ == 0xffff) { |
135 | if (--size == 0) | 135 | if (--size == 0) |
136 | return (p - addr) << 4; | 136 | return (p - addr) << 4; |