1 #include <linux/module.h>
2 #include <asm/bitops.h>
4 #undef find_first_zero_bit
5 #undef find_next_zero_bit
10 * find_first_zero_bit - find the first zero bit in a memory region
11 * @addr: The address to start the search at
12 * @size: The maximum size to search
14 * Returns the bit-number of the first zero bit, not the number of the byte
17 inline long find_first_zero_bit(const unsigned long * addr
, unsigned long size
)
27 " xorq -8(%%rdi),%%rax\n"
30 "1: subq %[addr],%%rdi\n"
33 :"=d" (res
), "=&c" (d0
), "=&D" (d1
), "=&a" (d2
)
34 :"0" (0ULL), "1" ((size
+ 63) >> 6), "2" (addr
), "3" (-1ULL),
35 [addr
] "r" (addr
) : "memory");
40 * find_next_zero_bit - find the first zero bit in a memory region
41 * @addr: The address to base the search on
42 * @offset: The bitnumber to start searching at
43 * @size: The maximum size to search
45 long find_next_zero_bit (const unsigned long * addr
, long size
, long offset
)
47 unsigned long * p
= ((unsigned long *) addr
) + (offset
>> 6);
48 unsigned long set
= 0;
49 unsigned long res
, bit
= offset
&63;
53 * Look for zero in first word
58 : "r" (~(*p
>> bit
)), "r"(64L));
65 * No zero yet, search remaining full words for a zero
67 res
= find_first_zero_bit ((const unsigned long *)p
,
68 size
- 64 * (p
- (unsigned long *) addr
));
69 return (offset
+ set
+ res
);
73 __find_first_bit(const unsigned long * addr
, unsigned long size
)
82 " bsfq (%%rdi),%%rax\n"
83 "1: subq %[addr],%%rdi\n"
86 :"=a" (res
), "=&c" (d0
), "=&D" (d1
)
88 "1" ((size
+ 63) >> 6), "2" (addr
),
89 [addr
] "r" (addr
) : "memory");
94 * find_first_bit - find the first set bit in a memory region
95 * @addr: The address to start the search at
96 * @size: The maximum size to search
98 * Returns the bit-number of the first set bit, not the number of the byte
101 long find_first_bit(const unsigned long * addr
, unsigned long size
)
103 return __find_first_bit(addr
,size
);
107 * find_next_bit - find the first set bit in a memory region
108 * @addr: The address to base the search on
109 * @offset: The bitnumber to start searching at
110 * @size: The maximum size to search
112 long find_next_bit(const unsigned long * addr
, long size
, long offset
)
114 const unsigned long * p
= addr
+ (offset
>> 6);
115 unsigned long set
= 0, bit
= offset
& 63, res
;
119 * Look for nonzero in the first 64 bits:
124 : "r" (*p
>> bit
), "r" (64L));
125 if (set
< (64 - bit
))
131 * No set bit yet, search remaining full words for a bit
133 res
= __find_first_bit (p
, size
- 64 * (p
- addr
));
134 return (offset
+ set
+ res
);
137 EXPORT_SYMBOL(find_next_bit
);
138 EXPORT_SYMBOL(find_first_bit
);
139 EXPORT_SYMBOL(find_first_zero_bit
);
140 EXPORT_SYMBOL(find_next_zero_bit
);