From c51ef0d7d5c30a4d5687e8922c7e9a1a4d2f1976 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Tue, 30 Jan 2018 16:07:40 +0100 Subject: [PATCH] Remove unused simd implementation of side offsets. --- src/lib.rs | 4 +- src/side_offsets.rs | 156 -------------------------------------------- 2 files changed, 1 insertion(+), 159 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 10cc5a19..66d3071b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg_attr(feature = "unstable", feature(asm, cfg_target_feature, repr_simd, test, fn_must_use))] +#![cfg_attr(feature = "unstable", feature(cfg_target_feature, test, fn_must_use))] //! A collection of strongly typed math tools for computer graphics with an inclination //! towards 2d graphics and layout. @@ -74,8 +74,6 @@ pub use vector::{TypedVector2D, TypedVector3D, Vector2D, Vector3D, vec2, vec3}; pub use rect::{rect, Rect, TypedRect}; pub use rotation::{Angle, Rotation2D, Rotation3D, TypedRotation2D, TypedRotation3D}; pub use side_offsets::{SideOffsets2D, TypedSideOffsets2D}; -#[cfg(feature = "unstable")] -pub use side_offsets::SideOffsets2DSimdI32; pub use size::{Size2D, TypedSize2D, size2}; pub use trig::Trig; diff --git a/src/side_offsets.rs b/src/side_offsets.rs index 0e099e10..fc424371 100644 --- a/src/side_offsets.rs +++ b/src/side_offsets.rs @@ -136,159 +136,3 @@ impl TypedSideOffsets2D { TypedSideOffsets2D::new(Zero::zero(), Zero::zero(), Zero::zero(), Zero::zero()) } } - -/// A SIMD enabled version of TypedSideOffsets2D specialized for i32. -#[cfg(feature = "unstable")] -#[derive(Clone, Copy, PartialEq)] -#[repr(simd)] -pub struct SideOffsets2DSimdI32 { - pub top: i32, - pub bottom: i32, - pub right: i32, - pub left: i32, -} - -#[cfg(feature = "unstable")] -impl SideOffsets2DSimdI32 { - #[inline] - pub fn new(top: i32, right: i32, bottom: i32, left: i32) -> SideOffsets2DSimdI32 { - SideOffsets2DSimdI32 { - top: top, - bottom: bottom, - right: right, - left: left, - } - } -} - -#[cfg(feature = "unstable")] -impl SideOffsets2DSimdI32 { - #[inline] - pub fn new_all_same(all: i32) -> SideOffsets2DSimdI32 { - SideOffsets2DSimdI32::new(all.clone(), all.clone(), all.clone(), all.clone()) - } -} - -#[cfg(feature = "unstable")] -impl SideOffsets2DSimdI32 { - #[inline] - pub fn horizontal(&self) -> i32 { - self.left + self.right - } - - #[inline] - pub fn vertical(&self) -> i32 { - self.top + self.bottom - } -} - -/*impl Add for SideOffsets2DSimdI32 { - type Output = SideOffsets2DSimdI32; - #[inline] - fn add(self, other: SideOffsets2DSimdI32) -> SideOffsets2DSimdI32 { - self + other // Use SIMD addition - } -}*/ - -#[cfg(feature = "unstable")] -impl SideOffsets2DSimdI32 { - #[inline] - pub fn zero() -> SideOffsets2DSimdI32 { - SideOffsets2DSimdI32 { - top: 0, - bottom: 0, - right: 0, - left: 0, - } - } - - #[cfg(not(target_feature = "sse4.1"))] - #[inline] - pub fn is_zero(&self) -> bool { - self.top == 0 && self.right == 0 && self.bottom == 0 && self.left == 0 - } - - #[cfg(target_feature = "sse4.1")] - #[inline] - pub fn is_zero(&self) -> bool { - let is_zero: bool; - unsafe { - asm! { - "ptest $1, $1 - setz $0" - : "=r"(is_zero) - : "x"(*self) - : - : "intel" - }; - } - is_zero - } -} - -#[cfg(feature = "unstable")] -#[cfg(test)] -mod tests { - use super::SideOffsets2DSimdI32; - - #[test] - fn test_is_zero() { - assert!(SideOffsets2DSimdI32::new_all_same(0).is_zero()); - assert!(!SideOffsets2DSimdI32::new_all_same(1).is_zero()); - assert!(!SideOffsets2DSimdI32::new(1, 0, 0, 0).is_zero()); - assert!(!SideOffsets2DSimdI32::new(0, 1, 0, 0).is_zero()); - assert!(!SideOffsets2DSimdI32::new(0, 0, 1, 0).is_zero()); - assert!(!SideOffsets2DSimdI32::new(0, 0, 0, 1).is_zero()); - } -} - -#[cfg(feature = "unstable")] -#[cfg(bench)] -mod bench { - use test::BenchHarness; - use std::num::Zero; - use rand::{Rng, XorShiftRng}; - use super::SideOffsets2DSimdI32; - - #[cfg(target_arch = "x86")] - #[cfg(target_arch = "x86_64")] - #[bench] - fn bench_naive_is_zero(bh: &mut BenchHarness) { - fn is_zero(x: &SideOffsets2DSimdI32) -> bool { - x.top.is_zero() && x.right.is_zero() && x.bottom.is_zero() && x.left.is_zero() - } - let mut rng = XorShiftRng::new().unwrap(); - bh.iter(|| is_zero(&rng.gen::())) - } - - #[bench] - fn bench_is_zero(bh: &mut BenchHarness) { - let mut rng = XorShiftRng::new().unwrap(); - bh.iter(|| rng.gen::().is_zero()) - } - - #[bench] - fn bench_naive_add(bh: &mut BenchHarness) { - fn add(x: &SideOffsets2DSimdI32, y: &SideOffsets2DSimdI32) -> SideOffsets2DSimdI32 { - SideOffsets2DSimdI32 { - top: x.top + y.top, - right: x.right + y.right, - bottom: x.bottom + y.bottom, - left: x.left + y.left, - } - } - let mut rng = XorShiftRng::new().unwrap(); - bh.iter(|| { - add( - &rng.gen::(), - &rng.gen::(), - ) - }) - } - - #[bench] - fn bench_add(bh: &mut BenchHarness) { - let mut rng = XorShiftRng::new().unwrap(); - bh.iter(|| rng.gen::() + rng.gen::()) - } -}