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

Fix fastmath for vararg +, *, min, max methods #54513

Merged
merged 2 commits into from
May 29, 2024

Conversation

Zentrik
Copy link
Contributor

@Zentrik Zentrik commented May 17, 2024

Currently using the fastmath vararg +, *, min, max methods only actually sets fastmath if they are specifically overloaded even when the correct 2 argument methods have been defined.
As such, ComplexF32, ComplexF64 do not currently set fastmath when using the vararg methods. This will also fix any other types, such as those in SIMD.jl, which don't overload the vararg methods.

E.g.

x = ComplexF64(1)
f(x) = @fastmath x + x + x

now works correctly.

I see no reason why the vararg methods shouldn't default to using the fastmath 2 argument methods instead of the non fastmath ones, which is the current behaviour.

I also switched the implementation to use afoldl as that's what the non fastmath vararg methods use.

Fixes #54456 and eschnett/SIMD.jl#108.

I don't think checking what instructions llvm decides to use makes sense for checking fastmath is applying correctly.
@KristofferC
Copy link
Sponsor Member

This seems clearly good to me. I think n-arg parsing has shown to be a failure but unfortunately it seems to broken to change it now (#48849).

@KristofferC KristofferC merged commit 9634652 into JuliaLang:master May 29, 2024
10 checks passed
Comment on lines +288 to +289
$op_fast(a::Number, b::Number, c::Number, xs::Number...) =
$op_fast(promote(x,y,c,xs...)...)
Copy link
Contributor

@kimikage kimikage May 30, 2024

Choose a reason for hiding this comment

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

@Zentrik, @KristofferC

a, b, c != x, y, c 😱

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Nice catch, indicates some missing coverage as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should n-arg fastmath addition default to using to 2-arg fastmath addition for all types
3 participants