From 84bd60e4a5b88c9aa824797c8a444945b46e96b2 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 22 Sep 2020 17:57:29 +0200 Subject: Fix compilation when SIMD is not enabled. --- src/geometry/waabb.rs | 89 --------------------------------------------------- src/lib.rs | 15 ++++++--- src/utils.rs | 15 --------- 3 files changed, 11 insertions(+), 108 deletions(-) diff --git a/src/geometry/waabb.rs b/src/geometry/waabb.rs index 0a90801..4981373 100644 --- a/src/geometry/waabb.rs +++ b/src/geometry/waabb.rs @@ -5,14 +5,12 @@ use crate::math::{Point, Vector, SIMD_WIDTH}; use crate::utils; use ncollide::bounding_volume::AABB; use num::{One, Zero}; -#[cfg(feature = "simd-is-enabled")] use { crate::math::{SimdBool, SimdFloat}, simba::simd::{SimdPartialOrd, SimdValue}, }; #[derive(Debug, Copy, Clone)] -#[cfg(feature = "simd-is-enabled")] pub(crate) struct WRay { pub origin: Point, pub dir: Vector, @@ -28,26 +26,11 @@ impl WRay { } #[derive(Debug, Copy, Clone)] -#[cfg(not(feature = "simd-is-enabled"))] -pub(crate) struct WRay { - pub origin: [Point; SIMD_WIDTH], - pub dir: [Vector; SIMD_WIDTH], -} - -#[derive(Debug, Copy, Clone)] -#[cfg(feature = "simd-is-enabled")] pub(crate) struct WAABB { pub mins: Point, pub maxs: Point, } -#[derive(Debug, Copy, Clone)] -#[cfg(not(feature = "simd-is-enabled"))] -pub(crate) struct WAABB { - pub mins: [Point; SIMD_WIDTH], - pub maxs: [Point; SIMD_WIDTH], -} - #[cfg(feature = "serde-serialize")] impl serde::Serialize for WAABB { fn serialize(&self, serializer: S) -> Result @@ -56,24 +39,17 @@ impl serde::Serialize for WAABB { { use serde::ser::SerializeStruct; - #[cfg(feature = "simd-is-enabled")] let mins: Point<[f32; SIMD_WIDTH]> = Point::from( self.mins .coords .map(|e| array![|ii| e.extract(ii); SIMD_WIDTH]), ); - #[cfg(feature = "simd-is-enabled")] let maxs: Point<[f32; SIMD_WIDTH]> = Point::from( self.maxs .coords .map(|e| array![|ii| e.extract(ii); SIMD_WIDTH]), ); - #[cfg(not(feature = "simd-is-enabled"))] - let mins = self.mins; - #[cfg(not(feature = "simd-is-enabled"))] - let maxs = self.maxs; - let mut waabb = serializer.serialize_struct("WAABB", 2)?; waabb.serialize_field("mins", &mins)?; waabb.serialize_field("maxs", &maxs)?; @@ -98,7 +74,6 @@ impl<'de> serde::Deserialize<'de> for WAABB { ) } - #[cfg(feature = "simd-is-enabled")] fn visit_seq(self, mut seq: A) -> Result where A: serde::de::SeqAccess<'de>, @@ -113,27 +88,12 @@ impl<'de> serde::Deserialize<'de> for WAABB { let maxs = Point::from(maxs.coords.map(|e| SimdFloat::from(e))); Ok(WAABB { mins, maxs }) } - - #[cfg(not(feature = "simd-is-enabled"))] - fn visit_seq(self, mut seq: A) -> Result - where - A: serde::de::SeqAccess<'de>, - { - let mins = seq - .next_element()? - .ok_or_else(|| serde::de::Error::invalid_length(0, &self))?; - let maxs = seq - .next_element()? - .ok_or_else(|| serde::de::Error::invalid_length(1, &self))?; - Ok(WAABB { mins, maxs }) - } } deserializer.deserialize_struct("WAABB", &["mins", "maxs"], Visitor {}) } } -#[cfg(feature = "simd-is-enabled")] impl WAABB { pub fn new(mins: Point, maxs: Point) -> Self { Self { mins, maxs } @@ -241,7 +201,6 @@ impl WAABB { } } -#[cfg(feature = "simd-is-enabled")] impl From<[AABB; SIMD_WIDTH]> for WAABB { fn from(aabbs: [AABB; SIMD_WIDTH]) -> Self { let mins = array![|ii| aabbs[ii].mins; SIMD_WIDTH]; @@ -253,51 +212,3 @@ impl From<[AABB; SIMD_WIDTH]> for WAABB { } } } - -#[cfg(not(feature = "simd-is-enabled"))] -impl WAABB { - pub fn new_invalid() -> Self { - Self::splat(AABB::new_invalid()) - } - - pub fn splat(aabb: AABB) -> Self { - Self { - mins: [aabb.mins; SIMD_WIDTH], - maxs: [aabb.maxs; SIMD_WIDTH], - } - } - - #[cfg(feature = "dim2")] - pub fn intersects_lanewise(&self, other: &WAABB) -> [bool; SIMD_WIDTH] { - array![|ii| - self.mins[ii].x <= other.maxs[ii].x - && other.mins[ii].x <= self.maxs[ii].x - && self.mins[ii].y <= other.maxs[ii].y - && other.mins[ii].y <= self.maxs[ii].y - ; SIMD_WIDTH - ] - } - - #[cfg(feature = "dim3")] - pub fn intersects_lanewise(&self, other: &WAABB) -> [bool; SIMD_WIDTH] { - array![|ii| - self.mins[ii].x <= other.maxs[ii].x - && other.mins[ii].x <= self.maxs[ii].x - && self.mins[ii].y <= other.maxs[ii].y - && other.mins[ii].y <= self.maxs[ii].y - && self.mins[ii].z <= other.maxs[ii].z - && other.mins[ii].z <= self.maxs[ii].z - ; SIMD_WIDTH - ] - } -} - -#[cfg(not(feature = "simd-is-enabled"))] -impl From<[AABB; SIMD_WIDTH]> for WAABB { - fn from(aabbs: [AABB; SIMD_WIDTH]) -> Self { - let mins = array![|ii| aabbs[ii].mins; SIMD_WIDTH]; - let maxs = array![|ii| aabbs[ii].maxs; SIMD_WIDTH]; - - WAABB { mins, maxs } - } -} diff --git a/src/lib.rs b/src/lib.rs index 8cbf673..3674717 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -219,8 +219,15 @@ pub mod math { #[cfg(not(feature = "simd-is-enabled"))] mod simd { + use simba::simd::{AutoBoolx4, AutoF32x4}; /// The number of lanes of a SIMD number. pub const SIMD_WIDTH: usize = 4; + /// SIMD_WIDTH - 1 + pub const SIMD_LAST_INDEX: usize = 3; + /// A SIMD float with SIMD_WIDTH lanes. + pub type SimdFloat = AutoF32x4; + /// A SIMD bool with SIMD_WIDTH lanes. + pub type SimdBool = AutoBoolx4; } #[cfg(feature = "simd-is-enabled")] @@ -236,16 +243,16 @@ mod simd { /// SIMD_WIDTH - 1 pub const SIMD_LAST_INDEX: usize = 3; #[cfg(not(feature = "simd-nightly"))] - /// A SIMD float with SIMD_WIDTH lanes. + /// A SIMD float with SIMD_WIDTH lanes. pub type SimdFloat = WideF32x4; #[cfg(not(feature = "simd-nightly"))] - /// A SIMD bool with SIMD_WIDTH lanes. + /// A SIMD bool with SIMD_WIDTH lanes. pub type SimdBool = WideBoolF32x4; #[cfg(feature = "simd-nightly")] - /// A SIMD float with SIMD_WIDTH lanes. + /// A SIMD float with SIMD_WIDTH lanes. pub type SimdFloat = f32x4; #[cfg(feature = "simd-nightly")] - /// A bool float with SIMD_WIDTH lanes. + /// A bool float with SIMD_WIDTH lanes. pub type SimdBool = m32x4; // pub const SIMD_WIDTH: usize = 8; diff --git a/src/utils.rs b/src/utils.rs index c7cb908..ecdd4fd 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -5,12 +5,10 @@ use crate::dynamics::RigidBodyHandle; use indexmap::IndexMap as HashMap; use na::{Matrix2, Matrix3, Matrix3x2, Point2, Point3, Scalar, SimdRealField, Vector2, Vector3}; use num::Zero; -#[cfg(feature = "simd-is-enabled")] use simba::simd::SimdValue; #[cfg(all(not(feature = "enhanced-determinism"), feature = "serde-serialize"))] use std::collections::HashMap; use std::ops::{Add, Mul}; -#[cfg(feature = "simd-is-enabled")] use { crate::simd::{SimdBool, SimdFloat}, na::SimdPartialOrd, @@ -39,7 +37,6 @@ pub(crate) fn inv(val: f32) -> f32 { /// /// For each `i in [0..SIMD_WIDTH[`, if `do_swap.extract(i)` is `true` then /// `a.extract(i)` is swapped with `b.extract(i)`. -#[cfg(feature = "simd-is-enabled")] pub fn simd_swap(do_swap: SimdBool, a: &mut SimdFloat, b: &mut SimdFloat) { let _a = *a; *a = b.select(do_swap, *a); @@ -92,7 +89,6 @@ impl> WSign> for Vector3 { } } -#[cfg(feature = "simd-is-enabled")] impl WSign for SimdFloat { fn copy_sign_to(self, to: SimdFloat) -> SimdFloat { self.simd_copysign(to) @@ -117,7 +113,6 @@ impl WComponent for f32 { } } -#[cfg(feature = "simd-is-enabled")] impl WComponent for SimdFloat { type Element = f32; @@ -334,7 +329,6 @@ impl WDot for f32 { } } -#[cfg(feature = "simd-is-enabled")] impl WCrossMatrix for Vector3 { type CrossMat = Matrix3; @@ -349,7 +343,6 @@ impl WCrossMatrix for Vector3 { } } -#[cfg(feature = "simd-is-enabled")] impl WCrossMatrix for Vector2 { type CrossMat = Vector2; @@ -359,7 +352,6 @@ impl WCrossMatrix for Vector2 { } } -#[cfg(feature = "simd-is-enabled")] impl WCross> for Vector3 { type Result = Vector3; @@ -368,7 +360,6 @@ impl WCross> for Vector3 { } } -#[cfg(feature = "simd-is-enabled")] impl WCross> for SimdFloat { type Result = Vector2; @@ -377,7 +368,6 @@ impl WCross> for SimdFloat { } } -#[cfg(feature = "simd-is-enabled")] impl WCross> for Vector2 { type Result = SimdFloat; @@ -388,7 +378,6 @@ impl WCross> for Vector2 { } } -#[cfg(feature = "simd-is-enabled")] impl WDot> for Vector3 { type Result = SimdFloat; @@ -397,7 +386,6 @@ impl WDot> for Vector3 { } } -#[cfg(feature = "simd-is-enabled")] impl WDot> for Vector2 { type Result = SimdFloat; @@ -406,7 +394,6 @@ impl WDot> for Vector2 { } } -#[cfg(feature = "simd-is-enabled")] impl WDot for SimdFloat { type Result = SimdFloat; @@ -460,7 +447,6 @@ impl WAngularInertia for f32 { } } -#[cfg(feature = "simd-is-enabled")] impl WAngularInertia for SimdFloat { type AngVector = SimdFloat; type LinVector = Vector2; @@ -875,7 +861,6 @@ impl WAngularInertia for SdpMatrix3 { } } -#[cfg(feature = "simd-is-enabled")] impl WAngularInertia for SdpMatrix3 { type AngVector = Vector3; type LinVector = Vector3; -- cgit