Skip to content

Commit 8524dc5

Browse files
committed
Merge commit 4bb2416d42eb from llvm-project (by Jessica Clarke):
[builtins][AArch64] Implement _sync out-of-line atomics Whilst Clang does not use these, recent GCC does, and so on systems such as FreeBSD that wish to use compiler-rt as the system runtime library but also wish to support building programs with GCC these interfaces are needed. This is a light adaptation of the code committed to GCC by Sebastian Pop <[email protected]>, relicensed with permission for use in compiler-rt. Fixes llvm/llvm-project#63483 Reviewed By: sebpop, MaskRay Differential Revision: https://reviews.llvm.org/D158536 Reviewed by: dim MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D41716
1 parent c190fb3 commit 8524dc5

File tree

2 files changed

+38
-4
lines changed
  • contrib/llvm-project/compiler-rt/lib/builtins/aarch64
  • lib/libcompiler_rt

2 files changed

+38
-4
lines changed

contrib/llvm-project/compiler-rt/lib/builtins/aarch64/lse.S

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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
138163
1:
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
161192
1:
193+
BARRIER
162194
ret
163195
#endif
164196
END_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
184217
END_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
228262
END_COMPILERRT_OUTLINE_FUNCTION(NAME(LDNM))
229263
#endif // L_ldadd L_ldclr L_ldeor L_ldset

lib/libcompiler_rt/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ MK_WERROR.gcc= no
2222
.if ${MACHINE_CPUARCH} == "aarch64"
2323
. for pat in cas swp ldadd ldclr ldeor ldset
2424
. for size in 1 2 4 8 16
25-
. for model in 1 2 3 4
25+
. for model in 1 2 3 4 5
2626
. if ${pat} == "cas" || ${size} != "16"
2727
# Use .for to define lse_name, to get a special loop-local variable
2828
. for lse_name in outline_atomic_${pat}${size}_${model}.S

0 commit comments

Comments
 (0)