Skip to content

Commit

Permalink
Julia 1.5 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Sep 20, 2021
1 parent 47105fe commit fae0a11
Showing 1 changed file with 49 additions and 45 deletions.
94 changes: 49 additions & 45 deletions src/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Exponentiation operator, returns `x` raised to the power `y`.

logkxy = dmul(logkx, y)

if (VERSION v"1.6") && (T === Float64)
@static if VERSION v"1.6"
result = exp_hilo(logkxy.hi, logkxy.lo, Val(ℯ), VectorizationBase.has_feature(Val(:x86_64_avx512f)))
else
result = expk(logkxy)
Expand All @@ -34,50 +34,54 @@ Exponentiation operator, returns `x` raised to the power `y`.
end
@inline pow_fast(x, y) = exp2(y*log2_fast(x))

const J_TABLE_BASE = Ref(Base.Math.J_TABLE)
@inline base_exp_table_pointer() = VectorizationBase.stridedpointer(Base.unsafe_convert(Ptr{UInt64}, pointer_from_objref(J_TABLE_BASE)), VectorizationBase.LayoutPointers.StrideIndex{1,(1,),1}((StaticInt{8}(),), (StaticInt{0}(),)))

@inline function exp_hilo(x::Union{Float64,AbstractSIMD{<:Any,Float64}}, xlo::Union{Float64,AbstractSIMD{<:Any,Float64}}, ::Val{B}, ::False) where {B}
N_float = muladd(x, VectorizationBase.LogBo256INV(Val{B}(), Float64), VectorizationBase.MAGIC_ROUND_CONST(Float64))
N = VectorizationBase.target_trunc(reinterpret(UInt64, N_float))
N_float = N_float - VectorizationBase.MAGIC_ROUND_CONST(Float64)
r = VectorizationBase.fast_fma(N_float, VectorizationBase.LogBo256U(Val{B}(), Float64), x, fma_fast())
r = VectorizationBase.fast_fma(N_float, VectorizationBase.LogBo256L(Val{B}(), Float64), r, fma_fast())
# @show (N & 0x000000ff) % Int
j = vload(base_exp_table_pointer(), (N & 0x000000ff,))
jU = reinterpret(Float64, Base.Math.JU_CONST | (j&Base.Math.JU_MASK))
jL = reinterpret(Float64, Base.Math.JL_CONST | (j >> 8))
k = N >>> 0x00000008
very_small = muladd(jU, VectorizationBase.expm1b_kernel(Val{B}(), r), jL)
small_part = muladd(jU, xlo, very_small) + jU
# small_part = reinterpret(UInt64, vfmadd(js, expm1b_kernel(Val{B}(), r), js))
# return reinterpret(Float64, small_part), r, k, N_float, js
twopk = (k % UInt64) << 0x0000000000000034
res = reinterpret(Float64, twopk + reinterpret(UInt64, small_part))
return res
end
@inline function exp_hilo(x::Union{Float64,AbstractSIMD{<:Any,Float64}}, xlo::Union{Float64,AbstractSIMD{<:Any,Float64}}, ::Val{B}, ::True) where {B}
N_float = muladd(x, VectorizationBase.LogBo256INV(Val{B}(), Float64), VectorizationBase.MAGIC_ROUND_CONST(Float64))
N = VectorizationBase.target_trunc(reinterpret(UInt64, N_float))
N_float = N_float - VectorizationBase.MAGIC_ROUND_CONST(Float64)
r = fma(N_float, VectorizationBase.LogBo256U(Val{B}(), Float64), x)
r = fma(N_float, VectorizationBase.LogBo256L(Val{B}(), Float64), r)
# @show (N & 0x000000ff) % Int
# @show N N & 0x000000ff
j = vload(base_exp_table_pointer(), (N & 0x000000ff,))
jU = reinterpret(Float64, Base.Math.JU_CONST | (j&Base.Math.JU_MASK))
jL = reinterpret(Float64, Base.Math.JL_CONST | (j >> 8))
# @show N & 0x000000ff j jU jL
# k = N >>> 0x00000008
# small_part = reinterpret(UInt64, vfmadd(js, expm1b_kernel(Val{B}(), r), js))
very_small = muladd(jU, VectorizationBase.expm1b_kernel(Val{B}(), r), jL)
small_part = muladd(jU, xlo, very_small) + jU
# small_part = vfmadd(js, expm1b_kernel(Val{B}(), r), js)
# return reinterpret(Float64, small_part), r, k, N_float, js
res = VectorizationBase.vscalef(small_part, 0.00390625*N_float)
# twopk = (k % UInt64) << 0x0000000000000034
# res = reinterpret(Float64, twopk + small_part)
return res
@static if VERSION v"1.6"
@inline exp_hilo(x::Union{Float32,AbstractSIMD{<:Any,Float32}}, xlo::Union{Float32,AbstractSIMD{<:Any,Float32}}, ::Val{B}, _) where {B} = expk(Double(x, xlo))

