1
2
3
4
5
6
7
8#ifndef _ASM_BITOPS_H
9#define _ASM_BITOPS_H
10
11#include <linux/compiler.h>
12#include <asm/byteorder.h>
13#include <asm/atomic.h>
14#include <asm/barrier.h>
15
16#ifdef __KERNEL__
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31static inline int test_and_clear_bit(int nr, volatile void *addr)
32{
33 int oldval;
34
35 __asm__ __volatile__ (
36 " {R10 = %1; R11 = asr(%2,#5); }\n"
37 " {R10 += asl(R11,#2); R11 = and(%2,#0x1f)}\n"
38 "1: R12 = memw_locked(R10);\n"
39 " { P0 = tstbit(R12,R11); R12 = clrbit(R12,R11); }\n"
40 " memw_locked(R10,P1) = R12;\n"
41 " {if (!P1) jump 1b; %0 = mux(P0,#1,#0);}\n"
42 : "=&r" (oldval)
43 : "r" (addr), "r" (nr)
44 : "r10", "r11", "r12", "p0", "p1", "memory"
45 );
46
47 return oldval;
48}
49
50
51
52
53
54
55static inline int test_and_set_bit(int nr, volatile void *addr)
56{
57 int oldval;
58
59 __asm__ __volatile__ (
60 " {R10 = %1; R11 = asr(%2,#5); }\n"
61 " {R10 += asl(R11,#2); R11 = and(%2,#0x1f)}\n"
62 "1: R12 = memw_locked(R10);\n"
63 " { P0 = tstbit(R12,R11); R12 = setbit(R12,R11); }\n"
64 " memw_locked(R10,P1) = R12;\n"
65 " {if (!P1) jump 1b; %0 = mux(P0,#1,#0);}\n"
66 : "=&r" (oldval)
67 : "r" (addr), "r" (nr)
68 : "r10", "r11", "r12", "p0", "p1", "memory"
69 );
70
71
72 return oldval;
73
74}
75
76
77
78
79
80
81static inline int test_and_change_bit(int nr, volatile void *addr)
82{
83 int oldval;
84
85 __asm__ __volatile__ (
86 " {R10 = %1; R11 = asr(%2,#5); }\n"
87 " {R10 += asl(R11,#2); R11 = and(%2,#0x1f)}\n"
88 "1: R12 = memw_locked(R10);\n"
89 " { P0 = tstbit(R12,R11); R12 = togglebit(R12,R11); }\n"
90 " memw_locked(R10,P1) = R12;\n"
91 " {if (!P1) jump 1b; %0 = mux(P0,#1,#0);}\n"
92 : "=&r" (oldval)
93 : "r" (addr), "r" (nr)
94 : "r10", "r11", "r12", "p0", "p1", "memory"
95 );
96
97 return oldval;
98
99}
100
101
102
103
104
105
106static inline void clear_bit(int nr, volatile void *addr)
107{
108 test_and_clear_bit(nr, addr);
109}
110
111static inline void set_bit(int nr, volatile void *addr)
112{
113 test_and_set_bit(nr, addr);
114}
115
116static inline void change_bit(int nr, volatile void *addr)
117{
118 test_and_change_bit(nr, addr);
119}
120
121
122
123
124
125
126
127
128
129
130static __always_inline void
131arch___clear_bit(unsigned long nr, volatile unsigned long *addr)
132{
133 test_and_clear_bit(nr, addr);
134}
135
136static __always_inline void
137arch___set_bit(unsigned long nr, volatile unsigned long *addr)
138{
139 test_and_set_bit(nr, addr);
140}
141
142static __always_inline void
143arch___change_bit(unsigned long nr, volatile unsigned long *addr)
144{
145 test_and_change_bit(nr, addr);
146}
147
148
149static __always_inline bool
150arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
151{
152 return test_and_clear_bit(nr, addr);
153}
154
155static __always_inline bool
156arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr)
157{
158 return test_and_set_bit(nr, addr);
159}
160
161static __always_inline bool
162arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
163{
164 return test_and_change_bit(nr, addr);
165}
166
167static __always_inline bool
168arch_test_bit(unsigned long nr, const volatile unsigned long *addr)
169{
170 int retval;
171
172 asm volatile(
173 "{P0 = tstbit(%1,%2); if (P0.new) %0 = #1; if (!P0.new) %0 = #0;}\n"
174 : "=&r" (retval)
175 : "r" (addr[BIT_WORD(nr)]), "r" (nr % BITS_PER_LONG)
176 : "p0"
177 );
178
179 return retval;
180}
181
182static __always_inline bool
183arch_test_bit_acquire(unsigned long nr, const volatile unsigned long *addr)
184{
185 int retval;
186
187 asm volatile(
188 "{P0 = tstbit(%1,%2); if (P0.new) %0 = #1; if (!P0.new) %0 = #0;}\n"
189 : "=&r" (retval)
190 : "r" (addr[BIT_WORD(nr)]), "r" (nr % BITS_PER_LONG)
191 : "p0", "memory"
192 );
193
194 return retval;
195}
196
197
198
199
200
201
202
203static inline long ffz(int x)
204{
205 int r;
206
207 asm("%0 = ct1(%1);\n"
208 : "=&r" (r)
209 : "r" (x));
210 return r;
211}
212
213
214
215
216
217
218
219
220static inline int fls(unsigned int x)
221{
222 int r;
223
224 asm("{ %0 = cl0(%1);}\n"
225 "%0 = sub(#32,%0);\n"
226 : "=&r" (r)
227 : "r" (x)
228 : "p0");
229
230 return r;
231}
232
233
234
235
236
237
238
239
240
241static inline int ffs(int x)
242{
243 int r;
244
245 asm("{ P0 = cmp.eq(%1,#0); %0 = ct0(%1);}\n"
246 "{ if (P0) %0 = #0; if (!P0) %0 = add(%0,#1);}\n"
247 : "=&r" (r)
248 : "r" (x)
249 : "p0");
250
251 return r;
252}
253
254
255
256
257
258
259
260
261
262
263static inline unsigned long __ffs(unsigned long word)
264{
265 int num;
266
267 asm("%0 = ct0(%1);\n"
268 : "=&r" (num)
269 : "r" (word));
270
271 return num;
272}
273
274
275
276
277
278
279
280
281static inline unsigned long __fls(unsigned long word)
282{
283 int num;
284
285 asm("%0 = cl0(%1);\n"
286 "%0 = sub(#31,%0);\n"
287 : "=&r" (num)
288 : "r" (word));
289
290 return num;
291}
292
293#include <asm-generic/bitops/lock.h>
294#include <asm-generic/bitops/non-instrumented-non-atomic.h>
295
296#include <asm-generic/bitops/fls64.h>
297#include <asm-generic/bitops/sched.h>
298#include <asm-generic/bitops/hweight.h>
299
300#include <asm-generic/bitops/le.h>
301#include <asm-generic/bitops/ext2-atomic.h>
302
303#endif
304#endif
305