From 11c43c0c160539b6d040539b668e0142769537a5 Mon Sep 17 00:00:00 2001 From: Caleb Zulawski Date: Fri, 21 Jul 2023 15:33:09 -0400 Subject: [PATCH] Fix is_subnormal on architectures that flush subnormals to zero --- crates/core_simd/src/elements/float.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/core_simd/src/elements/float.rs b/crates/core_simd/src/elements/float.rs index 501c1c5ddd3..d700011ff9c 100644 --- a/crates/core_simd/src/elements/float.rs +++ b/crates/core_simd/src/elements/float.rs @@ -336,7 +336,10 @@ fn is_finite(self) -> Self::Mask { #[inline] fn is_subnormal(self) -> Self::Mask { - self.abs().simd_ne(Self::splat(0.0)) & (self.to_bits() & Self::splat(Self::Scalar::INFINITY).to_bits()).simd_eq(Simd::splat(0)) + // On some architectures (e.g. armv7 and some ppc) subnormals are flushed to zero, + // so this comparison must be done with integers. + let not_zero = self.abs().to_bits().simd_ne(Self::splat(0.0).to_bits()); + not_zero & (self.to_bits() & Self::splat(Self::Scalar::INFINITY).to_bits()).simd_eq(Simd::splat(0)) } #[inline]