1
2#ifndef _ASM_IA64_BITOPS_H
3#define _ASM_IA64_BITOPS_H
4
5
6
7
8
9
10
11
12
13#ifndef _LINUX_BITOPS_H
14#error only <linux/bitops.h> can be included directly
15#endif
16
17#include <linux/compiler.h>
18#include <linux/types.h>
19#include <asm/intrinsics.h>
20#include <asm/barrier.h>
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39static __inline__ void
40set_bit (int nr, volatile void *addr)
41{
42 __u32 bit, old, new;
43 volatile __u32 *m;
44 CMPXCHG_BUGCHECK_DECL
45
46 m = (volatile __u32 *) addr + (nr >> 5);
47 bit = 1 << (nr & 31);
48 do {
49 CMPXCHG_BUGCHECK(m);
50 old = *m;
51 new = old | bit;
52 } while (cmpxchg_acq(m, old, new) != old);
53}
54
55
56
57
58
59
60
61
62
63
64static __always_inline void
65arch___set_bit(unsigned long nr, volatile unsigned long *addr)
66{
67 *((__u32 *) addr + (nr >> 5)) |= (1 << (nr & 31));
68}
69
70
71
72
73
74
75
76
77
78
79
80static __inline__ void
81clear_bit (int nr, volatile void *addr)
82{
83 __u32 mask, old, new;
84 volatile __u32 *m;
85 CMPXCHG_BUGCHECK_DECL
86
87 m = (volatile __u32 *) addr + (nr >> 5);
88 mask = ~(1 << (nr & 31));
89 do {
90 CMPXCHG_BUGCHECK(m);
91 old = *m;
92 new = old & mask;
93 } while (cmpxchg_acq(m, old, new) != old);
94}
95
96
97
98
99
100
101
102
103
104static __inline__ void
105clear_bit_unlock (int nr, volatile void *addr)
106{
107 __u32 mask, old, new;
108 volatile __u32 *m;
109 CMPXCHG_BUGCHECK_DECL
110
111 m = (volatile __u32 *) addr + (nr >> 5);
112 mask = ~(1 << (nr & 31));
113 do {
114 CMPXCHG_BUGCHECK(m);
115 old = *m;
116 new = old & mask;
117 } while (cmpxchg_rel(m, old, new) != old);
118}
119
120
121
122
123
124
125
126
127
128static __inline__ void
129__clear_bit_unlock(int nr, void *addr)
130{
131 __u32 * const m = (__u32 *) addr + (nr >> 5);
132 __u32 const new = *m & ~(1 << (nr & 31));
133
134 ia64_st4_rel_nta(m, new);
135}
136
137
138
139
140
141
142
143
144
145
146static __always_inline void
147arch___clear_bit(unsigned long nr, volatile unsigned long *addr)
148{
149 *((__u32 *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
150}
151
152
153
154
155
156
157
158
159
160
161static __inline__ void
162change_bit (int nr, volatile void *addr)
163{
164 __u32 bit, old, new;
165 volatile __u32 *m;
166 CMPXCHG_BUGCHECK_DECL
167
168 m = (volatile __u32 *) addr + (nr >> 5);
169 bit = (1 << (nr & 31));
170 do {
171 CMPXCHG_BUGCHECK(m);
172 old = *m;
173 new = old ^ bit;
174 } while (cmpxchg_acq(m, old, new) != old);
175}
176
177
178
179
180
181
182
183
184
185
186static __always_inline void
187arch___change_bit(unsigned long nr, volatile unsigned long *addr)
188{
189 *((__u32 *) addr + (nr >> 5)) ^= (1 << (nr & 31));
190}
191
192
193
194
195
196
197
198
199
200static __inline__ int
201test_and_set_bit (int nr, volatile void *addr)
202{
203 __u32 bit, old, new;
204 volatile __u32 *m;
205 CMPXCHG_BUGCHECK_DECL
206
207 m = (volatile __u32 *) addr + (nr >> 5);
208 bit = 1 << (nr & 31);
209 do {
210 CMPXCHG_BUGCHECK(m);
211 old = *m;
212 new = old | bit;
213 } while (cmpxchg_acq(m, old, new) != old);
214 return (old & bit) != 0;
215}
216
217
218
219
220
221
222
223
224#define test_and_set_bit_lock test_and_set_bit
225
226
227
228
229
230
231
232
233
234
235static __always_inline bool
236arch___test_and_set_bit(unsigned long nr, volatile unsigned long *addr)
237{
238 __u32 *p = (__u32 *) addr + (nr >> 5);
239 __u32 m = 1 << (nr & 31);
240 int oldbitset = (*p & m) != 0;
241
242 *p |= m;
243 return oldbitset;
244}
245
246
247
248
249
250
251
252
253
254static __inline__ int
255test_and_clear_bit (int nr, volatile void *addr)
256{
257 __u32 mask, old, new;
258 volatile __u32 *m;
259 CMPXCHG_BUGCHECK_DECL
260
261 m = (volatile __u32 *) addr + (nr >> 5);
262 mask = ~(1 << (nr & 31));
263 do {
264 CMPXCHG_BUGCHECK(m);
265 old = *m;
266 new = old & mask;
267 } while (cmpxchg_acq(m, old, new) != old);
268 return (old & ~mask) != 0;
269}
270
271
272
273
274
275
276
277
278
279
280static __always_inline bool
281arch___test_and_clear_bit(unsigned long nr, volatile unsigned long *addr)
282{
283 __u32 *p = (__u32 *) addr + (nr >> 5);
284 __u32 m = 1 << (nr & 31);
285 int oldbitset = (*p & m) != 0;
286
287 *p &= ~m;
288 return oldbitset;
289}
290
291
292
293
294
295
296
297
298
299static __inline__ int
300test_and_change_bit (int nr, volatile void *addr)
301{
302 __u32 bit, old, new;
303 volatile __u32 *m;
304 CMPXCHG_BUGCHECK_DECL
305
306 m = (volatile __u32 *) addr + (nr >> 5);
307 bit = (1 << (nr & 31));
308 do {
309 CMPXCHG_BUGCHECK(m);
310 old = *m;
311 new = old ^ bit;
312 } while (cmpxchg_acq(m, old, new) != old);
313 return (old & bit) != 0;
314}
315
316
317
318
319
320
321
322
323static __always_inline bool
324arch___test_and_change_bit(unsigned long nr, volatile unsigned long *addr)
325{
326 __u32 old, bit = (1 << (nr & 31));
327 __u32 *m = (__u32 *) addr + (nr >> 5);
328
329 old = *m;
330 *m = old ^ bit;
331 return (old & bit) != 0;
332}
333
334#define arch_test_bit generic_test_bit
335#define arch_test_bit_acquire generic_test_bit_acquire
336
337
338
339
340
341
342
343
344static inline unsigned long
345ffz (unsigned long x)
346{
347 unsigned long result;
348
349 result = ia64_popcnt(x & (~x - 1));
350 return result;
351}
352
353
354
355
356
357
358
359static __inline__ unsigned long
360__ffs (unsigned long x)
361{
362 unsigned long result;
363
364 result = ia64_popcnt((x-1) & ~x);
365 return result;
366}
367
368#ifdef __KERNEL__
369
370
371
372
373
374static inline unsigned long
375ia64_fls (unsigned long x)
376{
377 long double d = x;
378 long exp;
379
380 exp = ia64_getf_exp(d);
381 return exp - 0xffff;
382}
383
384
385
386
387
388static inline int fls(unsigned int t)
389{
390 unsigned long x = t & 0xffffffffu;
391
392 if (!x)
393 return 0;
394 x |= x >> 1;
395 x |= x >> 2;
396 x |= x >> 4;
397 x |= x >> 8;
398 x |= x >> 16;
399 return ia64_popcnt(x);
400}
401
402
403
404
405
406static inline unsigned long
407__fls (unsigned long x)
408{
409 x |= x >> 1;
410 x |= x >> 2;
411 x |= x >> 4;
412 x |= x >> 8;
413 x |= x >> 16;
414 x |= x >> 32;
415 return ia64_popcnt(x) - 1;
416}
417
418#include <asm-generic/bitops/fls64.h>
419
420#include <asm-generic/bitops/builtin-ffs.h>
421
422
423
424
425
426static __inline__ unsigned long __arch_hweight64(unsigned long x)
427{
428 unsigned long result;
429 result = ia64_popcnt(x);
430 return result;
431}
432
433#define __arch_hweight32(x) ((unsigned int) __arch_hweight64((x) & 0xfffffffful))
434#define __arch_hweight16(x) ((unsigned int) __arch_hweight64((x) & 0xfffful))
435#define __arch_hweight8(x) ((unsigned int) __arch_hweight64((x) & 0xfful))
436
437#include <asm-generic/bitops/const_hweight.h>
438
439#endif
440
441#ifdef __KERNEL__
442
443#include <asm-generic/bitops/non-instrumented-non-atomic.h>
444
445#include <asm-generic/bitops/le.h>
446
447#include <asm-generic/bitops/ext2-atomic-setbit.h>
448
449#include <asm-generic/bitops/sched.h>
450
451#endif
452
453#endif
454