kernel: Import atomic_testandset_int() from FreeBSD
[dragonfly.git] / sys / cpu / i386 / include / atomic.h
1 /*-
2  * Copyright (c) 1998 Doug Rabson
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD: src/sys/i386/include/atomic.h,v 1.9.2.1 2000/07/07 00:38:47 obrien Exp $
27  */
28 #ifndef _CPU_ATOMIC_H_
29 #define _CPU_ATOMIC_H_
30
31 #ifndef _SYS_TYPES_H_
32 #include <sys/types.h>
33 #endif
34
35 /*
36  * Various simple arithmetic on memory which is atomic in the presence
37  * of interrupts and multiple processors.
38  *
39  * atomic_set_char(P, V)        (*(u_char*)(P) |= (V))
40  * atomic_clear_char(P, V)      (*(u_char*)(P) &= ~(V))
41  * atomic_add_char(P, V)        (*(u_char*)(P) += (V))
42  * atomic_subtract_char(P, V)   (*(u_char*)(P) -= (V))
43  *
44  * atomic_set_short(P, V)       (*(u_short*)(P) |= (V))
45  * atomic_clear_short(P, V)     (*(u_short*)(P) &= ~(V))
46  * atomic_add_short(P, V)       (*(u_short*)(P) += (V))
47  * atomic_subtract_short(P, V)  (*(u_short*)(P) -= (V))
48  *
49  * atomic_set_int(P, V)         (*(u_int*)(P) |= (V))
50  * atomic_clear_int(P, V)       (*(u_int*)(P) &= ~(V))
51  * atomic_add_int(P, V)         (*(u_int*)(P) += (V))
52  * atomic_subtract_int(P, V)    (*(u_int*)(P) -= (V))
53  *
54  * atomic_set_long(P, V)        (*(u_long*)(P) |= (V))
55  * atomic_clear_long(P, V)      (*(u_long*)(P) &= ~(V))
56  * atomic_add_long(P, V)        (*(u_long*)(P) += (V))
57  * atomic_subtract_long(P, V)   (*(u_long*)(P) -= (V))
58  */
59
60 /*
61  * The above functions are expanded inline in the statically-linked
62  * kernel and lock prefixes are generated.
63  *
64  * Kernel modules call real functions which are built into the kernel.
65  */
66 #if defined(KLD_MODULE)
67 #define ATOMIC_ASM(NAME, TYPE, OP, V)                   \
68         extern void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v); \
69         extern void atomic_##NAME##_##TYPE##_nonlocked(volatile u_##TYPE *p, u_##TYPE v);
70
71 int     atomic_testandset_int(volatile u_int *p, u_int v);
72
73 #else /* !KLD_MODULE */
74 #define MPLOCKED        "lock ; "
75
76 /*
77  * The assembly is volatilized to demark potential before-and-after side
78  * effects if an interrupt or SMP collision were to occur.  The primary
79  * atomic instructions are MP safe, the nonlocked instructions are 
80  * local-interrupt-safe (so we don't depend on C 'X |= Y' generating an
81  * atomic instruction).
82  *
83  * +m - memory is read and written (=m - memory is only written)
84  * iq - integer constant or %ax/%bx/%cx/%dx (ir = int constant or any reg)
85  *      (Note: byte instructions only work on %ax,%bx,%cx, or %dx).  iq
86  *      is good enough for our needs so don't get fancy.
87  */
88
89 /* egcs 1.1.2+ version */
90 #define ATOMIC_ASM(NAME, TYPE, OP, V)                   \
91 static __inline void                                    \
92 atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
93 {                                                       \
94         __asm __volatile(MPLOCKED OP                    \
95                          : "+m" (*p)                    \
96                          : "iq" (V));                   \
97 }                                                       \
98 static __inline void                                    \
99 atomic_##NAME##_##TYPE##_nonlocked(volatile u_##TYPE *p, u_##TYPE v)\
100 {                                                       \
101         __asm __volatile(OP                             \
102                          : "+m" (*p)                    \
103                          : "iq" (V));                   \
104 }
105
106 #endif /* KLD_MODULE */
107
108 /* egcs 1.1.2+ version */
109 ATOMIC_ASM(set,      char,  "orb %b1,%0",   v)
110 ATOMIC_ASM(clear,    char,  "andb %b1,%0", ~v)
111 ATOMIC_ASM(add,      char,  "addb %b1,%0",  v)
112 ATOMIC_ASM(subtract, char,  "subb %b1,%0",  v)
113
114 ATOMIC_ASM(set,      short, "orw %w1,%0",   v)
115 ATOMIC_ASM(clear,    short, "andw %w1,%0", ~v)
116 ATOMIC_ASM(add,      short, "addw %w1,%0",  v)
117 ATOMIC_ASM(subtract, short, "subw %w1,%0",  v)
118
119 ATOMIC_ASM(set,      int,   "orl %1,%0",   v)
120 ATOMIC_ASM(clear,    int,   "andl %1,%0", ~v)
121 ATOMIC_ASM(add,      int,   "addl %1,%0",  v)
122 ATOMIC_ASM(subtract, int,   "subl %1,%0",  v)
123
124 ATOMIC_ASM(set,      long,  "orl %1,%0",   v)
125 ATOMIC_ASM(clear,    long,  "andl %1,%0", ~v)
126 ATOMIC_ASM(add,      long,  "addl %1,%0",  v)
127 ATOMIC_ASM(subtract, long,  "subl %1,%0",  v)
128
129 #if defined(KLD_MODULE)
130
131 u_int   atomic_readandclear_int(volatile u_int *addr);
132
133 #else /* !KLD_MODULE */
134
135 static __inline u_int
136 atomic_readandclear_int(volatile u_int *addr)
137 {
138         u_int res;
139
140         res = 0;
141         __asm __volatile(
142         "       xchgl   %1,%0 ;         "
143         "# atomic_readandclear_int"
144         : "+r" (res),                   /* 0 */
145           "=m" (*addr)                  /* 1 */
146         : "m" (*addr));
147
148         return (res);
149 }
150
151 #endif /* KLD_MODULE */
152
153
154 /*
155  * atomic_poll_acquire_int(P)   Returns non-zero on success, 0 if the lock
156  *                              has already been acquired.
157  * atomic_poll_release_int(P)
158  *
159  * These support the NDIS driver and are also used for IPIQ interlocks
160  * between cpus.  Both the acquisition and release must be 
161  * cache-synchronizing instructions.
162  */
163
164 #if defined(KLD_MODULE)
165
166 extern int atomic_swap_int(volatile int *addr, int value);
167 extern void *atomic_swap_ptr(volatile void **addr, void *value);
168 extern int atomic_poll_acquire_int(volatile u_int *p);
169 extern void atomic_poll_release_int(volatile u_int *p);
170
171 #else
172
173 static __inline int
174 atomic_swap_int(volatile int *addr, int value)
175 {
176         __asm __volatile("xchgl %0, %1" :
177             "=r" (value), "=m" (*addr) : "0" (value) : "memory");
178         return (value);
179 }
180
181 static __inline void *
182 atomic_swap_ptr(volatile void **addr, void *value)
183 {
184         __asm __volatile("xchgl %0, %1" :
185             "=r" (value), "=m" (*addr) : "0" (value) : "memory");
186         return (value);
187 }
188
189 static __inline
190 int
191 atomic_poll_acquire_int(volatile u_int *p)
192 {
193         u_int data;
194
195         __asm __volatile(MPLOCKED "btsl $0,%0; setnc %%al; andl $255,%%eax" : "+m" (*p), "=a" (data));
196         return(data);
197 }
198
199 static __inline
200 void
201 atomic_poll_release_int(volatile u_int *p)
202 {
203         __asm __volatile(MPLOCKED "btrl $0,%0" : "+m" (*p));
204 }
205
206 #endif
207
208 /*
209  * These functions operate on a 32 bit interrupt interlock which is defined
210  * as follows:
211  *
212  *      bit 0-30        interrupt handler disabled bits (counter)
213  *      bit 31          interrupt handler currently running bit (1 = run)
214  *
215  * atomic_intr_cond_test(P)     Determine if the interlock is in an
216  *                              acquired state.  Returns 0 if it not
217  *                              acquired, non-zero if it is.
218  *
219  * atomic_intr_cond_try(P)
220  *                              Increment the request counter and attempt to
221  *                              set bit 31 to acquire the interlock.  If
222  *                              we are unable to set bit 31 the request
223  *                              counter is decremented and we return -1,
224  *                              otherwise we return 0.
225  *
226  * atomic_intr_cond_enter(P, func, arg)
227  *                              Increment the request counter and attempt to
228  *                              set bit 31 to acquire the interlock.  If
229  *                              we are unable to set bit 31 func(arg) is
230  *                              called in a loop until we are able to set
231  *                              bit 31.
232  *
233  * atomic_intr_cond_exit(P, func, arg)
234  *                              Decrement the request counter and clear bit
235  *                              31.  If the request counter is still non-zero
236  *                              call func(arg) once.
237  *
238  * atomic_intr_handler_disable(P)
239  *                              Set bit 30, indicating that the interrupt
240  *                              handler has been disabled.  Must be called
241  *                              after the hardware is disabled.
242  *
243  *                              Returns bit 31 indicating whether a serialized
244  *                              accessor is active (typically the interrupt
245  *                              handler is running).  0 == not active,
246  *                              non-zero == active.
247  *
248  * atomic_intr_handler_enable(P)
249  *                              Clear bit 30, indicating that the interrupt
250  *                              handler has been enabled.  Must be called
251  *                              before the hardware is actually enabled.
252  *
253  * atomic_intr_handler_is_enabled(P)
254  *                              Returns bit 30, 0 indicates that the handler
255  *                              is enabled, non-zero indicates that it is
256  *                              disabled.  The request counter portion of
257  *                              the field is ignored.
258  */
259
260 #if defined(KLD_MODULE)
261
262 void atomic_intr_init(__atomic_intr_t *p);
263 int atomic_intr_handler_disable(__atomic_intr_t *p);
264 void atomic_intr_handler_enable(__atomic_intr_t *p);
265 int atomic_intr_handler_is_enabled(__atomic_intr_t *p);
266 int atomic_intr_cond_test(__atomic_intr_t *p);
267 int atomic_intr_cond_try(__atomic_intr_t *p);
268 void atomic_intr_cond_enter(__atomic_intr_t *p, void (*func)(void *), void *arg);
269 void atomic_intr_cond_exit(__atomic_intr_t *p, void (*func)(void *), void *arg);
270 uint64_t atomic_load_acq_64_i586(volatile uint64_t *p);
271
272 #else
273
274 static __inline
275 void
276 atomic_intr_init(__atomic_intr_t *p)
277 {
278         *p = 0;
279 }
280
281 static __inline
282 int
283 atomic_intr_handler_disable(__atomic_intr_t *p)
284 {
285         int data;
286
287         __asm __volatile(MPLOCKED "orl $0x40000000,%1; movl %1,%%eax; " \
288                                   "andl $0x80000000,%%eax" \
289                                   : "=a"(data) , "+m"(*p));
290         return(data);
291 }
292
293 static __inline
294 void
295 atomic_intr_handler_enable(__atomic_intr_t *p)
296 {
297         __asm __volatile(MPLOCKED "andl $0xBFFFFFFF,%0" : "+m" (*p));
298 }
299
300 static __inline
301 int
302 atomic_intr_handler_is_enabled(__atomic_intr_t *p)
303 {
304         int data;
305
306         __asm __volatile("movl %1,%%eax; andl $0x40000000,%%eax" \
307                          : "=a"(data) : "m"(*p));
308         return(data);
309 }
310
311 static __inline
312 void
313 atomic_intr_cond_enter(__atomic_intr_t *p, void (*func)(void *), void *arg)
314 {
315         __asm __volatile(MPLOCKED "incl %0; " \
316                          "1: ;" \
317                          MPLOCKED "btsl $31,%0; jnc 2f; " \
318                          "pushl %2; call *%1; addl $4,%%esp; " \
319                          "jmp 1b; " \
320                          "2: ;" \
321                          : "+m" (*p) \
322                          : "r"(func), "m"(arg) \
323                          : "ax", "cx", "dx");
324 }
325
326 /*
327  * Attempt to enter the interrupt condition variable.  Returns zero on
328  * success, 1 on failure.
329  */
330 static __inline
331 int
332 atomic_intr_cond_try(__atomic_intr_t *p)
333 {
334         int ret;
335
336         __asm __volatile(MPLOCKED "incl %0; "                   \
337                          "1: ;"                                 \
338                          "subl %%eax,%%eax; "                   \
339                          MPLOCKED "btsl $31,%0; jnc 2f; "       \
340                          MPLOCKED "decl %0; "                   \
341                          "movl $1,%%eax;"                       \
342                          "2: ;"
343                          : "+m" (*p), "=&a"(ret)
344                          : : "cx", "dx");
345         return (ret);
346 }
347
348
349 static __inline
350 int
351 atomic_intr_cond_test(__atomic_intr_t *p)
352 {
353         return((int)(*p & 0x80000000));
354 }
355
356 static __inline
357 void
358 atomic_intr_cond_exit(__atomic_intr_t *p, void (*func)(void *), void *arg)
359 {
360         __asm __volatile(MPLOCKED "decl %0; " \
361                         MPLOCKED "btrl $31,%0; " \
362                         "testl $0x3FFFFFFF,%0; jz 1f; " \
363                          "pushl %2; call *%1; addl $4,%%esp; " \
364                          "1: ;" \
365                          : "+m" (*p) \
366                          : "r"(func), "m"(arg) \
367                          : "ax", "cx", "dx");
368 }
369
370 static __inline uint64_t
371 atomic_load_acq_64_i586(volatile uint64_t *p)
372 {
373         uint64_t res;
374
375         __asm __volatile(
376         "       movl %%ebx,%%eax ;      "
377         "       movl %%ecx,%%edx ;      "
378         "       " MPLOCKED "            "
379         "       cmpxchg8b %2"
380         : "=&A" (res),                  /* 0 */
381           "=m" (*p)                     /* 1 */
382         : "m" (*p)                      /* 2 */
383         : "memory", "cc");
384
385         return (res);
386 }
387
388 #endif /* _KERNEL */
389
390 /*
391  * Atomic compare and set
392  *
393  * if (*_dst == _old) *_dst = _new (all 32 bit words)
394  *
395  * Returns 0 on failure, non-zero on success
396  */
397 #if defined(KLD_MODULE)
398
399 extern int atomic_cmpset_int(volatile u_int *_dst, u_int _old, u_int _new);
400 extern long atomic_cmpset_long(volatile u_long *_dst, u_long _exp, u_long _src);
401 extern u_int atomic_fetchadd_int(volatile u_int *_p, u_int _v);
402 extern u_long atomic_fetchadd_long(volatile u_long *_p, u_long _v);
403
404 #else
405
406 static __inline int
407 atomic_cmpset_int(volatile u_int *_dst, u_int _old, u_int _new)
408 {
409         u_int res = _old;
410
411         __asm __volatile(MPLOCKED "cmpxchgl %2,%1; " \
412                          : "+a" (res), "=m" (*_dst) \
413                          : "r" (_new), "m" (*_dst) \
414                          : "memory");
415         return (res == _old);
416 }
417
418 static __inline long
419 atomic_cmpset_long(volatile u_long *_dst, u_long _exp, u_long _src)
420 {
421          return (atomic_cmpset_int((volatile u_int *)_dst, (u_int)_exp,
422                                    (u_int)_src));
423 }
424
425 /*
426  * Atomically add the value of v to the integer pointed to by p and return
427  * the previous value of *p.
428  */
429 static __inline u_int
430 atomic_fetchadd_int(volatile u_int *_p, u_int _v)
431 {
432         __asm __volatile(MPLOCKED "xaddl %0,%1; " \
433                          : "+r" (_v), "=m" (*_p)        \
434                          : "m" (*_p)            \
435                          : "memory");
436         return (_v);
437 }
438
439 static __inline int
440 atomic_testandset_int(volatile u_int *p, u_int v)
441 {
442         u_char res;
443
444         __asm __volatile(
445         "       " MPLOCKED "            "
446         "       btsl    %2,%1 ;         "
447         "       setc    %0 ;            "
448         "# atomic_testandset_int"
449         : "=q" (res),                   /* 0 */
450           "+m" (*p)                     /* 1 */
451         : "Ir" (v & 0x1f)               /* 2 */
452         : "cc");
453         return (res);
454 }
455
456 static __inline u_long
457 atomic_fetchadd_long(volatile u_long *_p, u_long _v)
458 {
459         __asm __volatile(MPLOCKED "xaddl %0,%1; " \
460                          : "+r" (_v), "=m" (*_p)        \
461                          : "m" (*_p)            \
462                          : "memory");
463         return (_v);
464 }
465
466 #endif  /* KLD_MODULE */
467
468 #if defined(KLD_MODULE)
469
470 #define ATOMIC_STORE_LOAD(TYPE, LOP, SOP)                       \
471 extern u_##TYPE atomic_load_acq_##TYPE(volatile u_##TYPE *p);   \
472 extern void     atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v);
473
474 #else /* !KLD_MODULE */
475
476 #define ATOMIC_STORE_LOAD(TYPE, LOP, SOP)               \
477 static __inline u_##TYPE                                \
478 atomic_load_acq_##TYPE(volatile u_##TYPE *p)            \
479 {                                                       \
480         u_##TYPE res;                                   \
481                                                         \
482         __asm __volatile(MPLOCKED LOP                   \
483         : "=a" (res),                   /* 0 */         \
484           "=m" (*p)                     /* 1 */         \
485         : "m" (*p)                      /* 2 */         \
486         : "memory");                                    \
487                                                         \
488         return (res);                                   \
489 }                                                       \
490                                                         \
491 /*                                                      \
492  * The XCHG instruction asserts LOCK automagically.     \
493  */                                                     \
494 static __inline void                                    \
495 atomic_store_rel_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\
496 {                                                       \
497         __asm __volatile(SOP                            \
498         : "=m" (*p),                    /* 0 */         \
499           "+r" (v)                      /* 1 */         \
500         : "m" (*p));                    /* 2 */         \
501 }                                                       \
502 struct __hack
503
504 #endif /* !KLD_MODULE */
505
506 ATOMIC_STORE_LOAD(char, "cmpxchgb %b0,%1", "xchgb %b1,%0");
507 ATOMIC_STORE_LOAD(short,"cmpxchgw %w0,%1", "xchgw %w1,%0");
508 ATOMIC_STORE_LOAD(int,  "cmpxchgl %0,%1",  "xchgl %1,%0");
509 ATOMIC_STORE_LOAD(long, "cmpxchgl %0,%1",  "xchgl %1,%0");
510
511 #undef ATOMIC_ASM
512 #undef ATOMIC_STORE_LOAD
513
514 /* Acquire and release variants are identical to the normal ones. */
515 #define atomic_set_acq_char             atomic_set_char
516 #define atomic_set_rel_char             atomic_set_char
517 #define atomic_clear_acq_char           atomic_clear_char
518 #define atomic_clear_rel_char           atomic_clear_char
519 #define atomic_add_acq_char             atomic_add_char
520 #define atomic_add_rel_char             atomic_add_char
521 #define atomic_subtract_acq_char        atomic_subtract_char
522 #define atomic_subtract_rel_char        atomic_subtract_char
523
524 #define atomic_set_acq_short            atomic_set_short
525 #define atomic_set_rel_short            atomic_set_short
526 #define atomic_clear_acq_short          atomic_clear_short
527 #define atomic_clear_rel_short          atomic_clear_short
528 #define atomic_add_acq_short            atomic_add_short
529 #define atomic_add_rel_short            atomic_add_short
530 #define atomic_subtract_acq_short       atomic_subtract_short
531 #define atomic_subtract_rel_short       atomic_subtract_short
532
533 #define atomic_set_acq_int              atomic_set_int
534 #define atomic_set_rel_int              atomic_set_int
535 #define atomic_clear_acq_int            atomic_clear_int
536 #define atomic_clear_rel_int            atomic_clear_int
537 #define atomic_add_acq_int              atomic_add_int
538 #define atomic_add_rel_int              atomic_add_int
539 #define atomic_subtract_acq_int         atomic_subtract_int
540 #define atomic_subtract_rel_int         atomic_subtract_int
541 #define atomic_cmpset_acq_int           atomic_cmpset_int
542 #define atomic_cmpset_rel_int           atomic_cmpset_int
543
544 #define atomic_set_acq_long             atomic_set_long
545 #define atomic_set_rel_long             atomic_set_long
546 #define atomic_clear_acq_long           atomic_clear_long
547 #define atomic_clear_rel_long           atomic_clear_long
548 #define atomic_add_acq_long             atomic_add_long
549 #define atomic_add_rel_long             atomic_add_long
550 #define atomic_subtract_acq_long        atomic_subtract_long
551 #define atomic_subtract_rel_long        atomic_subtract_long
552 #define atomic_cmpset_acq_long          atomic_cmpset_long
553 #define atomic_cmpset_rel_long          atomic_cmpset_long
554
555 /* cpumask_t is 32-bits on i386 */
556 #define atomic_set_cpumask              atomic_set_int
557 #define atomic_clear_cpumask            atomic_clear_int
558 #define atomic_cmpset_cpumask           atomic_cmpset_int
559
560 /* Operations on 8-bit bytes. */
561 #define atomic_set_8            atomic_set_char
562 #define atomic_set_acq_8        atomic_set_acq_char
563 #define atomic_set_rel_8        atomic_set_rel_char
564 #define atomic_clear_8          atomic_clear_char
565 #define atomic_clear_acq_8      atomic_clear_acq_char
566 #define atomic_clear_rel_8      atomic_clear_rel_char
567 #define atomic_add_8            atomic_add_char
568 #define atomic_add_acq_8        atomic_add_acq_char
569 #define atomic_add_rel_8        atomic_add_rel_char
570 #define atomic_subtract_8       atomic_subtract_char
571 #define atomic_subtract_acq_8   atomic_subtract_acq_char
572 #define atomic_subtract_rel_8   atomic_subtract_rel_char
573 #define atomic_load_acq_8       atomic_load_acq_char
574 #define atomic_store_rel_8      atomic_store_rel_char
575
576 /* Operations on 16-bit words. */
577 #define atomic_set_16           atomic_set_short
578 #define atomic_set_acq_16       atomic_set_acq_short
579 #define atomic_set_rel_16       atomic_set_rel_short
580 #define atomic_clear_16         atomic_clear_short
581 #define atomic_clear_acq_16     atomic_clear_acq_short
582 #define atomic_clear_rel_16     atomic_clear_rel_short
583 #define atomic_add_16           atomic_add_short
584 #define atomic_add_acq_16       atomic_add_acq_short
585 #define atomic_add_rel_16       atomic_add_rel_short
586 #define atomic_subtract_16      atomic_subtract_short
587 #define atomic_subtract_acq_16  atomic_subtract_acq_short
588 #define atomic_subtract_rel_16  atomic_subtract_rel_short
589 #define atomic_load_acq_16      atomic_load_acq_short
590 #define atomic_store_rel_16     atomic_store_rel_short
591
592 /* Operations on 32-bit double words. */
593 #define atomic_set_32           atomic_set_int
594 #define atomic_set_acq_32       atomic_set_acq_int
595 #define atomic_set_rel_32       atomic_set_rel_int
596 #define atomic_clear_32         atomic_clear_int
597 #define atomic_clear_acq_32     atomic_clear_acq_int
598 #define atomic_clear_rel_32     atomic_clear_rel_int
599 #define atomic_add_32           atomic_add_int
600 #define atomic_add_acq_32       atomic_add_acq_int
601 #define atomic_add_rel_32       atomic_add_rel_int
602 #define atomic_subtract_32      atomic_subtract_int
603 #define atomic_subtract_acq_32  atomic_subtract_acq_int
604 #define atomic_subtract_rel_32  atomic_subtract_rel_int
605 #define atomic_load_acq_32      atomic_load_acq_int
606 #define atomic_store_rel_32     atomic_store_rel_int
607 #define atomic_cmpset_32        atomic_cmpset_int
608 #define atomic_cmpset_acq_32    atomic_cmpset_acq_int
609 #define atomic_cmpset_rel_32    atomic_cmpset_rel_int
610 #define atomic_readandclear_32  atomic_readandclear_int
611 #define atomic_fetchadd_32      atomic_fetchadd_int
612
613 /* Operations on 64-bit quad words. */
614 #define atomic_load_acq_64      atomic_load_acq_64_i586
615
616 /* Operations on pointers. */
617 #define atomic_set_ptr(p, v) \
618         atomic_set_int((volatile u_int *)(p), (u_int)(v))
619 #define atomic_set_acq_ptr(p, v) \
620         atomic_set_acq_int((volatile u_int *)(p), (u_int)(v))
621 #define atomic_set_rel_ptr(p, v) \
622         atomic_set_rel_int((volatile u_int *)(p), (u_int)(v))
623 #define atomic_clear_ptr(p, v) \
624         atomic_clear_int((volatile u_int *)(p), (u_int)(v))
625 #define atomic_clear_acq_ptr(p, v) \
626         atomic_clear_acq_int((volatile u_int *)(p), (u_int)(v))
627 #define atomic_clear_rel_ptr(p, v) \
628         atomic_clear_rel_int((volatile u_int *)(p), (u_int)(v))
629 #define atomic_add_ptr(p, v) \
630         atomic_add_int((volatile u_int *)(p), (u_int)(v))
631 #define atomic_add_acq_ptr(p, v) \
632         atomic_add_acq_int((volatile u_int *)(p), (u_int)(v))
633 #define atomic_add_rel_ptr(p, v) \
634         atomic_add_rel_int((volatile u_int *)(p), (u_int)(v))
635 #define atomic_subtract_ptr(p, v) \
636         atomic_subtract_int((volatile u_int *)(p), (u_int)(v))
637 #define atomic_subtract_acq_ptr(p, v) \
638         atomic_subtract_acq_int((volatile u_int *)(p), (u_int)(v))
639 #define atomic_subtract_rel_ptr(p, v) \
640         atomic_subtract_rel_int((volatile u_int *)(p), (u_int)(v))
641 #define atomic_load_acq_ptr(p) \
642         atomic_load_acq_int((volatile u_int *)(p))
643 #define atomic_store_rel_ptr(p, v) \
644         atomic_store_rel_int((volatile u_int *)(p), (v))
645 #define atomic_cmpset_ptr(dst, old, new) \
646         atomic_cmpset_int((volatile u_int *)(dst), (u_int)(old), (u_int)(new))
647 #define atomic_cmpset_acq_ptr(dst, old, new) \
648         atomic_cmpset_acq_int((volatile u_int *)(dst), (u_int)(old), \
649             (u_int)(new))
650 #define atomic_cmpset_rel_ptr(dst, old, new) \
651         atomic_cmpset_rel_int((volatile u_int *)(dst), (u_int)(old), \
652             (u_int)(new))
653 #define atomic_readandclear_ptr(p) \
654         atomic_readandclear_int((volatile u_int *)(p))
655
656 #endif /* ! _CPU_ATOMIC_H_ */