You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
When checking whether a
Float32
orFloat64
is finite, both in Crystal code itself via#finite?
and in certain primitive conversions likeFloat64::MAX.to_f32
, the check is done withx != x * 2
. It seems this could generate suboptimal code compared to direct comparisons against infinity: https://godbolt.org/z/zzT8va1oPThere is exactly one binary representation of each signed infinity for
Float32
andFloat64
, and it should be possible to use them directly. Additionally, thellvm.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.The text was updated successfully, but these errors were encountered: