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.
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::fmt::{self, Debug, Formatter};
use std::mem;
@ -175,9 +175,7 @@ impl Add<F32x4> for F32x4 {
type Output = F32x4;
#[inline]
fn add(self, other: F32x4) -> F32x4 {
unsafe {
F32x4(simd_add(self.0, other.0))
}
unsafe { F32x4(simd_add(self.0, other.0)) }
}
}
@ -185,9 +183,7 @@ impl Mul<F32x4> for F32x4 {
type Output = F32x4;
#[inline]
fn mul(self, other: F32x4) -> F32x4 {
unsafe {
F32x4(simd_mul(self.0, other.0))
}
unsafe { F32x4(simd_mul(self.0, other.0)) }
}
}
@ -195,9 +191,7 @@ impl Sub<F32x4> for F32x4 {
type Output = F32x4;
#[inline]
fn sub(self, other: F32x4) -> F32x4 {
unsafe {
F32x4(simd_sub(self.0, other.0))
}
unsafe { F32x4(simd_sub(self.0, other.0)) }
}
}
@ -285,7 +279,6 @@ impl IndexMut<usize> for I32x4 {
}
}
impl Add<I32x4> for I32x4 {
type Output = I32x4;
#[inline]
@ -354,9 +347,7 @@ pub struct U8x16(pub uint8x16_t);
impl U8x16 {
#[inline]
pub fn as_i32x4(self) -> I32x4 {
unsafe {
I32x4(*mem::transmute::<&uint8x16_t, &int32x4_t>(&self.0))
}
unsafe { I32x4(*mem::transmute::<&uint8x16_t, &int32x4_t>(&self.0)) }
}
#[inline]

View File

@ -13,22 +13,29 @@
//! 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"))]
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 mod scalar;
#[cfg(all(pf_rustc_nightly, target_arch = "aarch64"))]
pub mod arm;
mod extras;
pub mod scalar;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub mod x86;
mod extras;
#[cfg(test)]
mod test;

View File

@ -71,12 +71,22 @@ impl F32x4 {
#[inline]
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]
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
@ -124,7 +134,12 @@ impl F32x4 {
// Converts these packed floats to integers.
#[inline]
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
@ -181,7 +196,12 @@ impl Add<F32x4> for F32x4 {
type Output = F32x4;
#[inline]
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;
#[inline]
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;
#[inline]
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]
pub fn as_u8x16(self) -> U8x16 {
unsafe {
U8x16(*mem::transmute::<&[i32; 4], &[u8; 16]>(&self.0))
}
unsafe { U8x16(*mem::transmute::<&[i32; 4], &[u8; 16]>(&self.0)) }
}
#[inline]
@ -268,7 +296,12 @@ impl I32x4 {
/// Converts these packed integers to floats.
#[inline]
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;
#[inline]
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;
#[inline]
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;
#[inline]
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],
])
}
}
@ -344,9 +392,7 @@ pub struct U8x16([u8; 16]);
impl U8x16 {
#[inline]
pub fn as_i32x4(self) -> I32x4 {
unsafe {
I32x4(*mem::transmute::<&[u8; 16], &[i32; 4]>(&self.0))
}
unsafe { I32x4(*mem::transmute::<&[u8; 16], &[i32; 4]>(&self.0)) }
}
#[inline]

View File

@ -68,9 +68,9 @@ fn test_f32x4_swizzles() {
fn test_f32x4_concatenations() {
let a = F32x4::new(4.0, 2.0, 6.0, -1.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_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_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_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));
}
@ -124,14 +124,14 @@ fn test_i32x4_constructors() {
#[test]
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);
assert_eq!(a.min(b), I32x4::new(6, -5, -40, 2));
}
#[test]
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);
assert_eq!(a.packed_eq(b), U32x4::new(0, !0, !0, 0));
}

View File

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

View File

@ -17,7 +17,9 @@ impl I32x4 {
pub fn xyxy(self) -> I32x4 {
unsafe {
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 {
unsafe {
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 {
unsafe {
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 {
unsafe {
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,
)))
}
}
}