const J_TABLE_BASE = Ref(Base.Math.J_TABLE)
@inline base_exp_table_pointer() = VectorizationBase.stridedpointer(Base.unsafe_convert(Ptr{UInt64}, pointer_from_objref(J_TABLE_BASE)), VectorizationBase.LayoutPointers.StrideIndex{1,(1,),1}((StaticInt{8}(),), (StaticInt{0}(),)))

@inline function exp_hilo(x::Union{Float64,AbstractSIMD{<:Any,Float64}}, xlo::Union{Float64,AbstractSIMD{<:Any,Float64}}, ::Val{B}, ::False) where {B}
N_float = muladd(x, VectorizationBase.LogBo256INV(Val{B}(), Float64), VectorizationBase.MAGIC_ROUND_CONST(Float64))
N = VectorizationBase.target_trunc(reinterpret(UInt64, N_float))
N_float = N_float - VectorizationBase.MAGIC_ROUND_CONST(Float64)
r = VectorizationBase.fast_fma(N_float, VectorizationBase.LogBo256U(Val{B}(), Float64), x, fma_fast())
r = VectorizationBase.fast_fma(N_float, VectorizationBase.LogBo256L(Val{B}(), Float64), r, fma_fast())
# @show (N & 0x000000ff) % Int
j = vload(base_exp_table_pointer(), (N & 0x000000ff,))
jU = reinterpret(Float64, Base.Math.JU_CONST | (j&Base.Math.JU_MASK))
jL = reinterpret(Float64, Base.Math.JL_CONST | (j >> 8))
k = N >>> 0x00000008
very_small = muladd(jU, VectorizationBase.expm1b_kernel(Val{B}(), r), jL)
small_part = muladd(jU, xlo, very_small) + jU
# small_part = reinterpret(UInt64, vfmadd(js, expm1b_kernel(Val{B}(), r), js))
# return reinterpret(Float64, small_part), r, k, N_float, js
twopk = (k % UInt64) << 0x0000000000000034
res = reinterpret(Float64, twopk + reinterpret(UInt64, small_part))
return res
end
@inline function exp_hilo(x::Union{Float64,AbstractSIMD{<:Any,Float64}}, xlo::Union{Float64,AbstractSIMD{<:Any,Float64}}, ::Val{B}, ::True) where {B}
N_float = muladd(x, VectorizationBase.LogBo256INV(Val{B}(), Float64), VectorizationBase.MAGIC_ROUND_CONST(Float64))
N = VectorizationBase.target_trunc(reinterpret(UInt64, N_float))
N_float = N_float - VectorizationBase.MAGIC_ROUND_CONST(Float64)
r = fma(N_float, VectorizationBase.LogBo256U(Val{B}(), Float64), x)
r = fma(N_float, VectorizationBase.LogBo256L(Val{B}(), Float64), r)
# @show (N & 0x000000ff) % Int
# @show N N & 0x000000ff
j = vload(base_exp_table_pointer(), (N & 0x000000ff,))
jU = reinterpret(Float64, Base.Math.JU_CONST | (j&Base.Math.JU_MASK))
jL = reinterpret(Float64, Base.Math.JL_CONST | (j >> 8))
# @show N & 0x000000ff j jU jL
# k = N >>> 0x00000008
# small_part = reinterpret(UInt64, vfmadd(js, expm1b_kernel(Val{B}(), r), js))
very_small = muladd(jU, VectorizationBase.expm1b_kernel(Val{B}(), r), jL)
small_part = muladd(jU, xlo, very_small) + jU
# small_part = vfmadd(js, expm1b_kernel(Val{B}(), r), js)
# return reinterpret(Float64, small_part), r, k, N_float, js
res = VectorizationBase.vscalef(small_part, 0.00390625*N_float)
# twopk = (k % UInt64) << 0x0000000000000034
# res = reinterpret(Float64, twopk + small_part)
return res
end
end


Expand Down

2 comments on commit fae0a11

@chriselrod
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/45206

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.27 -m "<description of version>" fae0a1165f3934f074885ef6357a8ac5469d086b
git push origin v0.6.27

Please sign in to comment.