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

Use native fmin/fmax in aarch64 #47814

Merged
merged 7 commits into from
Jan 3, 2023
Merged
Changes from 3 commits
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
24 changes: 21 additions & 3 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -851,26 +851,44 @@ minmax(x::T, y::T) where {T<:AbstractFloat} = min(x, y), max(x, y)

_isless(x::Float16, y::Float16) = signbit(widen(x) - widen(y))

Base.@assume_effects :total @inline llvm_min(x::Float64, y::Float64) = ccall("llvm.minimum.f64", llvmcall, Float64, (Float64, Float64), x, y)
Base.@assume_effects :total @inline llvm_min(x::Float32, y::Float32) = ccall("llvm.minimum.f32", llvmcall, Float32, (Float32, Float32), x, y)
Base.@assume_effects :total @inline llvm_max(x::Float64, y::Float64) = ccall("llvm.maximum.f64", llvmcall, Float64, (Float64, Float64), x, y)
Base.@assume_effects :total @inline llvm_max(x::Float32, y::Float32) = ccall("llvm.maximum.f32", llvmcall, Float32, (Float32, Float32), x, y)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can define these functions only if has_native_fminmax?


const has_native_fminmax = Sys.ARCH === :aarch64
function min(x::T, y::T) where {T<:Union{Float32,Float64}}
if has_native_fminmax
gbaraldi marked this conversation as resolved.
Show resolved Hide resolved
return llvm_min(x,y)
else
Copy link
Contributor

@giordano giordano Dec 6, 2022

Choose a reason for hiding this comment

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

Indentation below is off now. Maybe just end here?

diff = x - y
argmin = ifelse(signbit(diff), x, y)
anynan = isnan(x)|isnan(y)
ifelse(anynan, diff, argmin)
return ifelse(anynan, diff, argmin)
end
end

function max(x::T, y::T) where {T<:Union{Float32,Float64}}
if has_native_fminmax
return llvm_max(x,y)
else
diff = x - y
argmax = ifelse(signbit(diff), y, x)
anynan = isnan(x)|isnan(y)
ifelse(anynan, diff, argmax)
return ifelse(anynan, diff, argmax)
end
end

function minmax(x::T, y::T) where {T<:Union{Float32,Float64}}
if has_native_fminmax
return llvm_min(x, y), llvm_max(x, y)
else
diff = x - y
sdiff = signbit(diff)
min, max = ifelse(sdiff, x, y), ifelse(sdiff, y, x)
anynan = isnan(x)|isnan(y)
ifelse(anynan, diff, min), ifelse(anynan, diff, max)
return ifelse(anynan, diff, min), ifelse(anynan, diff, max)
end
end

"""
Expand Down