@@ -67,10 +67,19 @@ const MAX_ATOMIC_SIZE = 8
6767const MAX_POINTERATOMIC_SIZE = 8
6868end
6969
70+
71+ if VERSION < v " 1.12.0"
72+ ptr (typ) = typ* " *"
73+ inttoptr (typ, arg) = " inttoptr i$WORD_SIZE $arg to $(ptr (typ)) "
74+ else
75+ ptr (typ) = " ptr"
76+ inttoptr (_, arg) = " bitcast ptr $arg to ptr"
77+ end
78+
7079# Based on: https://github.com/JuliaLang/julia/blob/v1.6.3/base/atomics.jl
7180for typ in (inttypes... , floattypes... )
7281 lt = llvmtypes[typ]
73- rt = " $lt , $lt * "
82+ rt = " $lt , $( ptr (lt)) "
7483
7584 for ord in orderings
7685 ord in (release, acq_rel) && continue
@@ -84,7 +93,7 @@ for typ in (inttypes..., floattypes...)
8493 @eval function UnsafeAtomics. load (x:: Ptr{$typ} , :: $ (typeof (ord)), :: $ (typeof (sync)))
8594 return llvmcall (
8695 $ ("""
87- %ptr = inttoptr i $WORD_SIZE %0 to $lt *
96+ %ptr = $( inttoptr (lt, " %0 " ))
8897 %rv = load atomic $rt %ptr $ord , align $(sizeof (typ))
8998 ret $lt %rv
9099 """ ),
@@ -110,8 +119,8 @@ for typ in (inttypes..., floattypes...)
110119 @eval function UnsafeAtomics. store! (x:: Ptr{$typ} , v:: $typ , :: $ (typeof (ord)), :: $ (typeof (sync)))
111120 return llvmcall (
112121 $ ("""
113- %ptr = inttoptr i $WORD_SIZE %0 to $lt *
114- store atomic $lt %1, $lt * %ptr $ord , align $(sizeof (typ))
122+ %ptr = $( inttoptr (lt, " %0 " ))
123+ store atomic $lt %1, $( ptr (lt)) %ptr $ord , align $(sizeof (typ))
115124 ret void
116125 """ ),
117126 Cvoid,
@@ -161,13 +170,13 @@ for typ in (inttypes..., floattypes...)
161170 old = llvmcall (
162171 $ (
163172 """
164- %ptr = inttoptr i $WORD_SIZE %0 to $lt *
165- %rs = cmpxchg $lt * %ptr, $lt %1, $lt %2 $success_ordering $failure_ordering
173+ %ptr = $( inttoptr (lt, " %0 " ))
174+ %rs = cmpxchg $( ptr (lt)) %ptr, $lt %1, $lt %2 $success_ordering $failure_ordering
166175 %rv = extractvalue { $lt , i1 } %rs, 0
167176 %s1 = extractvalue { $lt , i1 } %rs, 1
168177 %s8 = zext i1 %s1 to i8
169- %sptr = inttoptr i $WORD_SIZE %3 to i8*
170- store i8 %s8, i8* %sptr
178+ %sptr = $( inttoptr ( " i8 " , " %3 " ))
179+ store i8 %s8, $( ptr ( " i8 " )) %sptr
171180 ret $lt %rv
172181 """
173182 ),
@@ -224,8 +233,8 @@ for typ in (inttypes..., floattypes...)
224233 )
225234 old = llvmcall (
226235 $ ("""
227- %ptr = inttoptr i $WORD_SIZE %0 to $lt *
228- %rv = atomicrmw $rmw $lt * %ptr, $lt %1 $ord
236+ %ptr = $( inttoptr (lt, " %0 " ))
237+ %rv = atomicrmw $rmw $( ptr (lt)) %ptr, $lt %1 $ord
229238 ret $lt %rv
230239 """ ),
231240 $ typ,
244253for sync in syncscopes
245254 if sync == none
246255 # Core.Intrinsics.atomic_fence was introduced in 1.10
247- @eval function UnsafeAtomics. fence (ord:: Ordering , :: $ (typeof (sync)))
248- Core. Intrinsics. atomic_fence (base_ordering (ord))
249- return nothing
256+ if VERSION < v " 1.14.0-DEV.1371"
257+ @eval function UnsafeAtomics. fence (ord:: Ordering , :: $ (typeof (sync)))
258+ Core. Intrinsics. atomic_fence (base_ordering (ord))
259+ return nothing
260+ end
261+ else
262+ @eval function UnsafeAtomics. fence (ord:: Ordering , :: $ (typeof (sync)))
263+ Core. Intrinsics. atomic_fence (base_ordering (ord), :system )
264+ return nothing
265+ end
250266 end
251267 if Sys. ARCH == :x86_64
252268 # FIXME : Disable this once on LLVM 19
0 commit comments