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

Faster floating-point finiteness checks #15013

Open
HertzDevil opened this issue Sep 18, 2024 · 0 comments
Open

Faster floating-point finiteness checks #15013

HertzDevil opened this issue Sep 18, 2024 · 0 comments

Comments

@HertzDevil
Copy link
Contributor

When checking whether a Float32 or Float64 is finite, both in Crystal code itself via #finite? and in certain primitive conversions like Float64::MAX.to_f32, the check is done with x != x * 2. It seems this could generate suboptimal code compared to direct comparisons against infinity: https://godbolt.org/z/zzT8va1oP

There is exactly one binary representation of each signed infinity for Float32 and Float64, and it should be possible to use them directly. Additionally, the llvm.is.fpclass.* intrinsic was introduced in LLVM 15, presumably to handle cases where a floating-point type has more binary representations. We should switch to this intrinsic in both the standard library and the primitive codegen if the LLVM version is new enough.

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

No branches or pull requests

1 participant