xref: /openbmc/linux/arch/sh/include/asm/bitops.h (revision fcc8487d)
1 #ifndef __ASM_SH_BITOPS_H
2 #define __ASM_SH_BITOPS_H
3 
4 #ifdef __KERNEL__
5 
6 #ifndef _LINUX_BITOPS_H
7 #error only <linux/bitops.h> can be included directly
8 #endif
9 
10 /* For __swab32 */
11 #include <asm/byteorder.h>
12 #include <asm/barrier.h>
13 
14 #ifdef CONFIG_GUSA_RB
15 #include <asm/bitops-grb.h>
16 #elif defined(CONFIG_CPU_SH2A)
17 #include <asm-generic/bitops/atomic.h>
18 #include <asm/bitops-op32.h>
19 #elif defined(CONFIG_CPU_SH4A)
20 #include <asm/bitops-llsc.h>
21 #elif defined(CONFIG_CPU_J2) && defined(CONFIG_SMP)
22 #include <asm/bitops-cas.h>
23 #else
24 #include <asm-generic/bitops/atomic.h>
25 #include <asm-generic/bitops/non-atomic.h>
26 #endif
27 
28 #ifdef CONFIG_SUPERH32
29 static inline unsigned long ffz(unsigned long word)
30 {
31 	unsigned long result;
32 
33 	__asm__("1:\n\t"
34 		"shlr	%1\n\t"
35 		"bt/s	1b\n\t"
36 		" add	#1, %0"
37 		: "=r" (result), "=r" (word)
38 		: "0" (~0L), "1" (word)
39 		: "t");
40 	return result;
41 }
42 
43 /**
44  * __ffs - find first bit in word.
45  * @word: The word to search
46  *
47  * Undefined if no bit exists, so code should check against 0 first.
48  */
49 static inline unsigned long __ffs(unsigned long word)
50 {
51 	unsigned long result;
52 
53 	__asm__("1:\n\t"
54 		"shlr	%1\n\t"
55 		"bf/s	1b\n\t"
56 		" add	#1, %0"
57 		: "=r" (result), "=r" (word)
58 		: "0" (~0L), "1" (word)
59 		: "t");
60 	return result;
61 }
62 #else
63 static inline unsigned long ffz(unsigned long word)
64 {
65 	unsigned long result, __d2, __d3;
66 
67         __asm__("gettr  tr0, %2\n\t"
68                 "pta    $+32, tr0\n\t"
69                 "andi   %1, 1, %3\n\t"
70                 "beq    %3, r63, tr0\n\t"
71                 "pta    $+4, tr0\n"
72                 "0:\n\t"
73                 "shlri.l        %1, 1, %1\n\t"
74                 "addi   %0, 1, %0\n\t"
75                 "andi   %1, 1, %3\n\t"
76                 "beqi   %3, 1, tr0\n"
77                 "1:\n\t"
78                 "ptabs  %2, tr0\n\t"
79                 : "=r" (result), "=r" (word), "=r" (__d2), "=r" (__d3)
80                 : "0" (0L), "1" (word));
81 
82 	return result;
83 }
84 
85 #include <asm-generic/bitops/__ffs.h>
86 #endif
87 
88 #include <asm-generic/bitops/find.h>
89 #include <asm-generic/bitops/ffs.h>
90 #include <asm-generic/bitops/hweight.h>
91 #include <asm-generic/bitops/lock.h>
92 #include <asm-generic/bitops/sched.h>
93 #include <asm-generic/bitops/le.h>
94 #include <asm-generic/bitops/ext2-atomic.h>
95 #include <asm-generic/bitops/fls.h>
96 #include <asm-generic/bitops/__fls.h>
97 #include <asm-generic/bitops/fls64.h>
98 
99 #endif /* __KERNEL__ */
100 
101 #endif /* __ASM_SH_BITOPS_H */
102