xref: /openbmc/linux/arch/sh/include/asm/bitops.h (revision 4eb5928d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_SH_BITOPS_H
3 #define __ASM_SH_BITOPS_H
4 
5 #ifndef _LINUX_BITOPS_H
6 #error only <linux/bitops.h> can be included directly
7 #endif
8 
9 /* For __swab32 */
10 #include <asm/byteorder.h>
11 #include <asm/barrier.h>
12 
13 #ifdef CONFIG_GUSA_RB
14 #include <asm/bitops-grb.h>
15 #elif defined(CONFIG_CPU_SH2A)
16 #include <asm-generic/bitops/atomic.h>
17 #include <asm/bitops-op32.h>
18 #elif defined(CONFIG_CPU_SH4A)
19 #include <asm/bitops-llsc.h>
20 #elif defined(CONFIG_CPU_J2) && defined(CONFIG_SMP)
21 #include <asm/bitops-cas.h>
22 #else
23 #include <asm-generic/bitops/atomic.h>
24 #include <asm-generic/bitops/non-atomic.h>
25 #endif
26 
27 static inline unsigned long ffz(unsigned long word)
28 {
29 	unsigned long result;
30 
31 	__asm__("1:\n\t"
32 		"shlr	%1\n\t"
33 		"bt/s	1b\n\t"
34 		" add	#1, %0"
35 		: "=r" (result), "=r" (word)
36 		: "0" (~0L), "1" (word)
37 		: "t");
38 	return result;
39 }
40 
41 /**
42  * __ffs - find first bit in word.
43  * @word: The word to search
44  *
45  * Undefined if no bit exists, so code should check against 0 first.
46  */
47 static inline unsigned long __ffs(unsigned long word)
48 {
49 	unsigned long result;
50 
51 	__asm__("1:\n\t"
52 		"shlr	%1\n\t"
53 		"bf/s	1b\n\t"
54 		" add	#1, %0"
55 		: "=r" (result), "=r" (word)
56 		: "0" (~0L), "1" (word)
57 		: "t");
58 	return result;
59 }
60 
61 #include <asm-generic/bitops/find.h>
62 #include <asm-generic/bitops/ffs.h>
63 #include <asm-generic/bitops/hweight.h>
64 #include <asm-generic/bitops/lock.h>
65 #include <asm-generic/bitops/sched.h>
66 #include <asm-generic/bitops/le.h>
67 #include <asm-generic/bitops/ext2-atomic.h>
68 #include <asm-generic/bitops/fls.h>
69 #include <asm-generic/bitops/__fls.h>
70 #include <asm-generic/bitops/fls64.h>
71 
72 #endif /* __ASM_SH_BITOPS_H */
73