Fix compilation when SIMD is not enabled.

This commit is contained in:
Crozet Sébastien
2020-09-22 17:57:29 +02:00
parent a7d77a0144
commit 84bd60e4a5
3 changed files with 11 additions and 108 deletions

View File

@@ -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<SimdFloat>,
pub dir: Vector<SimdFloat>,
@@ -28,26 +26,11 @@ impl WRay {
}
#[derive(Debug, Copy, Clone)]
#[cfg(not(feature = "simd-is-enabled"))]
pub(crate) struct WRay {
pub origin: [Point<f32>; SIMD_WIDTH],
pub dir: [Vector<f32>; SIMD_WIDTH],
}
#[derive(Debug, Copy, Clone)]
#[cfg(feature = "simd-is-enabled")]
pub(crate) struct WAABB {
pub mins: Point<SimdFloat>,
pub maxs: Point<SimdFloat>,
}
#[derive(Debug, Copy, Clone)]
#[cfg(not(feature = "simd-is-enabled"))]
pub(crate) struct WAABB {
pub mins: [Point<f32>; SIMD_WIDTH],
pub maxs: [Point<f32>; SIMD_WIDTH],
}
#[cfg(feature = "serde-serialize")]
impl serde::Serialize for WAABB {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -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<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
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<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
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<SimdFloat>, maxs: Point<SimdFloat>) -> Self {
Self { mins, maxs }
@@ -241,7 +201,6 @@ impl WAABB {
}
}
#[cfg(feature = "simd-is-enabled")]
impl From<[AABB<f32>; SIMD_WIDTH]> for WAABB {
fn from(aabbs: [AABB<f32>; SIMD_WIDTH]) -> Self {
let mins = array![|ii| aabbs[ii].mins; SIMD_WIDTH];
@@ -253,51 +212,3 @@ impl From<[AABB<f32>; 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<f32>) -> 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<f32>; SIMD_WIDTH]> for WAABB {
fn from(aabbs: [AABB<f32>; SIMD_WIDTH]) -> Self {
let mins = array![|ii| aabbs[ii].mins; SIMD_WIDTH];
let maxs = array![|ii| aabbs[ii].maxs; SIMD_WIDTH];
WAABB { mins, maxs }
}
}

View File

@@ -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;

View File

@@ -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<N: Scalar + Copy + WSign<N>> WSign<Vector3<N>> for Vector3<N> {
}
}
#[cfg(feature = "simd-is-enabled")]
impl WSign<SimdFloat> 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<f32> for f32 {
}
}
#[cfg(feature = "simd-is-enabled")]
impl WCrossMatrix for Vector3<SimdFloat> {
type CrossMat = Matrix3<SimdFloat>;
@@ -349,7 +343,6 @@ impl WCrossMatrix for Vector3<SimdFloat> {
}
}
#[cfg(feature = "simd-is-enabled")]
impl WCrossMatrix for Vector2<SimdFloat> {
type CrossMat = Vector2<SimdFloat>;
@@ -359,7 +352,6 @@ impl WCrossMatrix for Vector2<SimdFloat> {
}
}
#[cfg(feature = "simd-is-enabled")]
impl WCross<Vector3<SimdFloat>> for Vector3<SimdFloat> {
type Result = Vector3<SimdFloat>;
@@ -368,7 +360,6 @@ impl WCross<Vector3<SimdFloat>> for Vector3<SimdFloat> {
}
}
#[cfg(feature = "simd-is-enabled")]
impl WCross<Vector2<SimdFloat>> for SimdFloat {
type Result = Vector2<SimdFloat>;
@@ -377,7 +368,6 @@ impl WCross<Vector2<SimdFloat>> for SimdFloat {
}
}
#[cfg(feature = "simd-is-enabled")]
impl WCross<Vector2<SimdFloat>> for Vector2<SimdFloat> {
type Result = SimdFloat;
@@ -388,7 +378,6 @@ impl WCross<Vector2<SimdFloat>> for Vector2<SimdFloat> {
}
}
#[cfg(feature = "simd-is-enabled")]
impl WDot<Vector3<SimdFloat>> for Vector3<SimdFloat> {
type Result = SimdFloat;
@@ -397,7 +386,6 @@ impl WDot<Vector3<SimdFloat>> for Vector3<SimdFloat> {
}
}
#[cfg(feature = "simd-is-enabled")]
impl WDot<Vector2<SimdFloat>> for Vector2<SimdFloat> {
type Result = SimdFloat;
@@ -406,7 +394,6 @@ impl WDot<Vector2<SimdFloat>> for Vector2<SimdFloat> {
}
}
#[cfg(feature = "simd-is-enabled")]
impl WDot<SimdFloat> for SimdFloat {
type Result = SimdFloat;
@@ -460,7 +447,6 @@ impl WAngularInertia<f32> for f32 {
}
}
#[cfg(feature = "simd-is-enabled")]
impl WAngularInertia<SimdFloat> for SimdFloat {
type AngVector = SimdFloat;
type LinVector = Vector2<SimdFloat>;
@@ -875,7 +861,6 @@ impl WAngularInertia<f32> for SdpMatrix3<f32> {
}
}
#[cfg(feature = "simd-is-enabled")]
impl WAngularInertia<SimdFloat> for SdpMatrix3<SimdFloat> {
type AngVector = Vector3<SimdFloat>;
type LinVector = Vector3<SimdFloat>;