* [PATCH 1/2] Use generic routines for xfs_next_bit
@ 2007-09-28 13:15 Eric Sandeen
0 siblings, 0 replies; only message in thread
From: Eric Sandeen @ 2007-09-28 13:15 UTC (permalink / raw)
To: xfs-oss
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@sandeen.net>
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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-09-28 13:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-28 13:15 [PATCH 1/2] Use generic routines for xfs_next_bit Eric Sandeen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox