Skip to content

Commit 049ce35

Browse files
author
bors-servo
authored
Auto merge of #268 - nical:rm-sideoffsets-simd, r=SimonSapin
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 -->
2 parents 7bb2617 + c51ef0d commit 049ce35

File tree

2 files changed

+1
-159
lines changed

2 files changed

+1
-159
lines changed

src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
#![cfg_attr(feature = "unstable", feature(asm, cfg_target_feature, repr_simd, test, fn_must_use))]
10+
#![cfg_attr(feature = "unstable", feature(cfg_target_feature, test, fn_must_use))]
1111

1212
//! A collection of strongly typed math tools for computer graphics with an inclination
1313
//! towards 2d graphics and layout.
@@ -75,8 +75,6 @@ pub use vector::{TypedVector2D, TypedVector3D, Vector2D, Vector3D, vec2, vec3};
7575
pub use rect::{rect, Rect, TypedRect};
7676
pub use rotation::{Angle, Rotation2D, Rotation3D, TypedRotation2D, TypedRotation3D};
7777
pub use side_offsets::{SideOffsets2D, TypedSideOffsets2D};
78-
#[cfg(feature = "unstable")]
79-
pub use side_offsets::SideOffsets2DSimdI32;
8078
pub use size::{Size2D, TypedSize2D, size2};
8179
pub use trig::Trig;
8280

src/side_offsets.rs

