1 #include <linux/bitops.h>
3 #undef find_first_zero_bit
4 #undef find_next_zero_bit
9 * find_first_zero_bit - find the first zero bit in a memory region
10 * @addr: The address to start the search at
11 * @size: The maximum size to search
13 * Returns the bit-number of the first zero bit, not the number of the byte
16 inline long find_first_zero_bit(const unsigned long * addr, unsigned long size)
26 " xorq -8(%%rdi),%%rax\n"
29 "1: subq %[addr],%%rdi\n"
32 :"=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
33 :"0" (0ULL), "1" ((size + 63) >> 6), "2" (addr), "3" (-1ULL),
34 [addr] "r" (addr) : "memory");
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 long find_next_zero_bit (const unsigned long * addr, long size, long offset)
46 unsigned long * p = ((unsigned long *) addr) + (offset >> 6);
47 unsigned long set = 0;
48 unsigned long res, bit = offset&63;
52 * Look for zero in first word
57 : "r" (~(*p >> bit)), "r"(64L));
64 * No zero yet, search remaining full words for a zero
66 res = find_first_zero_bit ((const unsigned long *)p,
67 size - 64 * (p - (unsigned long *) addr));
68 return (offset + set + res);
72 __find_first_bit(const unsigned long * addr, unsigned long size)
81 " bsfq (%%rdi),%%rax\n"
82 "1: subq %[addr],%%rdi\n"
85 :"=a" (res), "=&c" (d0), "=&D" (d1)
87 "1" ((size + 63) >> 6), "2" (addr),
88 [addr] "r" (addr) : "memory");
93 * find_first_bit - find the first set bit in a memory region
94 * @addr: The address to start the search at
95 * @size: The maximum size to search
97 * Returns the bit-number of the first set bit, not the number of the byte
100 long find_first_bit(const unsigned long * addr, unsigned long size)
102 return __find_first_bit(addr,size);
106 * find_next_bit - find the first set bit in a memory region
107 * @addr: The address to base the search on
108 * @offset: The bitnumber to start searching at
109 * @size: The maximum size to search
111 long find_next_bit(const unsigned long * addr, long size, long offset)
113 const unsigned long * p = addr + (offset >> 6);
114 unsigned long set = 0, bit = offset & 63, res;
118 * Look for nonzero in the first 64 bits:
123 : "r" (*p >> bit), "r" (64L));
124 if (set < (64 - bit))
130 * No set bit yet, search remaining full words for a bit
132 res = __find_first_bit (p, size - 64 * (p - addr));
133 return (offset + set + res);
136 #include <linux/module.h>
138 EXPORT_SYMBOL(find_next_bit);
139 EXPORT_SYMBOL(find_first_bit);
140 EXPORT_SYMBOL(find_first_zero_bit);
141 EXPORT_SYMBOL(find_next_zero_bit);