]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | /* asm/arch/bitops.h for Linux/CRISv10 */ |
3 | ||
4 | #ifndef _CRIS_ARCH_BITOPS_H | |
5 | #define _CRIS_ARCH_BITOPS_H | |
6 | ||
7 | /* | |
8 | * Helper functions for the core of the ff[sz] functions, wrapping the | |
9 | * syntactically awkward asms. The asms compute the number of leading | |
10 | * zeroes of a bits-in-byte and byte-in-word and word-in-dword-swapped | |
11 | * number. They differ in that the first function also inverts all bits | |
12 | * in the input. | |
13 | */ | |
bb8cc641 | 14 | static inline unsigned long cris_swapnwbrlz(unsigned long w) |
1da177e4 LT |
15 | { |
16 | /* Let's just say we return the result in the same register as the | |
17 | input. Saying we clobber the input but can return the result | |
18 | in another register: | |
19 | ! __asm__ ("swapnwbr %2\n\tlz %2,%0" | |
20 | ! : "=r,r" (res), "=r,X" (dummy) : "1,0" (w)); | |
0a0fca9d | 21 | confuses gcc (core.c, gcc from cris-dist-1.14). */ |
1da177e4 LT |
22 | |
23 | unsigned long res; | |
24 | __asm__ ("swapnwbr %0 \n\t" | |
25 | "lz %0,%0" | |
26 | : "=r" (res) : "0" (w)); | |
27 | return res; | |
28 | } | |
29 | ||
bb8cc641 | 30 | static inline unsigned long cris_swapwbrlz(unsigned long w) |
1da177e4 LT |
31 | { |
32 | unsigned res; | |
33 | __asm__ ("swapwbr %0 \n\t" | |
34 | "lz %0,%0" | |
35 | : "=r" (res) | |
36 | : "0" (w)); | |
37 | return res; | |
38 | } | |
39 | ||
40 | /* | |
41 | * ffz = Find First Zero in word. Undefined if no zero exists, | |
42 | * so code should check against ~0UL first.. | |
43 | */ | |
bb8cc641 | 44 | static inline unsigned long ffz(unsigned long w) |
1da177e4 LT |
45 | { |
46 | return cris_swapnwbrlz(w); | |
47 | } | |
48 | ||
49 | /** | |
50 | * __ffs - find first bit in word. | |
51 | * @word: The word to search | |
52 | * | |
53 | * Undefined if no bit exists, so code should check against 0 first. | |
54 | */ | |
bb8cc641 | 55 | static inline unsigned long __ffs(unsigned long word) |
1da177e4 LT |
56 | { |
57 | return cris_swapnwbrlz(~word); | |
58 | } | |
59 | ||
60 | /** | |
61 | * ffs - find first bit set | |
62 | * @x: the word to search | |
63 | * | |
64 | * This is defined the same way as | |
65 | * the libc and compiler builtin ffs routines, therefore | |
66 | * differs in spirit from the above ffz (man ffs). | |
67 | */ | |
68 | ||
bb8cc641 | 69 | static inline unsigned long kernel_ffs(unsigned long w) |
1da177e4 LT |
70 | { |
71 | return w ? cris_swapwbrlz (w) + 1 : 0; | |
72 | } | |
73 | ||
74 | #endif |