Skip to content

Commit 4d0dc1e

Browse files
committed
add back jl_gc_alignment for now
1 parent dd37d6e commit 4d0dc1e

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

base/atomics.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
using Core.Intrinsics: llvmcall
44

5-
import Base: setindex!, getindex, unsafe_convert, datatype_alignment
5+
import Base: setindex!, getindex, unsafe_convert
66
import Base.Sys: ARCH, WORD_SIZE
77

88
export
@@ -332,6 +332,9 @@ inttype(::Type{Float16}) = Int16
332332
inttype(::Type{Float32}) = Int32
333333
inttype(::Type{Float64}) = Int64
334334

335+
336+
alignment(::Type{T}) where {T} = ccall(:jl_alignment, Cint, (Csize_t,), sizeof(T))
337+
335338
# All atomic operations have acquire and/or release semantics, depending on
336339
# whether the load or store values. Most of the time, this is what one wants
337340
# anyway, and it's only moderately expensive on most hardware.
@@ -343,13 +346,13 @@ for typ in atomictypes
343346
@eval getindex(x::Atomic{$typ}) =
344347
llvmcall($"""
345348
%ptr = inttoptr i$WORD_SIZE %0 to $lt*
346-
%rv = load atomic $rt %ptr acquire, align $(datatype_alignment(typ))
349+
%rv = load atomic $rt %ptr acquire, align $(alignment(typ))
347350
ret $lt %rv
348351
""", $typ, Tuple{Ptr{$typ}}, unsafe_convert(Ptr{$typ}, x))
349352
@eval setindex!(x::Atomic{$typ}, v::$typ) =
350353
llvmcall($"""
351354
%ptr = inttoptr i$WORD_SIZE %0 to $lt*
352-
store atomic $lt %1, $lt* %ptr release, align $(datatype_alignment(typ))
355+
store atomic $lt %1, $lt* %ptr release, align $(alignment(typ))
353356
ret void
354357
""", Void, Tuple{Ptr{$typ}, $typ}, unsafe_convert(Ptr{$typ}, x), v)
355358

src/julia_internal.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,28 @@ static const int jl_gc_sizeclasses[JL_GC_N_POOLS] = {
192192
// 64, 32, 160, 64, 16, 64, 112, 128, bytes lost
193193
};
194194

195+
STATIC_INLINE int jl_gc_alignment(size_t sz)
196+
{
197+
if (sz == 0)
198+
return sizeof(void*);
199+
#ifdef _P64
200+
(void)sz;
201+
return 16;
202+
#elif defined(_CPU_ARM_) || defined(_CPU_PPC_)
203+
return sz <= 4 ? 8 : 16;
204+
#else
205+
// szclass 8
206+
if (sz <= 4)
207+
return 8;
208+
// szclass 12
209+
if (sz <= 8)
210+
return 4;
211+
// szclass 16+
212+
return 16;
213+
#endif
214+
}
215+
JL_DLLEXPORT int jl_alignment(size_t sz);
216+
195217
STATIC_INLINE size_t JL_CONST_FUNC jl_gc_alignsz(size_t sz, size_t alignment)
196218
{
197219
// The pools are aligned with JL_HEAP_ALIGNMENT and no bigger alignment is possible.

src/threading.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,14 @@ void jl_init_threading(void)
820820
void jl_start_threads(void) { }
821821

822822
#endif // !JULIA_ENABLE_THREADING
823+
824+
// Make gc alignment available for threading
825+
// see threads.jl alignment
826+
JL_DLLEXPORT int jl_alignment(size_t sz)
827+
{
828+
return jl_gc_alignment(sz);
829+
}
830+
823831
#ifdef __cplusplus
824832
}
825833
#endif

0 commit comments

Comments
 (0)