Skip to content

Commit

Permalink
remove jl_alignment in favour of datatype_alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed May 20, 2017
1 parent 295f1ef commit cf1f1e8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
17 changes: 7 additions & 10 deletions base/atomics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using Core.Intrinsics: llvmcall

import Base: setindex!, getindex, unsafe_convert
import Base: setindex!, getindex, unsafe_convert, datatype_alignment
import Base.Sys: ARCH, WORD_SIZE

export
Expand Down Expand Up @@ -321,9 +321,6 @@ inttype(::Type{Float16}) = Int16
inttype(::Type{Float32}) = Int32
inttype(::Type{Float64}) = Int64


alignment(::Type{T}) where {T} = ccall(:jl_alignment, Cint, (Any,), T)

# All atomic operations have acquire and/or release semantics, depending on
# whether the load or store values. Most of the time, this is what one wants
# anyway, and it's only moderately expensive on most hardware.
Expand All @@ -335,39 +332,39 @@ for typ in atomictypes
if VersionNumber(Base.libllvm_version) >= v"3.8"
@eval getindex(x::Atomic{$typ}) =
llvmcall($"""
%rv = load atomic $rt %0 acquire, align $(alignment(typ))
%rv = load atomic $rt %0 acquire, align $(datatype_alignment(typ))
ret $lt %rv
""", $typ, Tuple{Ptr{$typ}}, unsafe_convert(Ptr{$typ}, x))
@eval setindex!(x::Atomic{$typ}, v::$typ) =
llvmcall($"""
store atomic $lt %1, $lt* %0 release, align $(alignment(typ))
store atomic $lt %1, $lt* %0 release, align $(datatype_alignment(typ))
ret void
""", Void, Tuple{Ptr{$typ},$typ}, unsafe_convert(Ptr{$typ}, x), v)
else
if typ <: Integer
@eval getindex(x::Atomic{$typ}) =
llvmcall($"""
%rv = load atomic $rt %0 acquire, align $(alignment(typ))
%rv = load atomic $rt %0 acquire, align $(datatype_alignment(typ))
ret $lt %rv
""", $typ, Tuple{Ptr{$typ}}, unsafe_convert(Ptr{$typ}, x))
@eval setindex!(x::Atomic{$typ}, v::$typ) =
llvmcall($"""
store atomic $lt %1, $lt* %0 release, align $(alignment(typ))
store atomic $lt %1, $lt* %0 release, align $(datatype_alignment(typ))
ret void
""", Void, Tuple{Ptr{$typ},$typ}, unsafe_convert(Ptr{$typ}, x), v)
else
@eval getindex(x::Atomic{$typ}) =
llvmcall($"""
%iptr = bitcast $lt* %0 to $ilt*
%irv = load atomic $irt %iptr acquire, align $(alignment(typ))
%irv = load atomic $irt %iptr acquire, align $(datatype_alignment(typ))
%rv = bitcast $ilt %irv to $lt
ret $lt %rv
""", $typ, Tuple{Ptr{$typ}}, unsafe_convert(Ptr{$typ}, x))
@eval setindex!(x::Atomic{$typ}, v::$typ) =
llvmcall($"""
%iptr = bitcast $lt* %0 to $ilt*
%ival = bitcast $lt %1 to $ilt
store atomic $ilt %ival, $ilt* %iptr release, align $(alignment(typ))
store atomic $ilt %ival, $ilt* %iptr release, align $(datatype_alignment(typ))
ret void
""", Void, Tuple{Ptr{$typ},$typ}, unsafe_convert(Ptr{$typ}, x), v)
end
Expand Down
2 changes: 0 additions & 2 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ extern jl_mutex_t gc_perm_lock;
void *jl_gc_perm_alloc_nolock(size_t sz, int zero);
void *jl_gc_perm_alloc(size_t sz, int zero);

JL_DLLEXPORT int jl_alignment(void* ty);

#define JL_SMALL_BYTE_ALIGNMENT 16
#define JL_CACHE_BYTE_ALIGNMENT 64
#define GC_MAX_SZCLASS (2032-sizeof(void*))
Expand Down
9 changes: 0 additions & 9 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,15 +832,6 @@ void jl_init_threading(void)
void jl_start_threads(void) { }

#endif // !JULIA_ENABLE_THREADING

// Make gc alignment available for threading
// see threads.jl alignment
JL_DLLEXPORT int jl_alignment(void* ty)
{
assert(jl_is_datatype(ty));
return jl_datatype_align(ty);
}

#ifdef __cplusplus
}
#endif

0 comments on commit cf1f1e8

Please sign in to comment.