1 #include <linux/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(const unsigned long *addr, unsigned long size,
12 const unsigned long *p = addr + (offset >> 6);
13 unsigned long result = offset & ~63UL;
22 tmp &= (~0UL << offset);
30 while (size & ~63UL) {
41 tmp &= (~0UL >> (64 - size));
42 if (tmp == 0UL) /* Are any bits set? */
43 return result + size; /* Nope. */
45 return result + __ffs(tmp);
48 /* find_next_zero_bit() finds the first zero bit in a bit string of length
49 * 'size' bits, starting the search at bit 'offset'. This is largely based
50 * on Linus's ALPHA routines, which are pretty portable BTW.
53 unsigned long find_next_zero_bit(const unsigned long *addr,
54 unsigned long size, unsigned long offset)
56 const unsigned long *p = addr + (offset >> 6);
57 unsigned long result = offset & ~63UL;
66 tmp |= ~0UL >> (64-offset);
74 while (size & ~63UL) {
86 if (tmp == ~0UL) /* Are any bits zero? */
87 return result + size; /* Nope. */
89 return result + ffz(tmp);
92 unsigned long find_next_zero_le_bit(unsigned long *addr, unsigned long size, unsigned long offset)
94 unsigned long *p = addr + (offset >> 6);
95 unsigned long result = offset & ~63UL;
103 tmp = __swab64p(p++);
104 tmp |= (~0UL >> (64-offset));
113 if(~(tmp = __swab64p(p++)))
122 tmp |= (~0UL << size);
123 if (tmp == ~0UL) /* Are any bits zero? */
124 return result + size; /* Nope. */
126 return result + ffz(tmp);