OLD | NEW |
---|---|
1 #define a_ll a_ll | 1 #define a_ll a_ll |
2 static inline int a_ll(volatile int *p) | 2 static inline int a_ll(volatile int* p) { |
3 { | 3 int v; |
4 » int v; | 4 __asm__ __volatile__("ldaxr %w0,%1" : "=r"(v) : "Q"(*p)); |
5 » __asm__ __volatile__ ("ldaxr %w0,%1" : "=r"(v) : "Q"(*p)); | 5 return v; |
6 » return v; | |
7 } | 6 } |
8 | 7 |
9 #define a_sc a_sc | 8 #define a_sc a_sc |
10 static inline int a_sc(volatile int *p, int v) | 9 static inline int a_sc(volatile int* p, int v) { |
11 { | 10 int r; |
12 » int r; | 11 __asm__ __volatile__("stlxr %w0,%w2,%1" |
13 » __asm__ __volatile__ ("stlxr %w0,%w2,%1" : "=&r"(r), "=Q"(*p) : "r"(v) : "memory"); | 12 : "=&r"(r), "=Q"(*p) |
14 » return !r; | 13 : "r"(v) |
14 : "memory"); | |
15 return !r; | |
15 } | 16 } |
16 | 17 |
17 #define a_barrier a_barrier | 18 #define a_barrier a_barrier |
18 static inline void a_barrier() | 19 static inline void a_barrier() { |
19 { | 20 __asm__ __volatile__("dmb ish" : : : "memory"); |
20 » __asm__ __volatile__ ("dmb ish" : : : "memory"); | |
21 } | 21 } |
22 | 22 |
23 #define a_cas a_cas | 23 #define a_cas a_cas |
24 static inline int a_cas(volatile int *p, int t, int s) | 24 static inline int a_cas(volatile int* p, int t, int s) { |
25 { | 25 int old; |
26 » int old; | 26 do { |
27 » do { | 27 old = a_ll(p); |
28 » » old = a_ll(p); | 28 if (old != t) { |
29 » » if (old != t) { | 29 a_barrier(); |
30 » » » a_barrier(); | 30 break; |
31 » » » break; | 31 } |
32 » » } | 32 } while (!a_sc(p, s)); |
33 » } while (!a_sc(p, s)); | 33 return old; |
34 » return old; | |
35 } | 34 } |
36 | 35 |
37 static inline void *a_ll_p(volatile void *p) | 36 static inline void* a_ll_p(volatile void* p) { |
38 { | 37 void* v; |
39 » void *v; | 38 __asm__ __volatile__("ldaxr %0, %1" : "=r"(v) : "Q"(*(void* volatile*)p)); |
40 » __asm__ __volatile__ ("ldaxr %0, %1" : "=r"(v) : "Q"(*(void *volatile *) p)); | 39 return v; |
41 » return v; | |
42 } | 40 } |
43 | 41 |
44 static inline int a_sc_p(volatile int *p, void *v) | 42 static inline int a_sc_p(volatile int* p, void* v) { |
45 { | 43 int r; |
46 » int r; | 44 __asm__ __volatile__("stlxr %w0,%2,%1" |
47 » __asm__ __volatile__ ("stlxr %w0,%2,%1" : "=&r"(r), "=Q"(*(void *volatil e *)p) : "r"(v) : "memory"); | 45 : "=&r"(r), "=Q"(*(void* volatile*)p) |
48 » return !r; | 46 : "r"(v) |
47 : "memory"); | |
48 return !r; | |
49 } | 49 } |
50 | 50 |
51 #define a_cas_p a_cas_p | 51 #define a_cas_p a_cas_p |
52 static inline void *a_cas_p(volatile void *p, void *t, void *s) | 52 static inline void* a_cas_p(volatile void* p, void* t, void* s) { |
53 { | 53 void* old; |
54 » void *old; | 54 do { |
55 » do { | 55 old = a_ll_p(p); |
56 » » old = a_ll_p(p); | 56 if (old != t) { |
57 » » if (old != t) { | 57 a_barrier(); |
58 » » » a_barrier(); | 58 break; |
59 » » » break; | 59 } |
60 » » } | 60 } while (!a_sc_p(p, s)); |
61 » } while (!a_sc_p(p, s)); | 61 return old; |
62 » return old; | |
63 } | 62 } |
64 | 63 |
65 #define a_ctz_64 a_ctz_64 | 64 #define a_ctz_64 a_ctz_64 |
66 static inline int a_ctz_64(uint64_t x) | 65 static inline int a_ctz_64(uint64_t x) { |
67 { | 66 __asm__( |
68 » __asm__( | 67 "»rbit %0, %1\n" |
viettrungluu
2016/02/18 23:55:37
Oh no, it kept the hard tab in the string!
| |
69 » » "» rbit %0, %1\n" | 68 "»clz %0, %0\n" |
70 » » "» clz %0, %0\n" | 69 : "=r"(x) |
71 » » : "=r"(x) : "r"(x)); | 70 : "r"(x)); |
72 » return x; | 71 return x; |
73 } | 72 } |
OLD | NEW |