Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _X86_64_BITOPS_H |
2 | #define _X86_64_BITOPS_H | |
3 | ||
4 | /* | |
5 | * Copyright 1992, Linus Torvalds. | |
6 | */ | |
7 | ||
ade8c56c | 8 | extern long find_first_zero_bit(const unsigned long *addr, unsigned long size); |
ade8c56c | 9 | extern long find_first_bit(const unsigned long *addr, unsigned long size); |
1da177e4 LT |
10 | |
11 | /* return index of first bet set in val or max when no bit is set */ | |
d2ccc3fd | 12 | static inline long __scanbit(unsigned long val, unsigned long max) |
1da177e4 LT |
13 | { |
14 | asm("bsfq %1,%0 ; cmovz %2,%0" : "=&r" (val) : "r" (val), "r" (max)); | |
15 | return val; | |
16 | } | |
17 | ||
1da177e4 LT |
18 | #define find_next_bit(addr,size,off) \ |
19 | ((__builtin_constant_p(size) && (size) <= BITS_PER_LONG ? \ | |
20 | ((off) + (__scanbit((*(unsigned long *)addr) >> (off),(size)-(off)))) : \ | |
21 | find_next_bit(addr,size,off))) | |
22 | ||
1da177e4 LT |
23 | #define find_next_zero_bit(addr,size,off) \ |
24 | ((__builtin_constant_p(size) && (size) <= BITS_PER_LONG ? \ | |
25 | ((off)+(__scanbit(~(((*(unsigned long *)addr)) >> (off)),(size)-(off)))) : \ | |
26 | find_next_zero_bit(addr,size,off))) | |
27 | ||
49f74946 JP |
28 | #define find_first_bit(addr, size) \ |
29 | ((__builtin_constant_p((size)) && (size) <= BITS_PER_LONG \ | |
30 | ? (__scanbit(*(unsigned long *)(addr), (size))) \ | |
31 | : find_first_bit((addr), (size)))) | |
32 | ||
33 | #define find_first_zero_bit(addr, size) \ | |
34 | ((__builtin_constant_p((size)) && (size) <= BITS_PER_LONG \ | |
35 | ? (__scanbit(~*(unsigned long *)(addr), (size))) \ | |
36 | : find_first_zero_bit((addr), (size)))) | |
37 | ||
38 | static inline void set_bit_string(unsigned long *bitmap, unsigned long i, | |
39 | int len) | |
40 | { | |
41 | unsigned long end = i + len; | |
1da177e4 | 42 | while (i < end) { |
49f74946 | 43 | __set_bit(i, bitmap); |
1da177e4 LT |
44 | i++; |
45 | } | |
49f74946 | 46 | } |
1da177e4 | 47 | |
1da177e4 LT |
48 | /** |
49 | * ffz - find first zero in word. | |
50 | * @word: The word to search | |
51 | * | |
52 | * Undefined if no zero exists, so code should check against ~0UL first. | |
53 | */ | |
ade8c56c | 54 | static inline unsigned long ffz(unsigned long word) |
1da177e4 LT |
55 | { |
56 | __asm__("bsfq %1,%0" | |
57 | :"=r" (word) | |
58 | :"r" (~word)); | |
59 | return word; | |
60 | } | |
61 | ||
62 | /** | |
63 | * __ffs - find first bit in word. | |
64 | * @word: The word to search | |
65 | * | |
66 | * Undefined if no bit exists, so code should check against 0 first. | |
67 | */ | |
ade8c56c | 68 | static inline unsigned long __ffs(unsigned long word) |
1da177e4 LT |
69 | { |
70 | __asm__("bsfq %1,%0" | |
71 | :"=r" (word) | |
72 | :"rm" (word)); | |
73 | return word; | |
74 | } | |
75 | ||
90933fc8 SH |
76 | /* |
77 | * __fls: find last bit set. | |
78 | * @word: The word to search | |
79 | * | |
80 | * Undefined if no zero exists, so code should check against ~0UL first. | |
81 | */ | |
ade8c56c | 82 | static inline unsigned long __fls(unsigned long word) |
90933fc8 SH |
83 | { |
84 | __asm__("bsrq %1,%0" | |
85 | :"=r" (word) | |
86 | :"rm" (word)); | |
87 | return word; | |
88 | } | |
89 | ||
1da177e4 LT |
90 | #ifdef __KERNEL__ |
91 | ||
f33e2fba | 92 | #include <asm-generic/bitops/sched.h> |
1da177e4 LT |
93 | |
94 | /** | |
95 | * ffs - find first bit set | |
96 | * @x: the word to search | |
97 | * | |
98 | * This is defined the same way as | |
99 | * the libc and compiler builtin ffs routines, therefore | |
100 | * differs in spirit from the above ffz (man ffs). | |
101 | */ | |
ade8c56c | 102 | static inline int ffs(int x) |
1da177e4 LT |
103 | { |
104 | int r; | |
105 | ||
106 | __asm__("bsfl %1,%0\n\t" | |
107 | "cmovzl %2,%0" | |
108 | : "=r" (r) : "rm" (x), "r" (-1)); | |
109 | return r+1; | |
110 | } | |
111 | ||
90933fc8 SH |
112 | /** |
113 | * fls64 - find last bit set in 64 bit word | |
114 | * @x: the word to search | |
115 | * | |
116 | * This is defined the same way as fls. | |
117 | */ | |
ade8c56c | 118 | static inline int fls64(__u64 x) |
90933fc8 SH |
119 | { |
120 | if (x == 0) | |
121 | return 0; | |
122 | return __fls(x) + 1; | |
123 | } | |
124 | ||
636dd2b7 SH |
125 | /** |
126 | * fls - find last bit set | |
127 | * @x: the word to search | |
128 | * | |
129 | * This is defined the same way as ffs. | |
130 | */ | |
ade8c56c | 131 | static inline int fls(int x) |
636dd2b7 SH |
132 | { |
133 | int r; | |
134 | ||
135 | __asm__("bsrl %1,%0\n\t" | |
136 | "cmovzl %2,%0" | |
137 | : "=&r" (r) : "rm" (x), "rm" (-1)); | |
138 | return r+1; | |
139 | } | |
140 | ||
0136611c AK |
141 | #define ARCH_HAS_FAST_MULTIPLIER 1 |
142 | ||
f33e2fba | 143 | #include <asm-generic/bitops/hweight.h> |
1da177e4 LT |
144 | |
145 | #endif /* __KERNEL__ */ | |
146 | ||
147 | #ifdef __KERNEL__ | |
148 | ||
f33e2fba AM |
149 | #include <asm-generic/bitops/ext2-non-atomic.h> |
150 | ||
49f74946 JP |
151 | #define ext2_set_bit_atomic(lock, nr, addr) \ |
152 | test_and_set_bit((nr), (unsigned long *)(addr)) | |
153 | #define ext2_clear_bit_atomic(lock, nr, addr) \ | |
154 | test_and_clear_bit((nr), (unsigned long *)(addr)) | |
f33e2fba AM |
155 | |
156 | #include <asm-generic/bitops/minix.h> | |
1da177e4 | 157 | |
1da177e4 LT |
158 | #endif /* __KERNEL__ */ |
159 | ||
160 | #endif /* _X86_64_BITOPS_H */ |