xref: /linux/arch/csky/include/asm/bitops.h (revision 0be3ff0c)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef __ASM_CSKY_BITOPS_H
4 #define __ASM_CSKY_BITOPS_H
5 
6 #include <linux/compiler.h>
7 #include <asm/barrier.h>
8 
9 /*
10  * asm-generic/bitops/ffs.h
11  */
12 static inline int ffs(int x)
13 {
14 	if (!x)
15 		return 0;
16 
17 	asm volatile (
18 		"brev %0\n"
19 		"ff1  %0\n"
20 		"addi %0, 1\n"
21 		: "=&r"(x)
22 		: "0"(x));
23 	return x;
24 }
25 
26 /*
27  * asm-generic/bitops/__ffs.h
28  */
29 static __always_inline unsigned long __ffs(unsigned long x)
30 {
31 	asm volatile (
32 		"brev %0\n"
33 		"ff1  %0\n"
34 		: "=&r"(x)
35 		: "0"(x));
36 	return x;
37 }
38 
39 /*
40  * asm-generic/bitops/fls.h
41  */
42 static __always_inline int fls(unsigned int x)
43 {
44 	asm volatile(
45 		"ff1 %0\n"
46 		: "=&r"(x)
47 		: "0"(x));
48 
49 	return (32 - x);
50 }
51 
52 /*
53  * asm-generic/bitops/__fls.h
54  */
55 static __always_inline unsigned long __fls(unsigned long x)
56 {
57 	return fls(x) - 1;
58 }
59 
60 #include <asm-generic/bitops/ffz.h>
61 #include <asm-generic/bitops/fls64.h>
62 
63 #ifndef _LINUX_BITOPS_H
64 #error only <linux/bitops.h> can be included directly
65 #endif
66 
67 #include <asm-generic/bitops/sched.h>
68 #include <asm-generic/bitops/hweight.h>
69 #include <asm-generic/bitops/lock.h>
70 #include <asm-generic/bitops/atomic.h>
71 
72 /*
73  * bug fix, why only could use atomic!!!!
74  */
75 #include <asm-generic/bitops/non-atomic.h>
76 
77 #include <asm-generic/bitops/le.h>
78 #include <asm-generic/bitops/ext2-atomic.h>
79 #endif /* __ASM_CSKY_BITOPS_H */
80