1 #include <linux/bitops.h>
2 #include <linux/module.h>
5 * find_next_bit - find the first set bit in a memory region
6 * @addr: The address to base the search on
7 * @offset: The bitnumber to start searching at
8 * @size: The maximum size to search
10 int find_next_bit(const unsigned long *addr
, int size
, int offset
)
12 const unsigned long *p
= addr
+ (offset
>> 5);
13 int set
= 0, bit
= offset
& 31, res
;
17 * Look for nonzero in the first 32 bits:
19 __asm__("bsfl %1,%0\n\t"
31 * No set bit yet, search remaining full words for a bit
33 res
= find_first_bit (p
, size
- 32 * (p
- addr
));
34 return (offset
+ set
+ res
);
36 EXPORT_SYMBOL(find_next_bit
);
39 * find_next_zero_bit - find the first zero bit in a memory region
40 * @addr: The address to base the search on
41 * @offset: The bitnumber to start searching at
42 * @size: The maximum size to search
44 int find_next_zero_bit(const unsigned long *addr
, int size
, int offset
)
46 unsigned long * p
= ((unsigned long *) addr
) + (offset
>> 5);
47 int set
= 0, bit
= offset
& 31, res
;
51 * Look for zero in the first 32 bits.
53 __asm__("bsfl %1,%0\n\t"
58 : "r" (~(*p
>> bit
)));
65 * No zero yet, search remaining full bytes for a zero
67 res
= find_first_zero_bit (p
, size
- 32 * (p
- (unsigned long *) addr
));
68 return (offset
+ set
+ res
);
70 EXPORT_SYMBOL(find_next_zero_bit
);