From ac39e6a0e62c3fbc60f63dcc4d75ea571616b858 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 6 Aug 2024 17:16:03 +0200 Subject: [PATCH 1/2] Add `only-soft-floats` feature to prevent using any intrinsics or arch-specific code --- Cargo.toml | 3 +++ crates/compiler-builtins-smoke-test/Cargo.toml | 1 + src/math/mod.rs | 2 +- src/math/sqrt.rs | 4 ++-- src/math/sqrtf.rs | 4 ++-- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d33ca61c..893a2e19 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,9 @@ unstable = [] # musl libc. musl-reference-tests = ['rand'] +# Used to prevent using any intrinsics or arch-specific code. +only-soft-floats = [] + [workspace] members = [ "crates/compiler-builtins-smoke-test", diff --git a/crates/compiler-builtins-smoke-test/Cargo.toml b/crates/compiler-builtins-smoke-test/Cargo.toml index 695b710f..ec48ca20 100644 --- a/crates/compiler-builtins-smoke-test/Cargo.toml +++ b/crates/compiler-builtins-smoke-test/Cargo.toml @@ -10,3 +10,4 @@ bench = false [features] unstable = [] checked = [] +only-soft-floats = [] diff --git a/src/math/mod.rs b/src/math/mod.rs index 05ebb708..04d3bbb6 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -76,7 +76,7 @@ macro_rules! div { macro_rules! llvm_intrinsically_optimized { (#[cfg($($clause:tt)*)] $e:expr) => { - #[cfg(all(feature = "unstable", $($clause)*))] + #[cfg(all(feature = "unstable", not(feature = "only-soft-floats"), $($clause)*))] { if true { // thwart the dead code lint $e diff --git a/src/math/sqrt.rs b/src/math/sqrt.rs index baa0db9f..a0003cb0 100644 --- a/src/math/sqrt.rs +++ b/src/math/sqrt.rs @@ -92,7 +92,7 @@ pub fn sqrt(x: f64) -> f64 { } } } - #[cfg(target_feature = "sse2")] + #[cfg(all(target_feature = "sse2", not(feature = "only-soft-floats")))] { // Note: This path is unlikely since LLVM will usually have already // optimized sqrt calls into hardware instructions if sse2 is available, @@ -107,7 +107,7 @@ pub fn sqrt(x: f64) -> f64 { _mm_cvtsd_f64(m_sqrt) } } - #[cfg(not(target_feature = "sse2"))] + #[cfg(any(not(target_feature = "sse2"), feature = "only-soft-floats"))] { use core::num::Wrapping; diff --git a/src/math/sqrtf.rs b/src/math/sqrtf.rs index 12bd6002..0cef073e 100644 --- a/src/math/sqrtf.rs +++ b/src/math/sqrtf.rs @@ -27,7 +27,7 @@ pub fn sqrtf(x: f32) -> f32 { } } } - #[cfg(target_feature = "sse")] + #[cfg(all(target_feature = "sse", not(feature = "only-soft-floats")))] { // Note: This path is unlikely since LLVM will usually have already // optimized sqrt calls into hardware instructions if sse is available, @@ -42,7 +42,7 @@ pub fn sqrtf(x: f32) -> f32 { _mm_cvtss_f32(m_sqrt) } } - #[cfg(not(target_feature = "sse"))] + #[cfg(any(not(target_feature = "sse"), feature = "only-soft-floats"))] { const TINY: f32 = 1.0e-30; From 5aeb0be6b06be94119dd7d0d9720e048935cb17b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 7 Aug 2024 11:29:47 +0200 Subject: [PATCH 2/2] Rename `only-soft-floats` feature into `force-soft-floats` --- Cargo.toml | 2 +- crates/compiler-builtins-smoke-test/Cargo.toml | 2 +- src/math/mod.rs | 2 +- src/math/sqrt.rs | 4 ++-- src/math/sqrtf.rs | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 893a2e19..c2388083 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ unstable = [] musl-reference-tests = ['rand'] # Used to prevent using any intrinsics or arch-specific code. -only-soft-floats = [] +force-soft-floats = [] [workspace] members = [ diff --git a/crates/compiler-builtins-smoke-test/Cargo.toml b/crates/compiler-builtins-smoke-test/Cargo.toml index ec48ca20..481d386a 100644 --- a/crates/compiler-builtins-smoke-test/Cargo.toml +++ b/crates/compiler-builtins-smoke-test/Cargo.toml @@ -10,4 +10,4 @@ bench = false [features] unstable = [] checked = [] -only-soft-floats = [] +force-soft-floats = [] diff --git a/src/math/mod.rs b/src/math/mod.rs index 04d3bbb6..a56532dd 100644 --- a/src/math/mod.rs +++ b/src/math/mod.rs @@ -76,7 +76,7 @@ macro_rules! div { macro_rules! llvm_intrinsically_optimized { (#[cfg($($clause:tt)*)] $e:expr) => { - #[cfg(all(feature = "unstable", not(feature = "only-soft-floats"), $($clause)*))] + #[cfg(all(feature = "unstable", not(feature = "force-soft-floats"), $($clause)*))] { if true { // thwart the dead code lint $e diff --git a/src/math/sqrt.rs b/src/math/sqrt.rs index a0003cb0..66cb7659 100644 --- a/src/math/sqrt.rs +++ b/src/math/sqrt.rs @@ -92,7 +92,7 @@ pub fn sqrt(x: f64) -> f64 { } } } - #[cfg(all(target_feature = "sse2", not(feature = "only-soft-floats")))] + #[cfg(all(target_feature = "sse2", not(feature = "force-soft-floats")))] { // Note: This path is unlikely since LLVM will usually have already // optimized sqrt calls into hardware instructions if sse2 is available, @@ -107,7 +107,7 @@ pub fn sqrt(x: f64) -> f64 { _mm_cvtsd_f64(m_sqrt) } } - #[cfg(any(not(target_feature = "sse2"), feature = "only-soft-floats"))] + #[cfg(any(not(target_feature = "sse2"), feature = "force-soft-floats"))] { use core::num::Wrapping; diff --git a/src/math/sqrtf.rs b/src/math/sqrtf.rs index 0cef073e..16cbb2f9 100644 --- a/src/math/sqrtf.rs +++ b/src/math/sqrtf.rs @@ -27,7 +27,7 @@ pub fn sqrtf(x: f32) -> f32 { } } } - #[cfg(all(target_feature = "sse", not(feature = "only-soft-floats")))] + #[cfg(all(target_feature = "sse", not(feature = "force-soft-floats")))] { // Note: This path is unlikely since LLVM will usually have already // optimized sqrt calls into hardware instructions if sse is available, @@ -42,7 +42,7 @@ pub fn sqrtf(x: f32) -> f32 { _mm_cvtss_f32(m_sqrt) } } - #[cfg(any(not(target_feature = "sse"), feature = "only-soft-floats"))] + #[cfg(any(not(target_feature = "sse"), feature = "force-soft-floats"))] { const TINY: f32 = 1.0e-30;