OSDN Git Service

fix global visibility (vis.h) support for out-of-tree builds
[android-x86/external-musl-libc.git] / arch / x32 / atomic.h
1 #ifndef _INTERNAL_ATOMIC_H
2 #define _INTERNAL_ATOMIC_H
3
4 #include <stdint.h>
5
6 static inline int a_ctz_64(uint64_t x)
7 {
8         __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
9         return x;
10 }
11
12 static inline int a_ctz_l(unsigned long x)
13 {
14         __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) );
15         return x;
16 }
17
18 static inline void a_and_64(volatile uint64_t *p, uint64_t v)
19 {
20         __asm__( "lock ; and %1, %0"
21                          : "=m"(*p) : "r"(v) : "memory" );
22 }
23
24 static inline void a_or_64(volatile uint64_t *p, uint64_t v)
25 {
26         __asm__( "lock ; or %1, %0"
27                          : "=m"(*p) : "r"(v) : "memory" );
28 }
29
30 static inline void a_or_l(volatile void *p, long v)
31 {
32         __asm__( "lock ; or %1, %0"
33                 : "=m"(*(long *)p) : "r"(v) : "memory" );
34 }
35
36 static inline void *a_cas_p(volatile void *p, void *t, void *s)
37 {
38         __asm__( "lock ; cmpxchg %3, %1"
39                 : "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
40         return t;
41 }
42
43 static inline int a_cas(volatile int *p, int t, int s)
44 {
45         __asm__( "lock ; cmpxchg %3, %1"
46                 : "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
47         return t;
48 }
49
50 static inline void a_or(volatile int *p, int v)
51 {
52         __asm__( "lock ; or %1, %0"
53                 : "=m"(*p) : "r"(v) : "memory" );
54 }
55
56 static inline void a_and(volatile int *p, int v)
57 {
58         __asm__( "lock ; and %1, %0"
59                 : "=m"(*p) : "r"(v) : "memory" );
60 }
61
62 static inline int a_swap(volatile int *x, int v)
63 {
64         __asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
65         return v;
66 }
67
68 static inline int a_fetch_add(volatile int *x, int v)
69 {
70         __asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
71         return v;
72 }
73
74 static inline void a_inc(volatile int *x)
75 {
76         __asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
77 }
78
79 static inline void a_dec(volatile int *x)
80 {
81         __asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
82 }
83
84 static inline void a_store(volatile int *p, int x)
85 {
86         __asm__( "mov %1, %0 ; lock ; orl $0,(%%rsp)" : "=m"(*p) : "r"(x) : "memory" );
87 }
88
89 static inline void a_spin()
90 {
91         __asm__ __volatile__( "pause" : : : "memory" );
92 }
93
94 static inline void a_barrier()
95 {
96         __asm__ __volatile__( "" : : : "memory" );
97 }
98
99 static inline void a_crash()
100 {
101         __asm__ __volatile__( "hlt" : : : "memory" );
102 }
103
104
105 #endif