We can use find_next_bit, which is assembly on some arches,
to implement xfs_next_bit. Tested on x86.
Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxxx>
Index: linux-2.6.22.i386/fs/xfs/xfs_bit.c
===================================================================
--- linux-2.6.22.i386.orig/fs/xfs/xfs_bit.c
+++ linux-2.6.22.i386/fs/xfs/xfs_bit.c
@@ -192,32 +192,16 @@ found:
*/
int xfs_next_bit(uint *map, uint size, uint start_bit)
{
- uint * p = ((unsigned int *) map) + (start_bit >> BIT_TO_WORD_SHIFT);
- uint result = start_bit & ~(NBWORD - 1);
- uint tmp;
+ int result;
- size <<= BIT_TO_WORD_SHIFT;
+ size <<= BIT_TO_WORD_SHIFT;
+ if (start_bit >= size) /* beyond end of bitmap */
+ return -1;
- if (start_bit >= size)
- return -1;
- size -= result;
- start_bit &= (NBWORD - 1);
- if (start_bit) {
- tmp = *p++;
- /* set to zero first offset bits prior to start */
- tmp &= (~0U << start_bit);
- if (tmp != 0U)
- goto found;
- result += NBWORD;
- size -= NBWORD;
- }
- while (size) {
- if ((tmp = *p++) != 0U)
- goto found;
- result += NBWORD;
- size -= NBWORD;
- }
- return -1;
-found:
- return result + ffs(tmp) - 1;
+ result = find_next_bit((unsigned long *)map, size, start_bit);
+
+ if (result == size) /* no bits set */
+ return -1;
+
+ return result;
}
|