Commit 7a283490 authored by Greg Ungerer's avatar Greg Ungerer Committed by Linus Torvalds

[PATCH] m68knommu: add find_next_bit() to bitops.h

A couple of fixups for asm-m68knommu/bitops.h:

. re-order definition of fls(), to be outside __KERNEL__
. add code for find_next_bit()
parent 3fb529dc
......@@ -76,12 +76,6 @@ static inline int __ffs(int x)
return r;
}
/*
* fls: find last bit set.
*/
#define fls(x) generic_fls(x)
/*
* Every architecture must define this function. It's the fastest
* way of searching a 140-bit bitmap where the first 100 bits are
......@@ -283,7 +277,7 @@ static __inline__ int __constant_test_bit(int nr, const volatile unsigned long *
return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
}
static __inline__ int __test_bit(int nr, const unsigned long * addr)
static __inline__ int __test_bit(int nr, const volatile unsigned long * addr)
{
int * a = (int *) addr;
int mask;
......@@ -337,6 +331,48 @@ static __inline__ int find_next_zero_bit (void * addr, int size, int offset)
return result + ffz(tmp);
}
/*
* Find next one bit in a bitmap reasonably efficiently.
*/
static __inline__ unsigned long find_next_bit(const unsigned long *addr,
unsigned long size, unsigned long offset)
{
unsigned int *p = ((unsigned int *) addr) + (offset >> 5);
unsigned int result = offset & ~31UL;
unsigned int tmp;
if (offset >= size)
return size;
size -= result;
offset &= 31UL;
if (offset) {
tmp = *p++;
tmp &= ~0UL << offset;
if (size < 32)
goto found_first;
if (tmp)
goto found_middle;
size -= 32;
result += 32;
}
while (size >= 32) {
if ((tmp = *p++) != 0)
goto found_middle;
result += 32;
size -= 32;
}
if (!size)
return result;
tmp = *p;
found_first:
tmp &= ~0UL >> (32 - size);
if (tmp == 0UL) /* Are any bits set? */
return result + size; /* Nope. */
found_middle:
return result + __ffs(tmp);
}
/*
* hweightN: returns the hamming weight (i.e. the number
* of bits set) of a N-bit word
......@@ -478,4 +514,9 @@ static __inline__ unsigned long ext2_find_next_zero_bit(void *addr, unsigned lon
#endif /* __KERNEL__ */
/*
* fls: find last bit set.
*/
#define fls(x) generic_fls(x)
#endif /* _M68KNOMMU_BITOPS_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment