Run `rustfmt` on the SIMD crate

This commit is contained in:
Patrick Walton 2019-04-29 16:57:21 -07:00
parent 60b951409c
commit 328e804378
6 changed files with 110 additions and 62 deletions

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
use std::arch::aarch64::{self, float32x4_t, int32x4_t, uint32x4_t, uint64x2_t, uint8x16_t}; use std::arch::aarch64::{self, float32x4_t, int32x4_t, uint32x4_t, uint64x2_t, uint8x16_t};
use std::arch::aarch64::{uint8x8x2_t, uint8x8_t}; use std::arch::aarch64::{uint8x8_t, uint8x8x2_t};
use std::f32; use std::f32;
use std::fmt::{self, Debug, Formatter}; use std::fmt::{self, Debug, Formatter};
use std::mem; use std::mem;
@ -175,9 +175,7 @@ impl Add<F32x4> for F32x4 {
type Output = F32x4; type Output = F32x4;
#[inline] #[inline]
fn add(self, other: F32x4) -> F32x4 { fn add(self, other: F32x4) -> F32x4 {
unsafe { unsafe { F32x4(simd_add(self.0, other.0)) }
F32x4(simd_add(self.0, other.0))
}
} }
} }
@ -185,9 +183,7 @@ impl Mul<F32x4> for F32x4 {
type Output = F32x4; type Output = F32x4;
#[inline] #[inline]
fn mul(self, other: F32x4) -> F32x4 { fn mul(self, other: F32x4) -> F32x4 {
unsafe { unsafe { F32x4(simd_mul(self.0, other.0)) }
F32x4(simd_mul(self.0, other.0))
}
} }
} }
@ -195,9 +191,7 @@ impl Sub<F32x4> for F32x4 {
type Output = F32x4; type Output = F32x4;
#[inline] #[inline]
fn sub(self, other: F32x4) -> F32x4 { fn sub(self, other: F32x4) -> F32x4 {
unsafe { unsafe { F32x4(simd_sub(self.0, other.0)) }
F32x4(simd_sub(self.0, other.0))
}
} }
} }
@ -285,7 +279,6 @@ impl IndexMut<usize> for I32x4 {
} }
} }
impl Add<I32x4> for I32x4 { impl Add<I32x4> for I32x4 {
type Output = I32x4; type Output = I32x4;
#[inline] #[inline]
@ -354,16 +347,14 @@ pub struct U8x16(pub uint8x16_t);
impl U8x16 { impl U8x16 {
#[inline] #[inline]
pub fn as_i32x4(self) -> I32x4 { pub fn as_i32x4(self) -> I32x4 {
unsafe { unsafe { I32x4(*mem::transmute::<&uint8x16_t, &int32x4_t>(&self.0)) }
I32x4(*mem::transmute::<&uint8x16_t, &int32x4_t>(&self.0))
}
} }
#[inline] #[inline]
pub fn shuffle(self, indices: U8x16) -> U8x16 { pub fn shuffle(self, indices: U8x16) -> U8x16 {
unsafe { unsafe {
let table = mem::transmute::<uint8x16_t, uint8x8x2_t>(self.0); let table = mem::transmute::<uint8x16_t, uint8x8x2_t>(self.0);
let low = aarch64::vtbl2_u8(table, indices.extract_low()); let low = aarch64::vtbl2_u8(table, indices.extract_low());
let high = aarch64::vtbl2_u8(table, indices.extract_high()); let high = aarch64::vtbl2_u8(table, indices.extract_high());
U8x16(aarch64::vcombine_u8(low, high)) U8x16(aarch64::vcombine_u8(low, high))
} }

View File

@ -13,22 +13,29 @@
//! A minimal SIMD abstraction, usable outside of Pathfinder. //! A minimal SIMD abstraction, usable outside of Pathfinder.
#[cfg(any(feature = "pf-no-simd",
not(any(target_arch = "x86",
target_arch = "x86_64",
all(pf_rustc_nightly, target_arch = "aarch64")))))]
pub use crate::scalar as default;
#[cfg(all(not(feature = "pf-no-simd"), pf_rustc_nightly, target_arch = "aarch64"))] #[cfg(all(not(feature = "pf-no-simd"), pf_rustc_nightly, target_arch = "aarch64"))]
pub use crate::arm as default; pub use crate::arm as default;
#[cfg(all(not(feature = "pf-no-simd"), any(target_arch = "x86", target_arch = "x86_64")))] #[cfg(any(
feature = "pf-no-simd",
not(any(
target_arch = "x86",
target_arch = "x86_64",
all(pf_rustc_nightly, target_arch = "aarch64")
))
))]
pub use crate::scalar as default;
#[cfg(all(
not(feature = "pf-no-simd"),
any(target_arch = "x86", target_arch = "x86_64")
))]
pub use crate::x86 as default; pub use crate::x86 as default;
pub mod scalar;
#[cfg(all(pf_rustc_nightly, target_arch = "aarch64"))] #[cfg(all(pf_rustc_nightly, target_arch = "aarch64"))]
pub mod arm; pub mod arm;
mod extras;
pub mod scalar;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub mod x86; pub mod x86;
mod extras;
#[cfg(test)] #[cfg(test)]
mod test; mod test;

View File

@ -71,12 +71,22 @@ impl F32x4 {
#[inline] #[inline]
pub fn floor(self) -> F32x4 { pub fn floor(self) -> F32x4 {
F32x4([self[0].floor(), self[1].floor(), self[2].floor(), self[3].floor()]) F32x4([
self[0].floor(),
self[1].floor(),
self[2].floor(),
self[3].floor(),
])
} }
#[inline] #[inline]
pub fn ceil(self) -> F32x4 { pub fn ceil(self) -> F32x4 {
F32x4([self[0].ceil(), self[1].ceil(), self[2].ceil(), self[3].ceil()]) F32x4([
self[0].ceil(),
self[1].ceil(),
self[2].ceil(),
self[3].ceil(),
])
} }
// Packed comparisons // Packed comparisons
@ -124,7 +134,12 @@ impl F32x4 {
// Converts these packed floats to integers. // Converts these packed floats to integers.
#[inline] #[inline]
pub fn to_i32x4(self) -> I32x4 { pub fn to_i32x4(self) -> I32x4 {
I32x4([self[0] as i32, self[1] as i32, self[2] as i32, self[3] as i32]) I32x4([
self[0] as i32,
self[1] as i32,
self[2] as i32,
self[3] as i32,
])
} }
// Concatenations // Concatenations
@ -181,7 +196,12 @@ impl Add<F32x4> for F32x4 {
type Output = F32x4; type Output = F32x4;
#[inline] #[inline]
fn add(self, other: F32x4) -> F32x4 { fn add(self, other: F32x4) -> F32x4 {
F32x4([self[0] + other[0], self[1] + other[1], self[2] + other[2], self[3] + other[3]]) F32x4([
self[0] + other[0],
self[1] + other[1],
self[2] + other[2],
self[3] + other[3],
])
} }
} }
@ -189,7 +209,12 @@ impl Mul<F32x4> for F32x4 {
type Output = F32x4; type Output = F32x4;
#[inline] #[inline]
fn mul(self, other: F32x4) -> F32x4 { fn mul(self, other: F32x4) -> F32x4 {
F32x4([self[0] * other[0], self[1] * other[1], self[2] * other[2], self[3] * other[3]]) F32x4([
self[0] * other[0],
self[1] * other[1],
self[2] * other[2],
self[3] * other[3],
])
} }
} }
@ -197,7 +222,12 @@ impl Sub<F32x4> for F32x4 {
type Output = F32x4; type Output = F32x4;
#[inline] #[inline]
fn sub(self, other: F32x4) -> F32x4 { fn sub(self, other: F32x4) -> F32x4 {
F32x4([self[0] - other[0], self[1] - other[1], self[2] - other[2], self[3] - other[3]]) F32x4([
self[0] - other[0],
self[1] - other[1],
self[2] - other[2],
self[3] - other[3],
])
} }
} }
@ -219,9 +249,7 @@ impl I32x4 {
#[inline] #[inline]
pub fn as_u8x16(self) -> U8x16 { pub fn as_u8x16(self) -> U8x16 {
unsafe { unsafe { U8x16(*mem::transmute::<&[i32; 4], &[u8; 16]>(&self.0)) }
U8x16(*mem::transmute::<&[i32; 4], &[u8; 16]>(&self.0))
}
} }
#[inline] #[inline]
@ -268,7 +296,12 @@ impl I32x4 {
/// Converts these packed integers to floats. /// Converts these packed integers to floats.
#[inline] #[inline]
pub fn to_f32x4(self) -> F32x4 { pub fn to_f32x4(self) -> F32x4 {
F32x4([self[0] as f32, self[1] as f32, self[2] as f32, self[3] as f32]) F32x4([
self[0] as f32,
self[1] as f32,
self[2] as f32,
self[3] as f32,
])
} }
} }
@ -291,7 +324,12 @@ impl Add<I32x4> for I32x4 {
type Output = I32x4; type Output = I32x4;
#[inline] #[inline]
fn add(self, other: I32x4) -> I32x4 { fn add(self, other: I32x4) -> I32x4 {
I32x4([self[0] + other[0], self[1] + other[1], self[2] + other[2], self[3] + other[3]]) I32x4([
self[0] + other[0],
self[1] + other[1],
self[2] + other[2],
self[3] + other[3],
])
} }
} }
@ -299,7 +337,12 @@ impl Sub<I32x4> for I32x4 {
type Output = I32x4; type Output = I32x4;
#[inline] #[inline]
fn sub(self, other: I32x4) -> I32x4 { fn sub(self, other: I32x4) -> I32x4 {
I32x4([self[0] - other[0], self[1] - other[1], self[2] - other[2], self[3] - other[3]]) I32x4([
self[0] - other[0],
self[1] - other[1],
self[2] - other[2],
self[3] - other[3],
])
} }
} }
@ -307,7 +350,12 @@ impl Mul<I32x4> for I32x4 {
type Output = I32x4; type Output = I32x4;
#[inline] #[inline]
fn mul(self, other: I32x4) -> I32x4 { fn mul(self, other: I32x4) -> I32x4 {
I32x4([self[0] * other[0], self[1] * other[1], self[2] * other[2], self[3] * other[3]]) I32x4([
self[0] * other[0],
self[1] * other[1],
self[2] * other[2],
self[3] * other[3],
])
} }
} }
@ -324,7 +372,7 @@ impl U32x4 {
#[inline] #[inline]
pub fn is_all_zeroes(&self) -> bool { pub fn is_all_zeroes(&self) -> bool {
self[0] == 0 && self[1] == 0 && self[2] == 0 && self[3] == 0 self[0] == 0 && self[1] == 0 && self[2] == 0 && self[3] == 0
} }
} }
@ -344,9 +392,7 @@ pub struct U8x16([u8; 16]);
impl U8x16 { impl U8x16 {
#[inline] #[inline]
pub fn as_i32x4(self) -> I32x4 { pub fn as_i32x4(self) -> I32x4 {
unsafe { unsafe { I32x4(*mem::transmute::<&[u8; 16], &[i32; 4]>(&self.0)) }
I32x4(*mem::transmute::<&[u8; 16], &[i32; 4]>(&self.0))
}
} }
#[inline] #[inline]

View File

@ -44,7 +44,7 @@ fn test_f32x4_basic_ops() {
#[test] #[test]
fn test_f32x4_packed_comparisons() { fn test_f32x4_packed_comparisons() {
let a = F32x4::new(7.0, 3.0, 6.0, -2.0); let a = F32x4::new(7.0, 3.0, 6.0, -2.0);
let b = F32x4::new(10.0, 3.0, 5.0, -2.0); let b = F32x4::new(10.0, 3.0, 5.0, -2.0);
assert_eq!(a.packed_eq(b), U32x4::new(0, !0, 0, !0)); assert_eq!(a.packed_eq(b), U32x4::new(0, !0, 0, !0));
} }
@ -66,19 +66,19 @@ fn test_f32x4_swizzles() {
#[test] #[test]
fn test_f32x4_concatenations() { fn test_f32x4_concatenations() {
let a = F32x4::new(4.0, 2.0, 6.0, -1.0); let a = F32x4::new(4.0, 2.0, 6.0, -1.0);
let b = F32x4::new(10.0, -3.0, 15.0, 41.0); let b = F32x4::new(10.0, -3.0, 15.0, 41.0);
assert_eq!(a.concat_xy_xy(b), F32x4::new( 4.0, 2.0, 10.0, -3.0)); assert_eq!(a.concat_xy_xy(b), F32x4::new(4.0, 2.0, 10.0, -3.0));
assert_eq!(a.concat_xy_zw(b), F32x4::new( 4.0, 2.0, 15.0, 41.0)); assert_eq!(a.concat_xy_zw(b), F32x4::new(4.0, 2.0, 15.0, 41.0));
assert_eq!(a.concat_zw_zw(b), F32x4::new( 6.0, -1.0, 15.0, 41.0)); assert_eq!(a.concat_zw_zw(b), F32x4::new(6.0, -1.0, 15.0, 41.0));
assert_eq!(a.concat_wz_yx(b), F32x4::new(-1.0, 6.0, -3.0, 10.0)); assert_eq!(a.concat_wz_yx(b), F32x4::new(-1.0, 6.0, -3.0, 10.0));
} }
#[test] #[test]
fn test_f32x4_arithmetic_overloads() { fn test_f32x4_arithmetic_overloads() {
let a = F32x4::new(4.0, -1.0, 6.0, -32.0); let a = F32x4::new(4.0, -1.0, 6.0, -32.0);
let b = F32x4::new(0.5, 0.5, 10.0, 3.0); let b = F32x4::new(0.5, 0.5, 10.0, 3.0);
let a_plus_b = F32x4::new(4.5, -0.5, 16.0, -29.0); let a_plus_b = F32x4::new(4.5, -0.5, 16.0, -29.0);
let a_minus_b = F32x4::new(3.5, -1.5, -4.0, -35.0); let a_minus_b = F32x4::new(3.5, -1.5, -4.0, -35.0);
let a_times_b = F32x4::new(2.0, -0.5, 60.0, -96.0); let a_times_b = F32x4::new(2.0, -0.5, 60.0, -96.0);
assert_eq!(a + b, a_plus_b); assert_eq!(a + b, a_plus_b);
@ -124,14 +124,14 @@ fn test_i32x4_constructors() {
#[test] #[test]
fn test_i32x4_basic_ops() { fn test_i32x4_basic_ops() {
let a = I32x4::new(6, 29, -40, 2 ); let a = I32x4::new(6, 29, -40, 2);
let b = I32x4::new(10, -5, 10, 46); let b = I32x4::new(10, -5, 10, 46);
assert_eq!(a.min(b), I32x4::new(6, -5, -40, 2)); assert_eq!(a.min(b), I32x4::new(6, -5, -40, 2));
} }
#[test] #[test]
fn test_i32x4_packed_comparisons() { fn test_i32x4_packed_comparisons() {
let a = I32x4::new( 59, 1, 5, 63 ); let a = I32x4::new(59, 1, 5, 63);
let b = I32x4::new(-59, 1, 5, 104); let b = I32x4::new(-59, 1, 5, 104);
assert_eq!(a.packed_eq(b), U32x4::new(0, !0, !0, 0)); assert_eq!(a.packed_eq(b), U32x4::new(0, !0, !0, 0));
} }

View File

@ -284,9 +284,7 @@ impl I32x4 {
#[inline] #[inline]
pub fn packed_gt(self, other: I32x4) -> U32x4 { pub fn packed_gt(self, other: I32x4) -> U32x4 {
unsafe { unsafe { U32x4(x86_64::_mm_cmpgt_epi32(self.0, other.0)) }
U32x4(x86_64::_mm_cmpgt_epi32(self.0, other.0))
}
} }
#[inline] #[inline]
@ -430,9 +428,7 @@ impl BitXor<U32x4> for U32x4 {
type Output = U32x4; type Output = U32x4;
#[inline] #[inline]
fn bitxor(self, other: U32x4) -> U32x4 { fn bitxor(self, other: U32x4) -> U32x4 {
unsafe { unsafe { U32x4(x86_64::_mm_xor_si128(self.0, other.0)) }
U32x4(x86_64::_mm_xor_si128(self.0, other.0))
}
} }
} }

View File

@ -17,7 +17,9 @@ impl I32x4 {
pub fn xyxy(self) -> I32x4 { pub fn xyxy(self) -> I32x4 {
unsafe { unsafe {
let this = x86_64::_mm_castsi128_ps(self.0); let this = x86_64::_mm_castsi128_ps(self.0);
I32x4(x86_64::_mm_castps_si128(x86_64::_mm_shuffle_ps(this, this, 68))) I32x4(x86_64::_mm_castps_si128(x86_64::_mm_shuffle_ps(
this, this, 68,
)))
} }
} }
@ -25,7 +27,9 @@ impl I32x4 {
pub fn xwzy(self) -> I32x4 { pub fn xwzy(self) -> I32x4 {
unsafe { unsafe {
let this = x86_64::_mm_castsi128_ps(self.0); let this = x86_64::_mm_castsi128_ps(self.0);
I32x4(x86_64::_mm_castps_si128(x86_64::_mm_shuffle_ps(this, this, 108))) I32x4(x86_64::_mm_castps_si128(x86_64::_mm_shuffle_ps(
this, this, 108,
)))
} }
} }
@ -33,7 +37,9 @@ impl I32x4 {
pub fn zyxw(self) -> I32x4 { pub fn zyxw(self) -> I32x4 {
unsafe { unsafe {
let this = x86_64::_mm_castsi128_ps(self.0); let this = x86_64::_mm_castsi128_ps(self.0);
I32x4(x86_64::_mm_castps_si128(x86_64::_mm_shuffle_ps(this, this, 198))) I32x4(x86_64::_mm_castps_si128(x86_64::_mm_shuffle_ps(
this, this, 198,
)))
} }
} }
@ -41,7 +47,9 @@ impl I32x4 {
pub fn zwxy(self) -> I32x4 { pub fn zwxy(self) -> I32x4 {
unsafe { unsafe {
let this = x86_64::_mm_castsi128_ps(self.0); let this = x86_64::_mm_castsi128_ps(self.0);
I32x4(x86_64::_mm_castps_si128(x86_64::_mm_shuffle_ps(this, this, 78))) I32x4(x86_64::_mm_castps_si128(x86_64::_mm_shuffle_ps(
this, this, 78,
)))
} }
} }
} }