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