diff options
Diffstat (limited to 'include/asm-frv/bitops.h')
-rw-r--r-- | include/asm-frv/bitops.h | 96 |
1 files changed, 89 insertions, 7 deletions
diff --git a/include/asm-frv/bitops.h b/include/asm-frv/bitops.h index 980ae1b0cd28..1f70d47148bd 100644 --- a/include/asm-frv/bitops.h +++ b/include/asm-frv/bitops.h | |||
@@ -157,23 +157,105 @@ static inline int __test_bit(int nr, const volatile void * addr) | |||
157 | __constant_test_bit((nr),(addr)) : \ | 157 | __constant_test_bit((nr),(addr)) : \ |
158 | __test_bit((nr),(addr))) | 158 | __test_bit((nr),(addr))) |
159 | 159 | ||
160 | #include <asm-generic/bitops/ffs.h> | ||
161 | #include <asm-generic/bitops/__ffs.h> | ||
162 | #include <asm-generic/bitops/find.h> | 160 | #include <asm-generic/bitops/find.h> |
163 | 161 | ||
164 | /* | 162 | /** |
165 | * fls: find last bit set. | 163 | * fls - find last bit set |
164 | * @x: the word to search | ||
165 | * | ||
166 | * This is defined the same way as ffs: | ||
167 | * - return 32..1 to indicate bit 31..0 most significant bit set | ||
168 | * - return 0 to indicate no bits set | ||
166 | */ | 169 | */ |
167 | #define fls(x) \ | 170 | #define fls(x) \ |
168 | ({ \ | 171 | ({ \ |
169 | int bit; \ | 172 | int bit; \ |
170 | \ | 173 | \ |
171 | asm("scan %1,gr0,%0" : "=r"(bit) : "r"(x)); \ | 174 | asm(" subcc %1,gr0,gr0,icc0 \n" \ |
175 | " ckne icc0,cc4 \n" \ | ||
176 | " cscan.p %1,gr0,%0 ,cc4,#1 \n" \ | ||
177 | " csub %0,%0,%0 ,cc4,#0 \n" \ | ||
178 | " csub %2,%0,%0 ,cc4,#1 \n" \ | ||
179 | : "=&r"(bit) \ | ||
180 | : "r"(x), "r"(32) \ | ||
181 | : "icc0", "cc4" \ | ||
182 | ); \ | ||
172 | \ | 183 | \ |
173 | bit ? 33 - bit : bit; \ | 184 | bit; \ |
174 | }) | 185 | }) |
175 | 186 | ||
176 | #include <asm-generic/bitops/fls64.h> | 187 | /** |
188 | * fls64 - find last bit set in a 64-bit value | ||
189 | * @n: the value to search | ||
190 | * | ||
191 | * This is defined the same way as ffs: | ||
192 | * - return 64..1 to indicate bit 63..0 most significant bit set | ||
193 | * - return 0 to indicate no bits set | ||
194 | */ | ||
195 | static inline __attribute__((const)) | ||
196 | int fls64(u64 n) | ||
197 | { | ||
198 | union { | ||
199 | u64 ll; | ||
200 | struct { u32 h, l; }; | ||
201 | } _; | ||
202 | int bit, x, y; | ||
203 | |||
204 | _.ll = n; | ||
205 | |||
206 | asm(" subcc.p %3,gr0,gr0,icc0 \n" | ||
207 | " subcc %4,gr0,gr0,icc1 \n" | ||
208 | " ckne icc0,cc4 \n" | ||
209 | " ckne icc1,cc5 \n" | ||
210 | " norcr cc4,cc5,cc6 \n" | ||
211 | " csub.p %0,%0,%0 ,cc6,1 \n" | ||
212 | " orcr cc5,cc4,cc4 \n" | ||
213 | " andcr cc4,cc5,cc4 \n" | ||
214 | " cscan.p %3,gr0,%0 ,cc4,0 \n" | ||
215 | " setlos #64,%1 \n" | ||
216 | " cscan.p %4,gr0,%0 ,cc4,1 \n" | ||
217 | " setlos #32,%2 \n" | ||
218 | " csub.p %1,%0,%0 ,cc4,0 \n" | ||
219 | " csub %2,%0,%0 ,cc4,1 \n" | ||
220 | : "=&r"(bit), "=r"(x), "=r"(y) | ||
221 | : "0r"(_.h), "r"(_.l) | ||
222 | : "icc0", "icc1", "cc4", "cc5", "cc6" | ||
223 | ); | ||
224 | return bit; | ||
225 | |||
226 | } | ||
227 | |||
228 | /** | ||
229 | * ffs - find first bit set | ||
230 | * @x: the word to search | ||
231 | * | ||
232 | * - return 32..1 to indicate bit 31..0 most least significant bit set | ||
233 | * - return 0 to indicate no bits set | ||
234 | */ | ||
235 | static inline __attribute__((const)) | ||
236 | int ffs(int x) | ||
237 | { | ||
238 | /* Note: (x & -x) gives us a mask that is the least significant | ||
239 | * (rightmost) 1-bit of the value in x. | ||
240 | */ | ||
241 | return fls(x & -x); | ||
242 | } | ||
243 | |||
244 | /** | ||
245 | * __ffs - find first bit set | ||
246 | * @x: the word to search | ||
247 | * | ||
248 | * - return 31..0 to indicate bit 31..0 most least significant bit set | ||
249 | * - if no bits are set in x, the result is undefined | ||
250 | */ | ||
251 | static inline __attribute__((const)) | ||
252 | int __ffs(unsigned long x) | ||
253 | { | ||
254 | int bit; | ||
255 | asm("scan %1,gr0,%0" : "=r"(bit) : "r"(x & -x)); | ||
256 | return 31 - bit; | ||
257 | } | ||
258 | |||
177 | #include <asm-generic/bitops/sched.h> | 259 | #include <asm-generic/bitops/sched.h> |
178 | #include <asm-generic/bitops/hweight.h> | 260 | #include <asm-generic/bitops/hweight.h> |
179 | 261 | ||