1 #ifndef _X86_64_BITOPS_H
2 #define _X86_64_BITOPS_H
5 * Copyright 1992, Linus Torvalds.
8 extern long find_first_zero_bit(const unsigned long *addr
, unsigned long size
);
9 extern long find_next_zero_bit(const unsigned long *addr
, long size
, long offset
);
10 extern long find_first_bit(const unsigned long *addr
, unsigned long size
);
11 extern long find_next_bit(const unsigned long *addr
, long size
, long offset
);
13 /* return index of first bet set in val or max when no bit is set */
14 static inline long __scanbit(unsigned long val
, unsigned long max
)
16 asm("bsfq %1,%0 ; cmovz %2,%0" : "=&r" (val
) : "r" (val
), "r" (max
));
20 #define find_first_bit(addr,size) \
21 ((__builtin_constant_p(size) && (size) <= BITS_PER_LONG ? \
22 (__scanbit(*(unsigned long *)addr,(size))) : \
23 find_first_bit(addr,size)))
25 #define find_next_bit(addr,size,off) \
26 ((__builtin_constant_p(size) && (size) <= BITS_PER_LONG ? \
27 ((off) + (__scanbit((*(unsigned long *)addr) >> (off),(size)-(off)))) : \
28 find_next_bit(addr,size,off)))
30 #define find_first_zero_bit(addr,size) \
31 ((__builtin_constant_p(size) && (size) <= BITS_PER_LONG ? \
32 (__scanbit(~*(unsigned long *)addr,(size))) : \
33 find_first_zero_bit(addr,size)))
35 #define find_next_zero_bit(addr,size,off) \
36 ((__builtin_constant_p(size) && (size) <= BITS_PER_LONG ? \
37 ((off)+(__scanbit(~(((*(unsigned long *)addr)) >> (off)),(size)-(off)))) : \
38 find_next_zero_bit(addr,size,off)))
41 * Find string of zero bits in a bitmap. -1 when not found.
44 find_next_zero_string(unsigned long *bitmap
, long start
, long nbits
, int len
);
46 static inline void set_bit_string(unsigned long *bitmap
, unsigned long i
,
49 unsigned long end
= i
+ len
;
56 static inline void __clear_bit_string(unsigned long *bitmap
, unsigned long i
,
59 unsigned long end
= i
+ len
;
61 __clear_bit(i
, bitmap
);
67 * ffz - find first zero in word.
68 * @word: The word to search
70 * Undefined if no zero exists, so code should check against ~0UL first.
72 static inline unsigned long ffz(unsigned long word
)
81 * __ffs - find first bit in word.
82 * @word: The word to search
84 * Undefined if no bit exists, so code should check against 0 first.
86 static inline unsigned long __ffs(unsigned long word
)
95 * __fls: find last bit set.
96 * @word: The word to search
98 * Undefined if no zero exists, so code should check against ~0UL first.
100 static inline unsigned long __fls(unsigned long word
)
110 #include <asm-generic/bitops/sched.h>
113 * ffs - find first bit set
114 * @x: the word to search
116 * This is defined the same way as
117 * the libc and compiler builtin ffs routines, therefore
118 * differs in spirit from the above ffz (man ffs).
120 static inline int ffs(int x
)
124 __asm__("bsfl %1,%0\n\t"
126 : "=r" (r
) : "rm" (x
), "r" (-1));
131 * fls64 - find last bit set in 64 bit word
132 * @x: the word to search
134 * This is defined the same way as fls.
136 static inline int fls64(__u64 x
)
144 * fls - find last bit set
145 * @x: the word to search
147 * This is defined the same way as ffs.
149 static inline int fls(int x
)
153 __asm__("bsrl %1,%0\n\t"
155 : "=&r" (r
) : "rm" (x
), "rm" (-1));
159 #define ARCH_HAS_FAST_MULTIPLIER 1
161 #include <asm-generic/bitops/hweight.h>
163 #endif /* __KERNEL__ */
167 #include <asm-generic/bitops/ext2-non-atomic.h>
169 #define ext2_set_bit_atomic(lock,nr,addr) \
170 test_and_set_bit((nr),(unsigned long*)addr)
171 #define ext2_clear_bit_atomic(lock,nr,addr) \
172 test_and_clear_bit((nr),(unsigned long*)addr)
174 #include <asm-generic/bitops/minix.h>
176 #endif /* __KERNEL__ */
178 #endif /* _X86_64_BITOPS_H */