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(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(unsigned long *addr
, unsigned long size
, unsigned long offset
)
55 unsigned long *p
= addr
+ (offset
>> 6);
56 unsigned long result
= offset
& ~63UL;
65 tmp
|= ~0UL >> (64-offset
);
73 while (size
& ~63UL) {
85 if (tmp
== ~0UL) /* Are any bits zero? */
86 return result
+ size
; /* Nope. */
88 return result
+ ffz(tmp
);
91 unsigned long find_next_zero_le_bit(unsigned long *addr
, unsigned long size
, unsigned long offset
)
93 unsigned long *p
= addr
+ (offset
>> 6);
94 unsigned long result
= offset
& ~63UL;
102 tmp
= __swab64p(p
++);
103 tmp
|= (~0UL >> (64-offset
));
112 if(~(tmp
= __swab64p(p
++)))
121 tmp
|= (~0UL << size
);
122 if (tmp
== ~0UL) /* Are any bits zero? */
123 return result
+ size
; /* Nope. */
125 return result
+ ffz(tmp
);