xref: /openbmc/linux/arch/sh/include/asm/bitops.h (revision 82df5b73)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_SH_BITOPS_H
3 #define __ASM_SH_BITOPS_H
4 
5 #ifdef __KERNEL__
6 
7 #ifndef _LINUX_BITOPS_H
8 #error only <linux/bitops.h> can be included directly
9 #endif
10 
11 /* For __swab32 */
12 #include <asm/byteorder.h>
13 #include <asm/barrier.h>
14 
15 #ifdef CONFIG_GUSA_RB
16 #include <asm/bitops-grb.h>
17 #elif defined(CONFIG_CPU_SH2A)
18 #include <asm-generic/bitops/atomic.h>
19 #include <asm/bitops-op32.h>
20 #elif defined(CONFIG_CPU_SH4A)
21 #include <asm/bitops-llsc.h>
22 #elif defined(CONFIG_CPU_J2) && defined(CONFIG_SMP)
23 #include <asm/bitops-cas.h>
24 #else
25 #include <asm-generic/bitops/atomic.h>
26 #include <asm-generic/bitops/non-atomic.h>
27 #endif
28 
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 
63 #include <asm-generic/bitops/find.h>
64 #include <asm-generic/bitops/ffs.h>
65 #include <asm-generic/bitops/hweight.h>
66 #include <asm-generic/bitops/lock.h>
67 #include <asm-generic/bitops/sched.h>
68 #include <asm-generic/bitops/le.h>
69 #include <asm-generic/bitops/ext2-atomic.h>
70 #include <asm-generic/bitops/fls.h>
71 #include <asm-generic/bitops/__fls.h>
72 #include <asm-generic/bitops/fls64.h>
73 
74 #endif /* __KERNEL__ */
75 
76 #endif /* __ASM_SH_BITOPS_H */
77