From cbbc9430b2fdf274680fc8269ec35b46d9f9caa7 Mon Sep 17 00:00:00 2001 From: royalmustard Date: Fri, 20 May 2022 15:22:00 +0200 Subject: [PATCH 1/2] added f64 support for nightly-simd --- src/lib.rs | 24 ++++++++----- src/utils/sdp_matrix.rs | 75 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ad398f99..6630ee02 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,13 +24,13 @@ the rust programming language. not(feature = "simd-nightly") ))] std::compile_error!("The `simd-is-enabled` feature should not be enabled explicitly. Please enable the `simd-stable` or the `simd-nightly` feature instead."); -#[cfg(all(feature = "simd-is-enabled", feature = "enhanced-determinism"))] +// #[cfg(all(feature = "simd-is-enabled", feature = "enhanced-determinism"))] +// std::compile_error!( +// "SIMD cannot be enabled when the `enhanced-determinism` feature is also enabled." +// ); +#[cfg(all(feature = "f64", feature="simd-stable"))] std::compile_error!( - "SIMD cannot be enabled when the `enhanced-determinism` feature is also enabled." -); -#[cfg(all(feature = "simd-is-enabled", feature = "f64"))] -std::compile_error!( - "Explicit SIMD optimization are not yet supported when the f64 feature is enabled." + "Explicit SIMD optimizations on stable are not yet supported when the f64 feature is enabled." ); macro_rules! array( @@ -254,7 +254,7 @@ mod simd { mod simd { #[allow(unused_imports)] #[cfg(feature = "simd-nightly")] - use simba::simd::{f32x16, f32x4, f32x8, m32x16, m32x4, m32x8, u8x16, u8x4, u8x8}; + use simba::simd::{f32x16, f32x4, f32x8, m32x16, m32x4, m32x8, u8x16, u8x4, u8x8, f64x4, m64x4}; #[cfg(feature = "simd-stable")] use simba::simd::{WideBoolF32x4, WideF32x4}; @@ -268,12 +268,18 @@ mod simd { #[cfg(not(feature = "simd-nightly"))] /// A SIMD bool with SIMD_WIDTH lanes. pub type SimdBool = WideBoolF32x4; - #[cfg(feature = "simd-nightly")] + #[cfg(all(feature = "simd-nightly", feature="f32"))] /// A SIMD float with SIMD_WIDTH lanes. pub type SimdReal = f32x4; - #[cfg(feature = "simd-nightly")] + #[cfg(all(feature = "simd-nightly", feature="f64"))] + /// A SIMD float with SIMD_WIDTH lanes. + pub type SimdReal = f64x4; + #[cfg(all(feature = "simd-nightly", feature="f32"))] /// A bool float with SIMD_WIDTH lanes. pub type SimdBool = m32x4; + #[cfg(all(feature = "simd-nightly", feature="f64"))] + /// A bool float with SIMD_WIDTH lanes. + pub type SimdBool = m64x4; // pub const SIMD_WIDTH: usize = 8; // pub const SIMD_LAST_INDEX: usize = 7; diff --git a/src/utils/sdp_matrix.rs b/src/utils/sdp_matrix.rs index 203203d8..9d0f3a5e 100644 --- a/src/utils/sdp_matrix.rs +++ b/src/utils/sdp_matrix.rs @@ -359,7 +359,7 @@ where } } -#[cfg(feature = "simd-nightly")] +#[cfg(all(feature = "simd-nightly", feature="f32"))] impl From<[SdpMatrix3; 8]> for SdpMatrix3 { fn from(data: [SdpMatrix3; 8]) -> Self { SdpMatrix3 { @@ -427,7 +427,7 @@ impl From<[SdpMatrix3; 8]> for SdpMatrix3 { } } -#[cfg(feature = "simd-nightly")] +#[cfg(all(feature = "simd-nightly", feature="f32"))] impl From<[SdpMatrix3; 16]> for SdpMatrix3 { fn from(data: [SdpMatrix3; 16]) -> Self { SdpMatrix3 { @@ -542,3 +542,74 @@ impl From<[SdpMatrix3; 16]> for SdpMatrix3 { } } } + + +#[cfg(all(feature = "simd-nightly", feature="f64", not(feature="f32")))] +impl From<[SdpMatrix3; 8]> for SdpMatrix3 { + fn from(data: [SdpMatrix3; 8]) -> Self { + SdpMatrix3 { + m11: simba::simd::f64x8::from([ + data[0].m11, + data[1].m11, + data[2].m11, + data[3].m11, + data[4].m11, + data[5].m11, + data[6].m11, + data[7].m11, + ]), + m12: simba::simd::f64x8::from([ + data[0].m12, + data[1].m12, + data[2].m12, + data[3].m12, + data[4].m12, + data[5].m12, + data[6].m12, + data[7].m12, + ]), + m13: simba::simd::f64x8::from([ + data[0].m13, + data[1].m13, + data[2].m13, + data[3].m13, + data[4].m13, + data[5].m13, + data[6].m13, + data[7].m13, + ]), + m22: simba::simd::f64x8::from([ + data[0].m22, + data[1].m22, + data[2].m22, + data[3].m22, + data[4].m22, + data[5].m22, + data[6].m22, + data[7].m22, + ]), + m23: simba::simd::f64x8::from([ + data[0].m23, + data[1].m23, + data[2].m23, + data[3].m23, + data[4].m23, + data[5].m23, + data[6].m23, + data[7].m23, + ]), + m33: simba::simd::f64x8::from([ + data[0].m33, + data[1].m33, + data[2].m33, + data[3].m33, + data[4].m33, + data[5].m33, + data[6].m33, + data[7].m33, + ]), + } + } +} + + From 768461be350d1f874967ba0d6c40d24475960e86 Mon Sep 17 00:00:00 2001 From: royalmustard <36129876+royalmustard@users.noreply.github.com> Date: Fri, 20 May 2022 17:19:47 +0200 Subject: [PATCH 2/2] Remove commented out compile warning --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6630ee02..c0ed0d60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,10 +24,10 @@ the rust programming language. not(feature = "simd-nightly") ))] std::compile_error!("The `simd-is-enabled` feature should not be enabled explicitly. Please enable the `simd-stable` or the `simd-nightly` feature instead."); -// #[cfg(all(feature = "simd-is-enabled", feature = "enhanced-determinism"))] -// std::compile_error!( -// "SIMD cannot be enabled when the `enhanced-determinism` feature is also enabled." -// ); +#[cfg(all(feature = "simd-is-enabled", feature = "enhanced-determinism"))] + std::compile_error!( + "SIMD cannot be enabled when the `enhanced-determinism` feature is also enabled." +); #[cfg(all(feature = "f64", feature="simd-stable"))] std::compile_error!( "Explicit SIMD optimizations on stable are not yet supported when the f64 feature is enabled."