Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make exp(::Float32) and friends vectorize #44865

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions base/special/exp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,25 +267,21 @@ end
twopk = Int64(k) << 52
return reinterpret(T, twopk + reinterpret(Int64, small_part))
end

oscardssmith marked this conversation as resolved.
Show resolved Hide resolved
@inline function exp_impl(x::Float32, base)
T = Float32
bad = (abs(x) <= SUBNORM_EXP(base, T))
oscardssmith marked this conversation as resolved.
Show resolved Hide resolved
N_float = round(x*LogBINV(base, T))
N = unsafe_trunc(Int32, N_float)
r = muladd(N_float, LogBU(base, T), x)
r = muladd(N_float, LogBL(base, T), r)
small_part = expb_kernel(base, r)
if !(abs(x) <= SUBNORM_EXP(base, T))
x > MAX_EXP(base, T) && return Inf32
x < MIN_EXP(base, T) && return 0.0f0
if N <= Int32(-24)
twopk = reinterpret(T, (N+Int32(151)) << Int32(23))
return (twopk*small_part)*(2f0^(-24))
end
N == 128 && return small_part * T(2.0) * T(2.0)^127
end
twopk = reinterpret(T, (N+Int32(127)) << Int32(23))
return twopk*small_part
power = (N+Int32(127))
x > MAX_EXP(base, T) && return Inf32
x < MIN_EXP(base, T) && return 0.0f0
x <= -SUBNORM_EXP(base, T) && (power+=Int32(24); small_part*=Float32(0x1p-24))
oscardssmith marked this conversation as resolved.
Show resolved Hide resolved
N == 128 && (power-=Int32(1); small_part*=2f0)
oscardssmith marked this conversation as resolved.
Show resolved Hide resolved
return small_part * reinterpret(T, power << Int32(23))
end

@inline function exp_impl_fast(x::Float32, base)
Expand Down