Skip to content

Commit

Permalink
Add a few precompiles and remove some unnecessary definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Jan 10, 2021
1 parent 280ed2f commit 2dd30f4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
19 changes: 6 additions & 13 deletions src/SLEEFPirates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ include("misc.jl") # miscallenous math functions including pow and cbrt
# include("sleef.jl")
# include("xsimd.jl")

@inline Base.exp(x::Vec) = exp(x)

# fallback definitions

for func in (:sin, :cos, :tan, :asin, :acos, :atan, :sinh, :cosh, :tanh,
Expand Down Expand Up @@ -184,18 +182,13 @@ for func in (:atan, :hypot, :pow)
end
ldexp(x::Float16, q::Int) = Float16(ldexpk(Float32(x), q))

@inline logit(x) = log(Base.FastMath.div_fast(x,Base.FastMath.sub_fast(1,x)))
@inline logit(x::AbstractSIMD{W,T}) where {W,T} = log(x / (vbroadcast(Val{W}(),one(T)) - x))
@inline invlogit(x) = Base.FastMath.inv_fast(Base.FastMath.add_fast(1, exp(Base.FastMath.sub_fast(x))))
@inline invlogit(x::AbstractSIMD{W,T}) where {W,T} = (o = vbroadcast(Val{W}(),one(T)); (o / (o + exp(-x))))
@inline nlogit(x) = log(Base.FastMath.div_fast(Base.FastMath.sub_fast(1,x), x))
@inline nlogit(x::AbstractSIMD{W,T}) where {W,T} = log((vbroadcast(Val{W}(),one(T)) - x) / x)
@inline ninvlogit(x) = Base.FastMath.inv_fast(Base.FastMath.add_fast(1, exp(x)))
@inline ninvlogit(x::AbstractSIMD{W,T}) where {W,T} = inv(vbroadcast(Val{W}(), one(T)) + exp(x))
@inline log1m(x) = Base.log1p(Base.FastMath.sub_fast(x))
@inline log1m(v::AbstractSIMD{W,T}) where {W,T} = log1p(-v)
@inline logit(x) = log(Base.FastMath.div_fast(x,Base.FastMath.sub_fast(one(x),x)))
@inline invlogit(x) = Base.FastMath.inv_fast(Base.FastMath.add_fast(one(x), exp(Base.FastMath.sub_fast(x))))
@inline nlogit(x) = log(Base.FastMath.div_fast(Base.FastMath.sub_fast(one(x),x), x))
@inline ninvlogit(x) = Base.FastMath.inv_fast(Base.FastMath.add_fast(one(x), exp(x)))
@inline log1m(x) = log1p(Base.FastMath.sub_fast(x))
@inline function tanh_fast(x)
exp2xm1 = expm1(x + x)
exp2xm1 = expm1(Base.FastMath.add_fast(x, x))
exp2xm1 / (exp2xm1 + typeof(x)(2))
end

Expand Down
4 changes: 0 additions & 4 deletions src/double.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ end
@inline function Double(x::Vec, y::Vec)
Double(Vec(data(x)), Vec(data(y)))
end
@inline promote_vtype(::Type{Mask{W,U}}, ::Type{Double{V}}) where {W, U, T, V <: AbstractSIMD{W,T}} = Double{V}
@inline promote_vtype(::Type{Double{V}}, ::Type{Mask{W,U}}) where {W, U, T, V <: AbstractSIMD{W,T}} = Double{V}
@inline promote_vtype(::Type{Mask{W,U}}, ::Type{Double{T}}) where {W, U, T <: Number} = Double{Vec{W,T}}
@inline promote_vtype(::Type{Double{T}}, ::Type{Mask{W,U}}) where {W, U, T <: Number} = Double{Vec{W,T}}
@inline Base.convert(::Type{Double{V}}, v::Vec) where {W,T,V <: AbstractSIMD{W,T}} = Double(convert(V, v), vzero(V))
@inline Base.convert(::Type{Double{V}}, v::V) where {V <: AbstractSIMD} = Double(v, vzero(V))
# @inline Base.convert(::Type{Double{V}}, m::Mask) where {V} = m
Expand Down
6 changes: 6 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
function _precompile_()
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
for T (Float32,Float64)
W = VectorizationBase.pick_vector_width(T)
for f (log, exp, sin, cos, tan, tanh, tanh_fast)
precompile(f, (Vec{W, T}, ))
end
end
end

0 comments on commit 2dd30f4

Please sign in to comment.