Refinded simd feature

This commit is contained in:
Dzmitry Malyshau 2017-06-06 16:44:13 -04:00
parent b87401be28
commit 087336d0c0
9 changed files with 94 additions and 93 deletions

View file

@ -14,9 +14,9 @@ env:
matrix: matrix:
include: include:
- rust: nightly - rust: nightly
env: CARGO_FEATURES="use_simd" env: CARGO_FEATURES="simd"
- rust: nightly - rust: nightly
env: CARGO_FEATURES="eders use_simd" env: CARGO_FEATURES="eders simd"
script: script:
- cargo build --features "$CARGO_FEATURES" - cargo build --features "$CARGO_FEATURES"

View file

@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] ## [Unreleased]
- Refactored `simd` and `serde` dependencies to match feature names
## [v0.14.1] - 2017-05-02 ## [v0.14.1] - 2017-05-02
### Fixed ### Fixed

View file

@ -19,7 +19,6 @@ name = "cgmath"
[features] [features]
unstable = [] unstable = []
eders = ["serde", "serde_derive"] eders = ["serde", "serde_derive"]
use_simd = ["simd"]
[dependencies] [dependencies]
approx = "0.1" approx = "0.1"

View file

@ -50,7 +50,7 @@
//! use cgmath::prelude::*; //! use cgmath::prelude::*;
//! ``` //! ```
#![cfg_attr(feature = "use_simd", feature(specialization))] #![cfg_attr(feature = "simd", feature(specialization))]
#[macro_use] #[macro_use]
extern crate approx; extern crate approx;
@ -63,7 +63,7 @@ extern crate serde_derive;
#[cfg(feature = "eders")] #[cfg(feature = "eders")]
extern crate serde; extern crate serde;
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
extern crate simd; extern crate simd;
// Re-exports // Re-exports

View file

