OLD | NEW |
| (Empty) |
1 #define a_cas a_cas | |
2 static inline int a_cas(volatile int* p, int t, int s) { | |
3 __asm__ __volatile__("lock ; cmpxchg %3, %1" | |
4 : "=a"(t), "=m"(*p) | |
5 : "a"(t), "r"(s) | |
6 : "memory"); | |
7 return t; | |
8 } | |
9 | |
10 #define a_swap a_swap | |
11 static inline int a_swap(volatile int* p, int v) { | |
12 __asm__ __volatile__("xchg %0, %1" : "=r"(v), "=m"(*p) : "0"(v) : "memory"); | |
13 return v; | |
14 } | |
15 | |
16 #define a_fetch_add a_fetch_add | |
17 static inline int a_fetch_add(volatile int* p, int v) { | |
18 __asm__ __volatile__("lock ; xadd %0, %1" | |
19 : "=r"(v), "=m"(*p) | |
20 : "0"(v) | |
21 : "memory"); | |
22 return v; | |
23 } | |
24 | |
25 #define a_and a_and | |
26 static inline void a_and(volatile int* p, int v) { | |
27 __asm__ __volatile__("lock ; and %1, %0" : "=m"(*p) : "r"(v) : "memory"); | |
28 } | |
29 | |
30 #define a_or a_or | |
31 static inline void a_or(volatile int* p, int v) { | |
32 __asm__ __volatile__("lock ; or %1, %0" : "=m"(*p) : "r"(v) : "memory"); | |
33 } | |
34 | |
35 #define a_inc a_inc | |
36 static inline void a_inc(volatile int* p) { | |
37 __asm__ __volatile__("lock ; incl %0" : "=m"(*p) : "m"(*p) : "memory"); | |
38 } | |
39 | |
40 #define a_dec a_dec | |
41 static inline void a_dec(volatile int* p) { | |
42 __asm__ __volatile__("lock ; decl %0" : "=m"(*p) : "m"(*p) : "memory"); | |
43 } | |
44 | |
45 #define a_store a_store | |
46 static inline void a_store(volatile int* p, int x) { | |
47 __asm__ __volatile__("mov %1, %0 ; lock ; orl $0,(%%esp)" | |
48 : "=m"(*p) | |
49 : "r"(x) | |
50 : "memory"); | |
51 } | |
52 | |
53 #define a_barrier a_barrier | |
54 static inline void a_barrier() { | |
55 __asm__ __volatile__("" : : : "memory"); | |
56 } | |
57 | |
58 #define a_pause a_pause | |
59 static inline void a_spin() { | |
60 __asm__ __volatile__("pause" : : : "memory"); | |
61 } | |
62 | |
63 #define a_crash a_crash | |
64 static inline void a_crash() { | |
65 __asm__ __volatile__("hlt" : : : "memory"); | |
66 } | |
67 | |
68 #define a_ctz_64 a_ctz_64 | |
69 static inline int a_ctz_64(uint64_t x) { | |
70 int r; | |
71 __asm__("bsf %1,%0 ; jnz 1f ; bsf %2,%0 ; add $32,%0\n1:" | |
72 : "=&r"(r) | |
73 : "r"((unsigned)x), "r"((unsigned)(x >> 32))); | |
74 return r; | |
75 } | |
76 | |
77 #define a_ctz_l a_ctz_l | |
78 static inline int a_ctz_l(unsigned long x) { | |
79 long r; | |
80 __asm__("bsf %1,%0" : "=r"(r) : "r"(x)); | |
81 return r; | |
82 } | |
OLD | NEW |