77// Out - of - line LSE atomics helpers. Ported from libgcc library.
88// N = { 1 , 2 , 4 , 8 }
99// M = { 1 , 2 , 4 , 8 , 16 }
10- // ORDER = { 'relax' , 'acq' , 'rel' , 'acq_rel' }
10+ // ORDER = { 'relax' , 'acq' , 'rel' , 'acq_rel' , 'sync' }
1111// Routines implemented:
1212//
1313// iM __aarch64_casM_ORDER(iM expected , iM desired , iM * ptr)
@@ -35,8 +35,8 @@ HIDDEN(___aarch64_have_lse_atomics)
3535#endif
3636
3737// Generate mnemonics for
38- // L_cas: SIZE: 1 , 2 , 4 , 8 , 16 MODEL: 1 , 2 , 3 , 4
39- // L_swp L_ldadd L_ldclr L_ldeor L_ldset: SIZE: 1 , 2 , 4 , 8 MODEL: 1 , 2 , 3 , 4
38+ // L_cas: SIZE: 1 , 2 , 4 , 8 , 16 MODEL: 1 , 2 , 3 , 4 , 5
39+ // L_swp L_ldadd L_ldclr L_ldeor L_ldset: SIZE: 1 , 2 , 4 , 8 MODEL: 1 , 2 , 3 , 4 , 5
4040
4141#if SIZE == 1
4242#define S b
@@ -64,24 +64,44 @@ HIDDEN(___aarch64_have_lse_atomics)
6464#define L
6565#define M 0x000000
6666#define N 0x000000
67+ #define BARRIER
6768#elif MODEL == 2
6869#define SUFF _acq
6970#define A a
7071#define L
7172#define M 0x400000
7273#define N 0x800000
74+ #define BARRIER
7375#elif MODEL == 3
7476#define SUFF _rel
7577#define A
7678#define L l
7779#define M 0x008000
7880#define N 0x400000
81+ #define BARRIER
7982#elif MODEL == 4
8083#define SUFF _acq_rel
8184#define A a
8285#define L l
8386#define M 0x408000
8487#define N 0xc00000
88+ #define BARRIER
89+ #elif MODEL == 5
90+ #define SUFF _sync
91+ #ifdef L_swp
92+ // swp has _acq semantics.
93+ #define A a
94+ #define L
95+ #define M 0x400000
96+ #define N 0x800000
97+ #else
98+ // All other _sync functions have _seq semantics.
99+ #define A a
100+ #define L l
101+ #define M 0x408000
102+ #define N 0xc00000
103+ #endif
104+ #define BARRIER dmb ish
85105#else
86106#error
87107#endif // MODEL
@@ -96,7 +116,12 @@ HIDDEN(___aarch64_have_lse_atomics)
96116#endif
97117
98118#define NAME(BASE) GLUE4(__aarch64_ , BASE , SIZE , SUFF)
119+ #if MODEL == 5
120+ // Drop A for _sync functions.
121+ #define LDXR GLUE3(ld , xr , S)
122+ #else
99123#define LDXR GLUE4(ld , A , xr , S)
124+ #endif
100125#define STXR GLUE4(st , L , xr , S)
101126
102127// Define temporary registers.
@@ -136,9 +161,15 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(NAME(cas))
136161 STXR w(tmp1) , s( 1 ) , [ x2 ]
137162 cbnz w(tmp1) , 0b
1381631 :
164+ BARRIER
139165 ret
140166#else
167+ #if MODEL == 5
168+ // Drop A for _sync functions.
169+ #define LDXP GLUE2(ld , xp)
170+ #else
141171#define LDXP GLUE3(ld , A , xp)
172+ #endif
142173#define STXP GLUE3(st , L , xp)
143174#ifdef HAS_ASM_LSE
144175#define CASP GLUE3(casp , A , L) x0 , x1 , x2 , x3 , [ x4 ]
@@ -159,6 +190,7 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(NAME(cas))
159190 STXP w(tmp2) , x2 , x3 , [ x4 ]
160191 cbnz w(tmp2) , 0b
1611921 :
193+ BARRIER
162194 ret
163195#endif
164196END_COMPILERRT_OUTLINE_FUNCTION(NAME(cas))
@@ -180,6 +212,7 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(NAME(swp))
180212 LDXR s( 0 ) , [ x1 ]
181213 STXR w(tmp1) , s(tmp0) , [ x1 ]
182214 cbnz w(tmp1) , 0b
215+ BARRIER
183216 ret
184217END_COMPILERRT_OUTLINE_FUNCTION(NAME(swp))
185218#endif // L_swp
@@ -224,6 +257,7 @@ DEFINE_COMPILERRT_OUTLINE_FUNCTION_UNMANGLED(NAME(LDNM))
224257 OP s(tmp1) , s( 0 ) , s(tmp0)
225258 STXR w(tmp2) , s(tmp1) , [ x1 ]
226259 cbnz w(tmp2) , 0b
260+ BARRIER
227261 ret
228262END_COMPILERRT_OUTLINE_FUNCTION(NAME(LDNM))
229263#endif // L_ldadd L_ldclr L_ldeor L_ldset
0 commit comments