@ -255,7 +255,7 @@ macro_rules! impl_index_operators {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
macro_rules! impl_operator_default { macro_rules! impl_operator_default {
// When it is an unary operator // When it is an unary operator
(<$S:ident: $Constraint:ident> $Op:ident for $Lhs:ty { (<$S:ident: $Constraint:ident> $Op:ident for $Lhs:ty {
@ -355,7 +355,7 @@ macro_rules! impl_operator_default {
}; };
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
macro_rules! impl_assignment_operator_default { macro_rules! impl_assignment_operator_default {
(<$S:ident: $Constraint:ident> $Op:ident<$Rhs:ty> for $Lhs:ty { (<$S:ident: $Constraint:ident> $Op:ident<$Rhs:ty> for $Lhs:ty {
fn $op:ident(&mut $lhs:ident, $rhs:ident) $body:block fn $op:ident(&mut $lhs:ident, $rhs:ident) $body:block
@ -368,13 +368,13 @@ macro_rules! impl_assignment_operator_default {
} }
/// Generates a binary operator implementation for the permutations of by-ref and by-val, for simd /// Generates a binary operator implementation for the permutations of by-ref and by-val, for simd
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
macro_rules! impl_operator_simd { macro_rules! impl_operator_simd {
// When it is an unary operator // When it is an unary operator
([$Simd:ident]; $Op:ident for $Lhs:ty { ([$Simd:ident]; $Op:ident for $Lhs:ty {
fn $op:ident($x:ident) -> $Output:ty { $body:expr } fn $op:ident($x:ident) -> $Output:ty { $body:expr }
}) => { }) => {
impl $Op for $Lhs { impl $Op for $Lhs {
#[inline] #[inline]
fn $op(self) -> $Output { fn $op(self) -> $Output {
@ -393,7 +393,7 @@ macro_rules! impl_operator_simd {
} }
} }
impl<'a> $Op<$Rhs> for &'a $Lhs { impl<'a> $Op<$Rhs> for &'a $Lhs {
#[inline] #[inline]
fn $op(self, other: $Rhs) -> $Output { fn $op(self, other: $Rhs) -> $Output {
@ -406,7 +406,7 @@ macro_rules! impl_operator_simd {
([$Simd:ident]; $Op:ident<$Rhs:ty> for $Lhs:ty { ([$Simd:ident]; $Op:ident<$Rhs:ty> for $Lhs:ty {
fn $op:ident($lhs:ident, $rhs:ident) -> $Output:ty { $body:expr } fn $op:ident($lhs:ident, $rhs:ident) -> $Output:ty { $body:expr }
}) => { }) => {
impl $Op<$Rhs> for $Lhs { impl $Op<$Rhs> for $Lhs {
#[inline] #[inline]
fn $op(self, other: $Rhs) -> $Output { fn $op(self, other: $Rhs) -> $Output {
@ -414,14 +414,14 @@ macro_rules! impl_operator_simd {
} }
} }
impl<'a> $Op<&'a $Rhs> for $Lhs { impl<'a> $Op<&'a $Rhs> for $Lhs {
#[inline] #[inline]
fn $op(self, other: &'a $Rhs) -> $Output { fn $op(self, other: &'a $Rhs) -> $Output {
let ($lhs, $rhs): ($Simd, $Simd) = (self.into(), (*other).into()); $body let ($lhs, $rhs): ($Simd, $Simd) = (self.into(), (*other).into()); $body
} }
} }
impl<'a> $Op<$Rhs> for &'a $Lhs { impl<'a> $Op<$Rhs> for &'a $Lhs {
#[inline] #[inline]
fn $op(self, other: $Rhs) -> $Output { fn $op(self, other: $Rhs) -> $Output {
@ -447,7 +447,7 @@ macro_rules! impl_operator_simd {
let ($lhs, $rhs): ($Simd, $Simd) = ($Simd::splat(self), other.into()); $body let ($lhs, $rhs): ($Simd, $Simd) = ($Simd::splat(self), other.into()); $body
} }
} }
impl<'a> $Op<&'a $Rhs> for $Lhs { impl<'a> $Op<&'a $Rhs> for $Lhs {
#[inline] #[inline]
fn $op(self, other: &'a $Rhs) -> $Output { fn $op(self, other: &'a $Rhs) -> $Output {

View file

@ -666,7 +666,7 @@ impl<S: BaseFloat> SquareMatrix for Matrix4<S> {
// A better option would be using specialization. But currently somewhat // A better option would be using specialization. But currently somewhat
// specialization is too buggy, and it won't apply here. I'm getting // specialization is too buggy, and it won't apply here. I'm getting
// weird error msgs. Help wanted. // weird error msgs. Help wanted.
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
fn invert(&self) -> Option<Matrix4<S>> { fn invert(&self) -> Option<Matrix4<S>> {
let det = self.determinant(); let det = self.determinant();
if det == S::zero() { if det == S::zero() {
@ -692,7 +692,7 @@ impl<S: BaseFloat> SquareMatrix for Matrix4<S> {
cf(3, 0), cf(3, 1), cf(3, 2), cf(3, 3))) cf(3, 0), cf(3, 1), cf(3, 2), cf(3, 3)))
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
fn invert(&self) -> Option<Matrix4<S>> { fn invert(&self) -> Option<Matrix4<S>> {
let tmp0 = unsafe { let tmp0 = unsafe {
det_sub_proc_unsafe(self, 1, 2, 3) det_sub_proc_unsafe(self, 1, 2, 3)
@ -1057,9 +1057,9 @@ macro_rules! impl_mv_operator {
impl_mv_operator!(Matrix2, Vector2 { x: 0, y: 1 }); impl_mv_operator!(Matrix2, Vector2 { x: 0, y: 1 });
impl_mv_operator!(Matrix3, Vector3 { x: 0, y: 1, z: 2 }); impl_mv_operator!(Matrix3, Vector3 { x: 0, y: 1, z: 2 });
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl_mv_operator!(Matrix4, Vector4 { x: 0, y: 1, z: 2, w: 3 }); impl_mv_operator!(Matrix4, Vector4 { x: 0, y: 1, z: 2, w: 3 });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator!(<S: BaseFloat> Mul<Vector4<S> > for Matrix4<S> { impl_operator!(<S: BaseFloat> Mul<Vector4<S> > for Matrix4<S> {
fn mul(matrix, vector) -> Vector4<S> { fn mul(matrix, vector) -> Vector4<S> {
matrix[0] * vector[0] + matrix[1] * vector[1] + matrix[2] * vector[2] + matrix[3] * vector[3] matrix[0] * vector[0] + matrix[1] * vector[1] + matrix[2] * vector[2] + matrix[3] * vector[3]

View file

@ -31,7 +31,7 @@ use point::Point3;
use rotation::{Rotation, Rotation3, Basis3}; use rotation::{Rotation, Rotation3, Basis3};
use vector::Vector3; use vector::Vector3;
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
use simd::f32x4 as Simdf32x4; use simd::f32x4 as Simdf32x4;
/// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector /// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector
@ -48,7 +48,7 @@ pub struct Quaternion<S> {
pub v: Vector3<S>, pub v: Vector3<S>,
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl From<Simdf32x4> for Quaternion<f32> { impl From<Simdf32x4> for Quaternion<f32> {
#[inline] #[inline]
fn from(f: Simdf32x4) -> Self { fn from(f: Simdf32x4) -> Self {
@ -63,7 +63,7 @@ impl From<Simdf32x4> for Quaternion<f32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl Into<Simdf32x4> for Quaternion<f32> { impl Into<Simdf32x4> for Quaternion<f32> {
#[inline] #[inline]
fn into(self) -> Simdf32x4 { fn into(self) -> Simdf32x4 {
@ -229,7 +229,7 @@ impl<S: BaseFloat> MetricSpace for Quaternion<S> {
} }
} }
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl<S: BaseFloat> InnerSpace for Quaternion<S> { impl<S: BaseFloat> InnerSpace for Quaternion<S> {
#[inline] #[inline]
fn dot(self, other: Quaternion<S>) -> S { fn dot(self, other: Quaternion<S>) -> S {
@ -237,7 +237,7 @@ impl<S: BaseFloat> InnerSpace for Quaternion<S> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl<S: BaseFloat> InnerSpace for Quaternion<S> { impl<S: BaseFloat> InnerSpace for Quaternion<S> {
#[inline] #[inline]
default fn dot(self, other: Quaternion<S>) -> S { default fn dot(self, other: Quaternion<S>) -> S {
@ -245,7 +245,7 @@ impl<S: BaseFloat> InnerSpace for Quaternion<S> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl InnerSpace for Quaternion<f32> { impl InnerSpace for Quaternion<f32> {
#[inline] #[inline]
fn dot(self, other: Quaternion<f32>) -> f32 { fn dot(self, other: Quaternion<f32>) -> f32 {
@ -277,21 +277,21 @@ impl<A> From<Euler<A>> for Quaternion<A::Unitless> where
} }
} }
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl_operator!(<S: BaseFloat> Neg for Quaternion<S> { impl_operator!(<S: BaseFloat> Neg for Quaternion<S> {
fn neg(quat) -> Quaternion<S> { fn neg(quat) -> Quaternion<S> {
Quaternion::from_sv(-quat.s, -quat.v) Quaternion::from_sv(-quat.s, -quat.v)
} }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_default!(<S: BaseFloat> Neg for Quaternion<S> { impl_operator_default!(<S: BaseFloat> Neg for Quaternion<S> {
fn neg(quat) -> Quaternion<S> { fn neg(quat) -> Quaternion<S> {
Quaternion::from_sv(-quat.s, -quat.v) Quaternion::from_sv(-quat.s, -quat.v)
} }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{ impl_operator_simd!{
[Simdf32x4]; Neg for Quaternion<f32> { [Simdf32x4]; Neg for Quaternion<f32> {
fn neg(lhs) -> Quaternion<f32> { fn neg(lhs) -> Quaternion<f32> {
@ -300,21 +300,21 @@ impl_operator_simd!{
} }
} }
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl_operator!(<S: BaseFloat> Mul<S> for Quaternion<S> { impl_operator!(<S: BaseFloat> Mul<S> for Quaternion<S> {
fn mul(lhs, rhs) -> Quaternion<S> { fn mul(lhs, rhs) -> Quaternion<S> {
Quaternion::from_sv(lhs.s * rhs, lhs.v * rhs) Quaternion::from_sv(lhs.s * rhs, lhs.v * rhs)
} }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_default!(<S: BaseFloat> Mul<S> for Quaternion<S> { impl_operator_default!(<S: BaseFloat> Mul<S> for Quaternion<S> {
fn mul(lhs, rhs) -> Quaternion<S> { fn mul(lhs, rhs) -> Quaternion<S> {
Quaternion::from_sv(lhs.s * rhs, lhs.v * rhs) Quaternion::from_sv(lhs.s * rhs, lhs.v * rhs)
} }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{@rs impl_operator_simd!{@rs
[Simdf32x4]; Mul<f32> for Quaternion<f32> { [Simdf32x4]; Mul<f32> for Quaternion<f32> {
fn mul(lhs, rhs) -> Quaternion<f32> { fn mul(lhs, rhs) -> Quaternion<f32> {
@ -323,17 +323,17 @@ impl_operator_simd!{@rs
} }
} }
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl_assignment_operator!(<S: BaseFloat> MulAssign<S> for Quaternion<S> { impl_assignment_operator!(<S: BaseFloat> MulAssign<S> for Quaternion<S> {
fn mul_assign(&mut self, scalar) { self.s *= scalar; self.v *= scalar; } fn mul_assign(&mut self, scalar) { self.s *= scalar; self.v *= scalar; }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_assignment_operator_default!(<S: BaseFloat> MulAssign<S> for Quaternion<S> { impl_assignment_operator_default!(<S: BaseFloat> MulAssign<S> for Quaternion<S> {
fn mul_assign(&mut self, scalar) { self.s *= scalar; self.v *= scalar; } fn mul_assign(&mut self, scalar) { self.s *= scalar; self.v *= scalar; }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl MulAssign<f32> for Quaternion<f32> { impl MulAssign<f32> for Quaternion<f32> {
fn mul_assign(&mut self, other: f32) { fn mul_assign(&mut self, other: f32) {
let s: Simdf32x4 = (*self).into(); let s: Simdf32x4 = (*self).into();
@ -342,21 +342,21 @@ impl MulAssign<f32> for Quaternion<f32> {
} }
} }
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl_operator!(<S: BaseFloat> Div<S> for Quaternion<S> { impl_operator!(<S: BaseFloat> Div<S> for Quaternion<S> {
fn div(lhs, rhs) -> Quaternion<S> { fn div(lhs, rhs) -> Quaternion<S> {
Quaternion::from_sv(lhs.s / rhs, lhs.v / rhs) Quaternion::from_sv(lhs.s / rhs, lhs.v / rhs)
} }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_default!(<S: BaseFloat> Div<S> for Quaternion<S> { impl_operator_default!(<S: BaseFloat> Div<S> for Quaternion<S> {
fn div(lhs, rhs) -> Quaternion<S> { fn div(lhs, rhs) -> Quaternion<S> {
Quaternion::from_sv(lhs.s / rhs, lhs.v / rhs) Quaternion::from_sv(lhs.s / rhs, lhs.v / rhs)
} }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{@rs impl_operator_simd!{@rs
[Simdf32x4]; Div<f32> for Quaternion<f32> { [Simdf32x4]; Div<f32> for Quaternion<f32> {
fn div(lhs, rhs) -> Quaternion<f32> { fn div(lhs, rhs) -> Quaternion<f32> {
@ -365,17 +365,17 @@ impl_operator_simd!{@rs
} }
} }
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl_assignment_operator!(<S: BaseFloat> DivAssign<S> for Quaternion<S> { impl_assignment_operator!(<S: BaseFloat> DivAssign<S> for Quaternion<S> {
fn div_assign(&mut self, scalar) { self.s /= scalar; self.v /= scalar; } fn div_assign(&mut self, scalar) { self.s /= scalar; self.v /= scalar; }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_assignment_operator_default!(<S: BaseFloat> DivAssign<S> for Quaternion<S> { impl_assignment_operator_default!(<S: BaseFloat> DivAssign<S> for Quaternion<S> {
fn div_assign(&mut self, scalar) { self.s /= scalar; self.v /= scalar; } fn div_assign(&mut self, scalar) { self.s /= scalar; self.v /= scalar; }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl DivAssign<f32> for Quaternion<f32> { impl DivAssign<f32> for Quaternion<f32> {
fn div_assign(&mut self, other: f32) { fn div_assign(&mut self, other: f32) {
let s: Simdf32x4 = (*self).into(); let s: Simdf32x4 = (*self).into();
@ -403,21 +403,21 @@ impl_operator!(<S: BaseFloat> Mul<Vector3<S> > for Quaternion<S> {
}} }}
}); });
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl_operator!(<S: BaseFloat> Add<Quaternion<S> > for Quaternion<S> { impl_operator!(<S: BaseFloat> Add<Quaternion<S> > for Quaternion<S> {
fn add(lhs, rhs) -> Quaternion<S> { fn add(lhs, rhs) -> Quaternion<S> {
Quaternion::from_sv(lhs.s + rhs.s, lhs.v + rhs.v) Quaternion::from_sv(lhs.s + rhs.s, lhs.v + rhs.v)
} }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_default!(<S: BaseFloat> Add<Quaternion<S> > for Quaternion<S> { impl_operator_default!(<S: BaseFloat> Add<Quaternion<S> > for Quaternion<S> {
fn add(lhs, rhs) -> Quaternion<S> { fn add(lhs, rhs) -> Quaternion<S> {
Quaternion::from_sv(lhs.s + rhs.s, lhs.v + rhs.v) Quaternion::from_sv(lhs.s + rhs.s, lhs.v + rhs.v)
} }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{ impl_operator_simd!{
[Simdf32x4]; Add<Quaternion<f32>> for Quaternion<f32> { [Simdf32x4]; Add<Quaternion<f32>> for Quaternion<f32> {
fn add(lhs, rhs) -> Quaternion<f32> { fn add(lhs, rhs) -> Quaternion<f32> {
@ -426,17 +426,17 @@ impl_operator_simd!{
} }
} }
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl_assignment_operator!(<S: BaseFloat> AddAssign<Quaternion<S> > for Quaternion<S> { impl_assignment_operator!(<S: BaseFloat> AddAssign<Quaternion<S> > for Quaternion<S> {
fn add_assign(&mut self, other) { self.s += other.s; self.v += other.v; } fn add_assign(&mut self, other) { self.s += other.s; self.v += other.v; }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_assignment_operator_default!(<S: BaseFloat> AddAssign<Quaternion<S> > for Quaternion<S> { impl_assignment_operator_default!(<S: BaseFloat> AddAssign<Quaternion<S> > for Quaternion<S> {
fn add_assign(&mut self, other) { self.s += other.s; self.v += other.v; } fn add_assign(&mut self, other) { self.s += other.s; self.v += other.v; }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl AddAssign for Quaternion<f32> { impl AddAssign for Quaternion<f32> {
#[inline] #[inline]
fn add_assign(&mut self, rhs: Self) { fn add_assign(&mut self, rhs: Self) {
@ -446,21 +446,21 @@ impl AddAssign for Quaternion<f32> {
} }
} }
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl_operator!(<S: BaseFloat> Sub<Quaternion<S> > for Quaternion<S> { impl_operator!(<S: BaseFloat> Sub<Quaternion<S> > for Quaternion<S> {
fn sub(lhs, rhs) -> Quaternion<S> { fn sub(lhs, rhs) -> Quaternion<S> {
Quaternion::from_sv(lhs.s - rhs.s, lhs.v - rhs.v) Quaternion::from_sv(lhs.s - rhs.s, lhs.v - rhs.v)
} }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_default!(<S: BaseFloat> Sub<Quaternion<S> > for Quaternion<S> { impl_operator_default!(<S: BaseFloat> Sub<Quaternion<S> > for Quaternion<S> {
fn sub(lhs, rhs) -> Quaternion<S> { fn sub(lhs, rhs) -> Quaternion<S> {
Quaternion::from_sv(lhs.s - rhs.s, lhs.v - rhs.v) Quaternion::from_sv(lhs.s - rhs.s, lhs.v - rhs.v)
} }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{ impl_operator_simd!{
[Simdf32x4]; Sub<Quaternion<f32>> for Quaternion<f32> { [Simdf32x4]; Sub<Quaternion<f32>> for Quaternion<f32> {
fn sub(lhs, rhs) -> Quaternion<f32> { fn sub(lhs, rhs) -> Quaternion<f32> {
@ -469,17 +469,17 @@ impl_operator_simd!{
} }
} }
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl_assignment_operator!(<S: BaseFloat> SubAssign<Quaternion<S> > for Quaternion<S> { impl_assignment_operator!(<S: BaseFloat> SubAssign<Quaternion<S> > for Quaternion<S> {
fn sub_assign(&mut self, other) { self.s -= other.s; self.v -= other.v; } fn sub_assign(&mut self, other) { self.s -= other.s; self.v -= other.v; }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_assignment_operator_default!(<S: BaseFloat> SubAssign<Quaternion<S> > for Quaternion<S> { impl_assignment_operator_default!(<S: BaseFloat> SubAssign<Quaternion<S> > for Quaternion<S> {
fn sub_assign(&mut self, other) { self.s -= other.s; self.v -= other.v; } fn sub_assign(&mut self, other) { self.s -= other.s; self.v -= other.v; }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl SubAssign for Quaternion<f32> { impl SubAssign for Quaternion<f32> {
#[inline] #[inline]
fn sub_assign(&mut self, rhs: Self) { fn sub_assign(&mut self, rhs: Self) {
@ -489,7 +489,7 @@ impl SubAssign for Quaternion<f32> {
} }
} }
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl_operator!(<S: BaseFloat> Mul<Quaternion<S> > for Quaternion<S> { impl_operator!(<S: BaseFloat> Mul<Quaternion<S> > for Quaternion<S> {
fn mul(lhs, rhs) -> Quaternion<S> { fn mul(lhs, rhs) -> Quaternion<S> {
Quaternion::new(lhs.s * rhs.s - lhs.v.x * rhs.v.x - lhs.v.y * rhs.v.y - lhs.v.z * rhs.v.z, Quaternion::new(lhs.s * rhs.s - lhs.v.x * rhs.v.x - lhs.v.y * rhs.v.y - lhs.v.z * rhs.v.z,
@ -499,7 +499,7 @@ impl_operator!(<S: BaseFloat> Mul<Quaternion<S> > for Quaternion<S> {
} }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_default!(<S: BaseFloat> Mul<Quaternion<S> > for Quaternion<S> { impl_operator_default!(<S: BaseFloat> Mul<Quaternion<S> > for Quaternion<S> {
fn mul(lhs, rhs) -> Quaternion<S> { fn mul(lhs, rhs) -> Quaternion<S> {
Quaternion::new(lhs.s * rhs.s - lhs.v.x * rhs.v.x - lhs.v.y * rhs.v.y - lhs.v.z * rhs.v.z, Quaternion::new(lhs.s * rhs.s - lhs.v.x * rhs.v.x - lhs.v.y * rhs.v.y - lhs.v.z * rhs.v.z,
@ -509,7 +509,7 @@ impl_operator_default!(<S: BaseFloat> Mul<Quaternion<S> > for Quaternion<S> {
} }
}); });
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{ impl_operator_simd!{
[Simdf32x4]; Mul<Quaternion<f32>> for Quaternion<f32> { [Simdf32x4]; Mul<Quaternion<f32>> for Quaternion<f32> {
fn mul(lhs, rhs) -> Quaternion<f32> { fn mul(lhs, rhs) -> Quaternion<f32> {

View file

@ -26,11 +26,11 @@ use angle::Rad;
use approx::ApproxEq; use approx::ApproxEq;
use num::{BaseNum, BaseFloat}; use num::{BaseNum, BaseFloat};
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
use simd::f32x4 as Simdf32x4; use simd::f32x4 as Simdf32x4;
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
use simd::i32x4 as Simdi32x4; use simd::i32x4 as Simdi32x4;
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
use simd::u32x4 as Simdu32x4; use simd::u32x4 as Simdu32x4;
/// A 1-dimensional vector. /// A 1-dimensional vector.
@ -301,7 +301,7 @@ macro_rules! impl_vector {
// Utility macro for generating associated functions for the vectors // Utility macro for generating associated functions for the vectors
// mainly duplication // mainly duplication
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
macro_rules! impl_vector_default { macro_rules! impl_vector_default {
($VectorN:ident { $($field:ident),+ }, $n:expr, $constructor:ident) => { ($VectorN:ident { $($field:ident),+ }, $n:expr, $constructor:ident) => {
impl<S> $VectorN<S> { impl<S> $VectorN<S> {
@ -529,7 +529,7 @@ macro_rules! impl_scalar_ops {
}; };
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
macro_rules! impl_scalar_ops_default { macro_rules! impl_scalar_ops_default {
($VectorN:ident<$S:ident> { $($field:ident),+ }) => { ($VectorN:ident<$S:ident> { $($field:ident),+ }) => {
impl_operator_default!(Mul<$VectorN<$S>> for $S { impl_operator_default!(Mul<$VectorN<$S>> for $S {
@ -547,9 +547,9 @@ macro_rules! impl_scalar_ops_default {
impl_vector!(Vector1 { x }, 1, vec1); impl_vector!(Vector1 { x }, 1, vec1);
impl_vector!(Vector2 { x, y }, 2, vec2); impl_vector!(Vector2 { x, y }, 2, vec2);
impl_vector!(Vector3 { x, y, z }, 3, vec3); impl_vector!(Vector3 { x, y, z }, 3, vec3);
#[cfg(not(feature = "use_simd"))] #[cfg(not(feature = "simd"))]
impl_vector!(Vector4 { x, y, z, w }, 4, vec4); impl_vector!(Vector4 { x, y, z, w }, 4, vec4);
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_vector_default!(Vector4 { x, y, z, w }, 4, vec4); impl_vector_default!(Vector4 { x, y, z, w }, 4, vec4);
impl_fixed_array_conversions!(Vector1<S> { x: 0 }, 1); impl_fixed_array_conversions!(Vector1<S> { x: 0 }, 1);
@ -757,7 +757,7 @@ impl<S: fmt::Debug> fmt::Debug for Vector4<S> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl From<Simdf32x4> for Vector4<f32> { impl From<Simdf32x4> for Vector4<f32> {
#[inline] #[inline]
fn from(f: Simdf32x4) -> Self { fn from(f: Simdf32x4) -> Self {
@ -772,7 +772,7 @@ impl From<Simdf32x4> for Vector4<f32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl Vector4<f32> { impl Vector4<f32> {
/// Compute and return the square root of each element. /// Compute and return the square root of each element.
#[inline] #[inline]
@ -798,7 +798,7 @@ impl Vector4<f32> {
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl Into<Simdf32x4> for Vector4<f32> { impl Into<Simdf32x4> for Vector4<f32> {
#[inline] #[inline]
fn into(self) -> Simdf32x4 { fn into(self) -> Simdf32x4 {
@ -807,7 +807,7 @@ impl Into<Simdf32x4> for Vector4<f32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{ impl_operator_simd!{
[Simdf32x4]; Add<Vector4<f32>> for Vector4<f32> { [Simdf32x4]; Add<Vector4<f32>> for Vector4<f32> {
fn add(lhs, rhs) -> Vector4<f32> { fn add(lhs, rhs) -> Vector4<f32> {
@ -816,7 +816,7 @@ impl_operator_simd!{
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{ impl_operator_simd!{
[Simdf32x4]; Sub<Vector4<f32>> for Vector4<f32> { [Simdf32x4]; Sub<Vector4<f32>> for Vector4<f32> {
fn sub(lhs, rhs) -> Vector4<f32> { fn sub(lhs, rhs) -> Vector4<f32> {
@ -825,7 +825,7 @@ impl_operator_simd!{
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{@rs impl_operator_simd!{@rs
[Simdf32x4]; Mul<f32> for Vector4<f32> { [Simdf32x4]; Mul<f32> for Vector4<f32> {
fn mul(lhs, rhs) -> Vector4<f32> { fn mul(lhs, rhs) -> Vector4<f32> {
@ -834,7 +834,7 @@ impl_operator_simd!{@rs
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{@rs impl_operator_simd!{@rs
[Simdf32x4]; Div<f32> for Vector4<f32> { [Simdf32x4]; Div<f32> for Vector4<f32> {
fn div(lhs, rhs) -> Vector4<f32> { fn div(lhs, rhs) -> Vector4<f32> {
@ -845,7 +845,7 @@ impl_operator_simd!{@rs
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{ impl_operator_simd!{
[Simdf32x4]; Neg for Vector4<f32> { [Simdf32x4]; Neg for Vector4<f32> {
fn neg(lhs) -> Vector4<f32> { fn neg(lhs) -> Vector4<f32> {
@ -854,7 +854,7 @@ impl_operator_simd!{
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl AddAssign for Vector4<f32> { impl AddAssign for Vector4<f32> {
#[inline] #[inline]
fn add_assign(&mut self, rhs: Self) { fn add_assign(&mut self, rhs: Self) {
@ -864,7 +864,7 @@ impl AddAssign for Vector4<f32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl SubAssign for Vector4<f32> { impl SubAssign for Vector4<f32> {
#[inline] #[inline]
fn sub_assign(&mut self, rhs: Self) { fn sub_assign(&mut self, rhs: Self) {
@ -874,7 +874,7 @@ impl SubAssign for Vector4<f32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl MulAssign<f32> for Vector4<f32> { impl MulAssign<f32> for Vector4<f32> {
fn mul_assign(&mut self, other: f32) { fn mul_assign(&mut self, other: f32) {
let s: Simdf32x4 = (*self).into(); let s: Simdf32x4 = (*self).into();
@ -883,7 +883,7 @@ impl MulAssign<f32> for Vector4<f32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl DivAssign<f32> for Vector4<f32> { impl DivAssign<f32> for Vector4<f32> {
fn div_assign(&mut self, other: f32) { fn div_assign(&mut self, other: f32) {
let s: Simdf32x4 = (*self).into(); let s: Simdf32x4 = (*self).into();
@ -892,7 +892,7 @@ impl DivAssign<f32> for Vector4<f32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl ElementWise for Vector4<f32> { impl ElementWise for Vector4<f32> {
#[inline] fn add_element_wise(self, rhs: Vector4<f32>) -> Vector4<f32> { self + rhs } #[inline] fn add_element_wise(self, rhs: Vector4<f32>) -> Vector4<f32> { self + rhs }
#[inline] fn sub_element_wise(self, rhs: Vector4<f32>) -> Vector4<f32> { self - rhs } #[inline] fn sub_element_wise(self, rhs: Vector4<f32>) -> Vector4<f32> { self - rhs }
@ -921,7 +921,7 @@ impl ElementWise for Vector4<f32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl ElementWise<f32> for Vector4<f32> { impl ElementWise<f32> for Vector4<f32> {
#[inline] fn add_element_wise(self, rhs: f32) -> Vector4<f32> { #[inline] fn add_element_wise(self, rhs: f32) -> Vector4<f32> {
let s: Simdf32x4 = self.into(); let s: Simdf32x4 = self.into();
@ -950,7 +950,7 @@ impl ElementWise<f32> for Vector4<f32> {
#[inline] fn div_assign_element_wise(&mut self, rhs: f32) { (*self) /= rhs; } #[inline] fn div_assign_element_wise(&mut self, rhs: f32) { (*self) /= rhs; }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl From<Simdi32x4> for Vector4<i32> { impl From<Simdi32x4> for Vector4<i32> {
#[inline] #[inline]
fn from(f: Simdi32x4) -> Self { fn from(f: Simdi32x4) -> Self {
@ -965,7 +965,7 @@ impl From<Simdi32x4> for Vector4<i32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl Into<Simdi32x4> for Vector4<i32> { impl Into<Simdi32x4> for Vector4<i32> {
#[inline] #[inline]
fn into(self) -> Simdi32x4 { fn into(self) -> Simdi32x4 {
@ -974,7 +974,7 @@ impl Into<Simdi32x4> for Vector4<i32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{ impl_operator_simd!{
[Simdi32x4]; Add<Vector4<i32>> for Vector4<i32> { [Simdi32x4]; Add<Vector4<i32>> for Vector4<i32> {
fn add(lhs, rhs) -> Vector4<i32> { fn add(lhs, rhs) -> Vector4<i32> {
@ -983,7 +983,7 @@ impl_operator_simd!{
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{ impl_operator_simd!{
[Simdi32x4]; Sub<Vector4<i32>> for Vector4<i32> { [Simdi32x4]; Sub<Vector4<i32>> for Vector4<i32> {
fn sub(lhs, rhs) -> Vector4<i32> { fn sub(lhs, rhs) -> Vector4<i32> {
@ -992,7 +992,7 @@ impl_operator_simd!{
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{@rs impl_operator_simd!{@rs
[Simdi32x4]; Mul<i32> for Vector4<i32> { [Simdi32x4]; Mul<i32> for Vector4<i32> {
fn mul(lhs, rhs) -> Vector4<i32> { fn mul(lhs, rhs) -> Vector4<i32> {
@ -1001,7 +1001,7 @@ impl_operator_simd!{@rs
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{ impl_operator_simd!{
[Simdi32x4]; Neg for Vector4<i32> { [Simdi32x4]; Neg for Vector4<i32> {
fn neg(lhs) -> Vector4<i32> { fn neg(lhs) -> Vector4<i32> {
@ -1010,7 +1010,7 @@ impl_operator_simd!{
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl AddAssign for Vector4<i32> { impl AddAssign for Vector4<i32> {
#[inline] #[inline]
fn add_assign(&mut self, rhs: Self) { fn add_assign(&mut self, rhs: Self) {
@ -1020,7 +1020,7 @@ impl AddAssign for Vector4<i32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl SubAssign for Vector4<i32> { impl SubAssign for Vector4<i32> {
#[inline] #[inline]
fn sub_assign(&mut self, rhs: Self) { fn sub_assign(&mut self, rhs: Self) {
@ -1030,7 +1030,7 @@ impl SubAssign for Vector4<i32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl MulAssign<i32> for Vector4<i32> { impl MulAssign<i32> for Vector4<i32> {
fn mul_assign(&mut self, other: i32) { fn mul_assign(&mut self, other: i32) {
let s: Simdi32x4 = (*self).into(); let s: Simdi32x4 = (*self).into();
@ -1039,7 +1039,7 @@ impl MulAssign<i32> for Vector4<i32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl From<Simdu32x4> for Vector4<u32> { impl From<Simdu32x4> for Vector4<u32> {
#[inline] #[inline]
fn from(f: Simdu32x4) -> Self { fn from(f: Simdu32x4) -> Self {
@ -1054,7 +1054,7 @@ impl From<Simdu32x4> for Vector4<u32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl Into<Simdu32x4> for Vector4<u32> { impl Into<Simdu32x4> for Vector4<u32> {
#[inline] #[inline]
fn into(self) -> Simdu32x4 { fn into(self) -> Simdu32x4 {
@ -1063,7 +1063,7 @@ impl Into<Simdu32x4> for Vector4<u32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{ impl_operator_simd!{
[Simdu32x4]; Add<Vector4<u32>> for Vector4<u32> { [Simdu32x4]; Add<Vector4<u32>> for Vector4<u32> {
fn add(lhs, rhs) -> Vector4<u32> { fn add(lhs, rhs) -> Vector4<u32> {
@ -1072,7 +1072,7 @@ impl_operator_simd!{
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{ impl_operator_simd!{
[Simdu32x4]; Sub<Vector4<u32>> for Vector4<u32> { [Simdu32x4]; Sub<Vector4<u32>> for Vector4<u32> {
fn sub(lhs, rhs) -> Vector4<u32> { fn sub(lhs, rhs) -> Vector4<u32> {
@ -1081,7 +1081,7 @@ impl_operator_simd!{
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl_operator_simd!{@rs impl_operator_simd!{@rs
[Simdu32x4]; Mul<u32> for Vector4<u32> { [Simdu32x4]; Mul<u32> for Vector4<u32> {
fn mul(lhs, rhs) -> Vector4<u32> { fn mul(lhs, rhs) -> Vector4<u32> {
@ -1090,7 +1090,7 @@ impl_operator_simd!{@rs
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl AddAssign for Vector4<u32> { impl AddAssign for Vector4<u32> {
#[inline] #[inline]
fn add_assign(&mut self, rhs: Self) { fn add_assign(&mut self, rhs: Self) {
@ -1100,7 +1100,7 @@ impl AddAssign for Vector4<u32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl SubAssign for Vector4<u32> { impl SubAssign for Vector4<u32> {
#[inline] #[inline]
fn sub_assign(&mut self, rhs: Self) { fn sub_assign(&mut self, rhs: Self) {
@ -1110,7 +1110,7 @@ impl SubAssign for Vector4<u32> {
} }
} }
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
impl MulAssign<u32> for Vector4<u32> { impl MulAssign<u32> for Vector4<u32> {
fn mul_assign(&mut self, other: u32) { fn mul_assign(&mut self, other: u32) {
let s: Simdu32x4 = (*self).into(); let s: Simdu32x4 = (*self).into();

View file

@ -146,7 +146,7 @@ mod test_magnitude {
assert_eq!(a.magnitude(), a_res); assert_eq!(a.magnitude(), a_res);
assert_eq!(b.magnitude(), b_res); assert_eq!(b.magnitude(), b_res);
#[cfg(feature = "use_simd")] #[cfg(feature = "simd")]
{ {
let a = Vector4::new(1f32, 4f32, 9f32, 16f32); let a = Vector4::new(1f32, 4f32, 9f32, 16f32);
assert_ulps_eq!(a.sqrt_element_wide(), Vector4::new(1f32, 2f32, 3f32, 4f32)); assert_ulps_eq!(a.sqrt_element_wide(), Vector4::new(1f32, 2f32, 3f32, 4f32));