5 * Copyright 1992, Linus Torvalds.
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 static inline int find_first_zero_bit(const unsigned long *addr, unsigned size)
23 /* This looks at memory.
24 * Mark it volatile to tell gcc not to move it around
26 asm volatile("movl $-1,%%eax\n\t"
27 "xorl %%edx,%%edx\n\t"
30 "xorl -4(%%edi),%%eax\n\t"
33 "1:\tsubl %%ebx,%%edi\n\t"
36 : "=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
37 : "1" ((size + 31) >> 5), "2" (addr),
38 "b" (addr) : "memory");
43 * find_next_zero_bit - find the first zero bit in a memory region
44 * @addr: The address to base the search on
45 * @offset: The bit number to start searching at
46 * @size: The maximum size to search
48 int find_next_zero_bit(const unsigned long *addr, int size, int offset);
51 * __ffs - find first bit in word.
52 * @word: The word to search
54 * Undefined if no bit exists, so code should check against 0 first.
56 static inline unsigned long __ffs(unsigned long word)
65 * find_first_bit - find the first set bit in a memory region
66 * @addr: The address to start the search at
67 * @size: The maximum size to search
69 * Returns the bit number of the first set bit, not the number of the byte
72 static inline unsigned find_first_bit(const unsigned long *addr, unsigned size)
77 unsigned long val = *addr++;
79 return __ffs(val) + x;
80 x += sizeof(*addr) << 3;
86 * find_next_bit - find the first set bit in a memory region
87 * @addr: The address to base the search on
88 * @offset: The bit number to start searching at
89 * @size: The maximum size to search
91 int find_next_bit(const unsigned long *addr, int size, int offset);
94 * ffz - find first zero in word.
95 * @word: The word to search
97 * Undefined if no zero exists, so code should check against ~0UL first.
99 static inline unsigned long ffz(unsigned long word)
109 #include <asm-generic/bitops/sched.h>
112 * ffs - find first bit set
113 * @x: the word to search
115 * This is defined the same way as
116 * the libc and compiler builtin ffs routines, therefore
117 * differs in spirit from the above ffz() (man ffs).
119 static inline int ffs(int x)
123 __asm__("bsfl %1,%0\n\t"
126 "1:" : "=r" (r) : "rm" (x));
131 * fls - find last bit set
132 * @x: the word to search
134 * This is defined the same way as ffs().
136 static inline int fls(int x)
140 __asm__("bsrl %1,%0\n\t"
143 "1:" : "=r" (r) : "rm" (x));
147 #include <asm-generic/bitops/hweight.h>
149 #endif /* __KERNEL__ */
151 #include <asm-generic/bitops/fls64.h>
155 #include <asm-generic/bitops/ext2-non-atomic.h>
157 #define ext2_set_bit_atomic(lock, nr, addr) \
158 test_and_set_bit((nr), (unsigned long *)(addr))
159 #define ext2_clear_bit_atomic(lock, nr, addr) \
160 test_and_clear_bit((nr), (unsigned long *)(addr))
162 #include <asm-generic/bitops/minix.h>
164 #endif /* __KERNEL__ */
166 #endif /* _I386_BITOPS_H */