Lines changed: 0 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -136,159 +136,3 @@ impl<T: Copy + Zero, U> TypedSideOffsets2D<T, U> {
136136
TypedSideOffsets2D::new(Zero::zero(), Zero::zero(), Zero::zero(), Zero::zero())
137137
}
138138
}
139-
140-
/// A SIMD enabled version of TypedSideOffsets2D specialized for i32.
141-
#[cfg(feature = "unstable")]
142-
#[derive(Clone, Copy, PartialEq)]
143-
#[repr(simd)]
144-
pub struct SideOffsets2DSimdI32 {
145-
pub top: i32,
146-
pub bottom: i32,
147-
pub right: i32,
148-
pub left: i32,
149-
}
150-
151-
#[cfg(feature = "unstable")]
152-
impl SideOffsets2DSimdI32 {
153-
#[inline]
154-
pub fn new(top: i32, right: i32, bottom: i32, left: i32) -> SideOffsets2DSimdI32 {
155-
SideOffsets2DSimdI32 {
156-
top: top,
157-
bottom: bottom,
158-
right: right,
159-
left: left,
160-
}
161-
}
162-
}
163-
164-
#[cfg(feature = "unstable")]
165-
impl SideOffsets2DSimdI32 {
166-
#[inline]
167-
pub fn new_all_same(all: i32) -> SideOffsets2DSimdI32 {
168-
SideOffsets2DSimdI32::new(all.clone(), all.clone(), all.clone(), all.clone())
169-
}
170-
}
171-
172-
#[cfg(feature = "unstable")]
173-
impl SideOffsets2DSimdI32 {
174-
#[inline]
175-
pub fn horizontal(&self) -> i32 {
176-
self.left + self.right
177-
}
178-
179-
#[inline]
180-
pub fn vertical(&self) -> i32 {
181-
self.top + self.bottom
182-
}
183-
}
184-
185-
/*impl Add for SideOffsets2DSimdI32 {
186-
type Output = SideOffsets2DSimdI32;
187-
#[inline]
188-
fn add(self, other: SideOffsets2DSimdI32) -> SideOffsets2DSimdI32 {
189-
self + other // Use SIMD addition
190-
}
191-
}*/
192-
193-
#[cfg(feature = "unstable")]
194-
impl SideOffsets2DSimdI32 {
195-
#[inline]
196-
pub fn zero() -> SideOffsets2DSimdI32 {
197-
SideOffsets2DSimdI32 {
198-
top: 0,
199-
bottom: 0,
200-
right: 0,
201-
left: 0,
202-
}
203-
}
204-
205-
#[cfg(not(target_feature = "sse4.1"))]
206-
#[inline]
207-
pub fn is_zero(&self) -> bool {
208-
self.top == 0 && self.right == 0 && self.bottom == 0 && self.left == 0
209-
}
210-
211-
#[cfg(target_feature = "sse4.1")]
212-
#[inline]
213-
pub fn is_zero(&self) -> bool {
214-
let is_zero: bool;
215-
unsafe {
216-
asm! {
217-
"ptest $1, $1
218-
setz $0"
219-
: "=r"(is_zero)
220-
: "x"(*self)
221-
:
222-
: "intel"
223-
};
224-
}
225-
is_zero
226-
}
227-
}
228-
229-
#[cfg(feature = "unstable")]
230-
#[cfg(test)]
231-
mod tests {
232-
use super::SideOffsets2DSimdI32;
233-
234-
#[test]
235-
fn test_is_zero() {
236-
assert!(SideOffsets2DSimdI32::new_all_same(0).is_zero());
237-
assert!(!SideOffsets2DSimdI32::new_all_same(1).is_zero());
238-
assert!(!SideOffsets2DSimdI32::new(1, 0, 0, 0).is_zero());
239-
assert!(!SideOffsets2DSimdI32::new(0, 1, 0, 0).is_zero());
240-
assert!(!SideOffsets2DSimdI32::new(0, 0, 1, 0).is_zero());
241-
assert!(!SideOffsets2DSimdI32::new(0, 0, 0, 1).is_zero());
242-
}
243-
}
244-
245-
#[cfg(feature = "unstable")]
246-
#[cfg(bench)]
247-
mod bench {
248-
use test::BenchHarness;
249-
use std::num::Zero;
250-
use rand::{Rng, XorShiftRng};
251-
use super::SideOffsets2DSimdI32;
252-
253-
#[cfg(target_arch = "x86")]
254-
#[cfg(target_arch = "x86_64")]
255-
#[bench]
256-
fn bench_naive_is_zero(bh: &mut BenchHarness) {
257-
fn is_zero(x: &SideOffsets2DSimdI32) -> bool {
258-
x.top.is_zero() && x.right.is_zero() && x.bottom.is_zero() && x.left.is_zero()
259-
}
260-
let mut rng = XorShiftRng::new().unwrap();
261-
bh.iter(|| is_zero(&rng.gen::<SideOffsets2DSimdI32>()))
262-
}
263-
264-
#[bench]
265-
fn bench_is_zero(bh: &mut BenchHarness) {
266-
let mut rng = XorShiftRng::new().unwrap();
267-
bh.iter(|| rng.gen::<SideOffsets2DSimdI32>().is_zero())
268-
}
269-
270-
#[bench]
271-
fn bench_naive_add(bh: &mut BenchHarness) {
272-
fn add(x: &SideOffsets2DSimdI32, y: &SideOffsets2DSimdI32) -> SideOffsets2DSimdI32 {
273-
SideOffsets2DSimdI32 {
274-
top: x.top + y.top,
275-
right: x.right + y.right,
276-
bottom: x.bottom + y.bottom,
277-
left: x.left + y.left,
278-
}
279-
}
280-
let mut rng = XorShiftRng::new().unwrap();
281-
bh.iter(|| {
282-
add(
283-
&rng.gen::<SideOffsets2DSimdI32>(),
284-
&rng.gen::<SideOffsets2DSimdI32>(),
285-
)
286-
})
287-
}
288-
289-
#[bench]
290-
fn bench_add(bh: &mut BenchHarness) {
291-
let mut rng = XorShiftRng::new().unwrap();
292-
bh.iter(|| rng.gen::<SideOffsets2DSimdI32>() + rng.gen::<SideOffsets2DSimdI32>())
293-
}
294-
}

0 commit comments

Comments
 (0)