2
2
3
3
using Core. Intrinsics: llvmcall
4
4
5
- import Base: setindex!, getindex, unsafe_convert
5
+ import Base: setindex!, getindex, unsafe_convert, datatype_alignment
6
6
import Base. Sys: ARCH, WORD_SIZE
7
7
8
8
export
@@ -321,9 +321,6 @@ inttype(::Type{Float16}) = Int16
321
321
inttype (:: Type{Float32} ) = Int32
322
322
inttype (:: Type{Float64} ) = Int64
323
323
324
-
325
- alignment (:: Type{T} ) where {T} = ccall (:jl_alignment , Cint, (Any,), T)
326
-
327
324
# All atomic operations have acquire and/or release semantics, depending on
328
325
# whether the load or store values. Most of the time, this is what one wants
329
326
# anyway, and it's only moderately expensive on most hardware.
@@ -335,39 +332,39 @@ for typ in atomictypes
335
332
if VersionNumber (Base. libllvm_version) >= v " 3.8"
336
333
@eval getindex (x:: Atomic{$typ} ) =
337
334
llvmcall ($ """
338
- %rv = load atomic $rt %0 acquire, align $(alignment (typ))
335
+ %rv = load atomic $rt %0 acquire, align $(datatype_alignment (typ))
339
336
ret $lt %rv
340
337
""" , $ typ, Tuple{Ptr{$ typ}}, unsafe_convert (Ptr{$ typ}, x))
341
338
@eval setindex! (x:: Atomic{$typ} , v:: $typ ) =
342
339
llvmcall ($ """
343
- store atomic $lt %1, $lt * %0 release, align $(alignment (typ))
340
+ store atomic $lt %1, $lt * %0 release, align $(datatype_alignment (typ))
344
341
ret void
345
342
""" , Void, Tuple{Ptr{$ typ},$ typ}, unsafe_convert (Ptr{$ typ}, x), v)
346
343
else
347
344
if typ <: Integer
348
345
@eval getindex (x:: Atomic{$typ} ) =
349
346
llvmcall ($ """
350
- %rv = load atomic $rt %0 acquire, align $(alignment (typ))
347
+ %rv = load atomic $rt %0 acquire, align $(datatype_alignment (typ))
351
348
ret $lt %rv
352
349
""" , $ typ, Tuple{Ptr{$ typ}}, unsafe_convert (Ptr{$ typ}, x))
353
350
@eval setindex! (x:: Atomic{$typ} , v:: $typ ) =
354
351
llvmcall ($ """
355
- store atomic $lt %1, $lt * %0 release, align $(alignment (typ))
352
+ store atomic $lt %1, $lt * %0 release, align $(datatype_alignment (typ))
356
353
ret void
357
354
""" , Void, Tuple{Ptr{$ typ},$ typ}, unsafe_convert (Ptr{$ typ}, x), v)
358
355
else
359
356
@eval getindex (x:: Atomic{$typ} ) =
360
357
llvmcall ($ """
361
358
%iptr = bitcast $lt * %0 to $ilt *
362
- %irv = load atomic $irt %iptr acquire, align $(alignment (typ))
359
+ %irv = load atomic $irt %iptr acquire, align $(datatype_alignment (typ))
363
360
%rv = bitcast $ilt %irv to $lt
364
361
ret $lt %rv
365
362
""" , $ typ, Tuple{Ptr{$ typ}}, unsafe_convert (Ptr{$ typ}, x))
366
363
@eval setindex! (x:: Atomic{$typ} , v:: $typ ) =
367
364
llvmcall ($ """
368
365
%iptr = bitcast $lt * %0 to $ilt *
369
366
%ival = bitcast $lt %1 to $ilt
370
- store atomic $ilt %ival, $ilt * %iptr release, align $(alignment (typ))
367
+ store atomic $ilt %ival, $ilt * %iptr release, align $(datatype_alignment (typ))
371
368
ret void
372
369
""" , Void, Tuple{Ptr{$ typ},$ typ}, unsafe_convert (Ptr{$ typ}, x), v)
373
370
end
0 commit comments