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. Mark it volatile to tell gcc not to move it around */
26 "xorl %%edx,%%edx\n\t"
29 "xorl -4(%%edi),%%eax\n\t"
32 "1:\tsubl %%ebx,%%edi\n\t"
35 :"=d" (res
), "=&c" (d0
), "=&D" (d1
), "=&a" (d2
)
36 :"1" ((size
+ 31) >> 5), "2" (addr
), "b" (addr
) : "memory");
41 * find_next_zero_bit - find the first zero bit in a memory region
42 * @addr: The address to base the search on
43 * @offset: The bit number to start searching at
44 * @size: The maximum size to search
46 int find_next_zero_bit(const unsigned long *addr
, int size
, int offset
);
49 * __ffs - find first bit in word.
50 * @word: The word to search
52 * Undefined if no bit exists, so code should check against 0 first.
54 static inline unsigned long __ffs(unsigned long word
)
63 * find_first_bit - find the first set bit in a memory region
64 * @addr: The address to start the search at
65 * @size: The maximum size to search
67 * Returns the bit number of the first set bit, not the number of the byte
70 static inline unsigned find_first_bit(const unsigned long *addr
, unsigned size
)
75 unsigned long val
= *addr
++;
77 return __ffs(val
) + x
;
78 x
+= (sizeof(*addr
)<<3);
84 * find_next_bit - find the first set bit in a memory region
85 * @addr: The address to base the search on
86 * @offset: The bit number to start searching at
87 * @size: The maximum size to search
89 int find_next_bit(const unsigned long *addr
, int size
, int offset
);
92 * ffz - find first zero in word.
93 * @word: The word to search
95 * Undefined if no zero exists, so code should check against ~0UL first.
97 static inline unsigned long ffz(unsigned long word
)
107 #include <asm-generic/bitops/sched.h>
110 * ffs - find first bit set
111 * @x: the word to search
113 * This is defined the same way as
114 * the libc and compiler builtin ffs routines, therefore
115 * differs in spirit from the above ffz() (man ffs).
117 static inline int ffs(int x
)
121 __asm__("bsfl %1,%0\n\t"
124 "1:" : "=r" (r
) : "rm" (x
));
129 * fls - find last bit set
130 * @x: the word to search
132 * This is defined the same way as ffs().
134 static inline int fls(int x
)
138 __asm__("bsrl %1,%0\n\t"
141 "1:" : "=r" (r
) : "rm" (x
));
145 #include <asm-generic/bitops/hweight.h>
147 #endif /* __KERNEL__ */
149 #include <asm-generic/bitops/fls64.h>
153 #include <asm-generic/bitops/ext2-non-atomic.h>
155 #define ext2_set_bit_atomic(lock, nr, addr) \
156 test_and_set_bit((nr), (unsigned long *)addr)
157 #define ext2_clear_bit_atomic(lock, nr, addr) \
158 test_and_clear_bit((nr), (unsigned long *)addr)
160 #include <asm-generic/bitops/minix.h>
162 #endif /* __KERNEL__ */
164 #endif /* _I386_BITOPS_H */