diff options
Diffstat (limited to 'fs/xfs/xfs_bit.c')
-rw-r--r-- | fs/xfs/xfs_bit.c | 91 |
1 files changed, 9 insertions, 82 deletions
diff --git a/fs/xfs/xfs_bit.c b/fs/xfs/xfs_bit.c index 1afe07f67e3b..fab0b6d5a41b 100644 --- a/fs/xfs/xfs_bit.c +++ b/fs/xfs/xfs_bit.c | |||
@@ -66,44 +66,6 @@ static const char xfs_highbit[256] = { | |||
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | /* | 68 | /* |
69 | * Count of bits set in byte, 0..8. | ||
70 | */ | ||
71 | static const char xfs_countbit[256] = { | ||
72 | 0, 1, 1, 2, 1, 2, 2, 3, /* 00 .. 07 */ | ||
73 | 1, 2, 2, 3, 2, 3, 3, 4, /* 08 .. 0f */ | ||
74 | 1, 2, 2, 3, 2, 3, 3, 4, /* 10 .. 17 */ | ||
75 | 2, 3, 3, 4, 3, 4, 4, 5, /* 18 .. 1f */ | ||
76 | 1, 2, 2, 3, 2, 3, 3, 4, /* 20 .. 27 */ | ||
77 | 2, 3, 3, 4, 3, 4, 4, 5, /* 28 .. 2f */ | ||
78 | 2, 3, 3, 4, 3, 4, 4, 5, /* 30 .. 37 */ | ||
79 | 3, 4, 4, 5, 4, 5, 5, 6, /* 38 .. 3f */ | ||
80 | 1, 2, 2, 3, 2, 3, 3, 4, /* 40 .. 47 */ | ||
81 | 2, 3, 3, 4, 3, 4, 4, 5, /* 48 .. 4f */ | ||
82 | 2, 3, 3, 4, 3, 4, 4, 5, /* 50 .. 57 */ | ||
83 | 3, 4, 4, 5, 4, 5, 5, 6, /* 58 .. 5f */ | ||
84 | 2, 3, 3, 4, 3, 4, 4, 5, /* 60 .. 67 */ | ||
85 | 3, 4, 4, 5, 4, 5, 5, 6, /* 68 .. 6f */ | ||
86 | 3, 4, 4, 5, 4, 5, 5, 6, /* 70 .. 77 */ | ||
87 | 4, 5, 5, 6, 5, 6, 6, 7, /* 78 .. 7f */ | ||
88 | 1, 2, 2, 3, 2, 3, 3, 4, /* 80 .. 87 */ | ||
89 | 2, 3, 3, 4, 3, 4, 4, 5, /* 88 .. 8f */ | ||
90 | 2, 3, 3, 4, 3, 4, 4, 5, /* 90 .. 97 */ | ||
91 | 3, 4, 4, 5, 4, 5, 5, 6, /* 98 .. 9f */ | ||
92 | 2, 3, 3, 4, 3, 4, 4, 5, /* a0 .. a7 */ | ||
93 | 3, 4, 4, 5, 4, 5, 5, 6, /* a8 .. af */ | ||
94 | 3, 4, 4, 5, 4, 5, 5, 6, /* b0 .. b7 */ | ||
95 | 4, 5, 5, 6, 5, 6, 6, 7, /* b8 .. bf */ | ||
96 | 2, 3, 3, 4, 3, 4, 4, 5, /* c0 .. c7 */ | ||
97 | 3, 4, 4, 5, 4, 5, 5, 6, /* c8 .. cf */ | ||
98 | 3, 4, 4, 5, 4, 5, 5, 6, /* d0 .. d7 */ | ||
99 | 4, 5, 5, 6, 5, 6, 6, 7, /* d8 .. df */ | ||
100 | 3, 4, 4, 5, 4, 5, 5, 6, /* e0 .. e7 */ | ||
101 | 4, 5, 5, 6, 5, 6, 6, 7, /* e8 .. ef */ | ||
102 | 4, 5, 5, 6, 5, 6, 6, 7, /* f0 .. f7 */ | ||
103 | 5, 6, 6, 7, 6, 7, 7, 8, /* f8 .. ff */ | ||
104 | }; | ||
105 | |||
106 | /* | ||
107 | * xfs_highbit32: get high bit set out of 32-bit argument, -1 if none set. | 69 | * xfs_highbit32: get high bit set out of 32-bit argument, -1 if none set. |
108 | */ | 70 | */ |
109 | inline int | 71 | inline int |
@@ -167,56 +129,21 @@ xfs_highbit64( | |||
167 | 129 | ||
168 | 130 | ||
169 | /* | 131 | /* |
170 | * Count the number of bits set in the bitmap starting with bit | 132 | * Return whether bitmap is empty. |
171 | * start_bit. Size is the size of the bitmap in words. | 133 | * Size is number of words in the bitmap, which is padded to word boundary |
172 | * | 134 | * Returns 1 for empty, 0 for non-empty. |
173 | * Do the counting by mapping a byte value to the number of set | ||
174 | * bits for that value using the xfs_countbit array, i.e. | ||
175 | * xfs_countbit[0] == 0, xfs_countbit[1] == 1, xfs_countbit[2] == 1, | ||
176 | * xfs_countbit[3] == 2, etc. | ||
177 | */ | 135 | */ |
178 | int | 136 | int |
179 | xfs_count_bits(uint *map, uint size, uint start_bit) | 137 | xfs_bitmap_empty(uint *map, uint size) |
180 | { | 138 | { |
181 | register int bits; | 139 | uint i; |
182 | register unsigned char *bytep; | 140 | uint ret = 0; |
183 | register unsigned char *end_map; | ||
184 | int byte_bit; | ||
185 | |||
186 | bits = 0; | ||
187 | end_map = (char*)(map + size); | ||
188 | bytep = (char*)(map + (start_bit & ~0x7)); | ||
189 | byte_bit = start_bit & 0x7; | ||
190 | |||
191 | /* | ||
192 | * If the caller fell off the end of the map, return 0. | ||
193 | */ | ||
194 | if (bytep >= end_map) { | ||
195 | return (0); | ||
196 | } | ||
197 | |||
198 | /* | ||
199 | * If start_bit is not byte aligned, then process the | ||
200 | * first byte separately. | ||
201 | */ | ||
202 | if (byte_bit != 0) { | ||
203 | /* | ||
204 | * Shift off the bits we don't want to look at, | ||
205 | * before indexing into xfs_countbit. | ||
206 | */ | ||
207 | bits += xfs_countbit[(*bytep >> byte_bit)]; | ||
208 | bytep++; | ||
209 | } | ||
210 | 141 | ||
211 | /* | 142 | for (i = 0; i < size; i++) { |
212 | * Count the bits in each byte until the end of the bitmap. | 143 | ret |= map[i]; |
213 | */ | ||
214 | while (bytep < end_map) { | ||
215 | bits += xfs_countbit[*bytep]; | ||
216 | bytep++; | ||
217 | } | 144 | } |
218 | 145 | ||
219 | return (bits); | 146 | return (ret == 0); |
220 | } | 147 | } |
221 | 148 | ||
222 | /* | 149 | /* |