Skip to content

Commit

Permalink
Auto merge of #268 - nical:rm-sideoffsets-simd, r=SimonSapin
Browse files Browse the repository at this point in the history
Remove unused simd implementation of side offsets.

This is kind of a breaking change for people that enable `--features unstable`. I believe that servo does not use this. I'd rather remove it for now and potentially re-add it or reimplement it when simd in stable rust is a thing and we need simd-ified side offsets.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/euclid/268)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo authored Jan 30, 2018
2 parents 7bb2617 + c51ef0d commit 049ce35
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 159 deletions.
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -75,8 +75,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;

Expand Down
156 changes: 0 additions & 156 deletions src/side_offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,159 +136,3 @@ impl<T: Copy + Zero, U> TypedSideOffsets2D<T, U> {
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::<SideOffsets2DSimdI32>()))
}

#[bench]
fn bench_is_zero(bh: &mut BenchHarness) {
let mut rng = XorShiftRng::new().unwrap();
bh.iter(|| rng.gen::<SideOffsets2DSimdI32>().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::<SideOffsets2DSimdI32>(),
&rng.gen::<SideOffsets2DSimdI32>(),
)
})
}

#[bench]
fn bench_add(bh: &mut BenchHarness) {
let mut rng = XorShiftRng::new().unwrap();
bh.iter(|| rng.gen::<SideOffsets2DSimdI32>() + rng.gen::<SideOffsets2DSimdI32>())
}
}

0 comments on commit 049ce35

Please sign in to comment.