1 #ifndef CONFIG_GENERIC_FIND_FIRST_BIT
2 #include <linux/bitops.h>
4 #undef find_first_zero_bit
8 __find_first_zero_bit(const unsigned long * addr, unsigned long size)
14 * We must test the size in words, not in bits, because
15 * otherwise incoming sizes in the range -63..-1 will not run
16 * any scasq instructions, and then the flags used by the je
17 * instruction will have whatever random value was in place
18 * before. Nobody should call us like that, but
19 * find_next_zero_bit() does when offset and size are at the
20 * same word and it fails to find a zero itself.
29 " xorq -8(%%rdi),%%rax\n"
32 "1: subq %[addr],%%rdi\n"
35 :"=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
36 :"0" (0ULL), "1" (size), "2" (addr), "3" (-1ULL),
37 [addr] "S" (addr) : "memory");
39 * Any register would do for [addr] above, but GCC tends to
40 * prefer rbx over rsi, even though rsi is readily available
41 * and doesn't have to be saved.
47 * find_first_zero_bit - find the first zero bit in a memory region
48 * @addr: The address to start the search at
49 * @size: The maximum size to search
51 * Returns the bit-number of the first zero bit, not the number of the byte
54 long find_first_zero_bit(const unsigned long * addr, unsigned long size)
56 return __find_first_zero_bit (addr, size);
60 __find_first_bit(const unsigned long * addr, unsigned long size)
66 * We must test the size in words, not in bits, because
67 * otherwise incoming sizes in the range -63..-1 will not run
68 * any scasq instructions, and then the flags used by the jz
69 * instruction will have whatever random value was in place
70 * before. Nobody should call us like that, but
71 * find_next_bit() does when offset and size are at the same
72 * word and it fails to find a one itself.
82 " bsfq (%%rdi),%%rax\n"
83 "1: subq %[addr],%%rdi\n"
86 :"=a" (res), "=&c" (d0), "=&D" (d1)
87 :"0" (0ULL), "1" (size), "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);
105 #include <linux/module.h>
107 EXPORT_SYMBOL(find_first_bit);
108 EXPORT_SYMBOL(find_first_zero_bit);