1 #include <asm/bitops.h>
4 * find_next_bit - find the next set bit in a memory region
5 * @addr: The address to base the search on
6 * @offset: The bitnumber to start searching at
7 * @size: The maximum size to search
9 unsigned long find_next_bit(unsigned long *addr, unsigned long size, unsigned long offset)
11 unsigned long *p = addr + (offset >> 6);
12 unsigned long result = offset & ~63UL;
21 tmp &= (~0UL << offset);
29 while (size & ~63UL) {
40 tmp &= (~0UL >> (64 - size));
41 if (tmp == 0UL) /* Are any bits set? */
42 return result + size; /* Nope. */
44 return result + __ffs(tmp);
47 /* find_next_zero_bit() finds the first zero bit in a bit string of length
48 * 'size' bits, starting the search at bit 'offset'. This is largely based
49 * on Linus's ALPHA routines, which are pretty portable BTW.
52 unsigned long find_next_zero_bit(unsigned long *addr, unsigned long size, unsigned long offset)
54 unsigned long *p = addr + (offset >> 6);
55 unsigned long result = offset & ~63UL;
64 tmp |= ~0UL >> (64-offset);
72 while (size & ~63UL) {
84 if (tmp == ~0UL) /* Are any bits zero? */
85 return result + size; /* Nope. */
87 return result + ffz(tmp);
90 unsigned long find_next_zero_le_bit(unsigned long *addr, unsigned long size, unsigned long offset)
92 unsigned long *p = addr + (offset >> 6);
93 unsigned long result = offset & ~63UL;
101 tmp = __swab64p(p++);
102 tmp |= (~0UL >> (64-offset));
111 if(~(tmp = __swab64p(p++)))
120 tmp |= (~0UL << size);
121 if (tmp == ~0UL) /* Are any bits zero? */
122 return result + size; /* Nope. */
124 return result + ffz(tmp);