From 328e804378ab61113fd3e8088fb867aa24063804 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 29 Apr 2019 16:57:21 -0700 Subject: [PATCH] Run `rustfmt` on the SIMD crate --- simd/src/arm/mod.rs | 21 +++------ simd/src/lib.rs | 23 ++++++---- simd/src/scalar/mod.rs | 80 +++++++++++++++++++++++++++-------- simd/src/test.rs | 24 +++++------ simd/src/x86/mod.rs | 8 +--- simd/src/x86/swizzle_i32x4.rs | 16 +++++-- 6 files changed, 110 insertions(+), 62 deletions(-) diff --git a/simd/src/arm/mod.rs b/simd/src/arm/mod.rs index d7c6e251..89ffe691 100644 --- a/simd/src/arm/mod.rs +++ b/simd/src/arm/mod.rs @@ -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 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 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 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 for I32x4 { } } - impl Add for I32x4 { type Output = I32x4; #[inline] @@ -354,16 +347,14 @@ 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] pub fn shuffle(self, indices: U8x16) -> U8x16 { unsafe { let table = mem::transmute::(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()); U8x16(aarch64::vcombine_u8(low, high)) } diff --git a/simd/src/lib.rs b/simd/src/lib.rs index 5e40ac32..cbffc2a4 100644 --- a/simd/src/lib.rs +++ b/simd/src/lib.rs @@ -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; diff --git a/simd/src/scalar/mod.rs b/simd/src/scalar/mod.rs index 9d6a35d0..cd18bcb3 100644 --- a/simd/src/scalar/mod.rs +++ b/simd/src/scalar/mod.rs @@ -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 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 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 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 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 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 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], + ]) } } @@ -324,7 +372,7 @@ impl U32x4 { #[inline] 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 { #[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] diff --git a/simd/src/test.rs b/simd/src/test.rs index 6186ef93..a9814473 100644 --- a/simd/src/test.rs +++ b/simd/src/test.rs @@ -44,7 +44,7 @@ fn test_f32x4_basic_ops() { #[test] 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); assert_eq!(a.packed_eq(b), U32x4::new(0, !0, 0, !0)); } @@ -66,19 +66,19 @@ fn test_f32x4_swizzles() { #[test] 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); - 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)); + 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)); } #[test] fn test_f32x4_arithmetic_overloads() { - 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 a_plus_b = F32x4::new(4.5, -0.5, 16.0, -29.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 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_times_b = F32x4::new(2.0, -0.5, 60.0, -96.0); assert_eq!(a + b, a_plus_b); @@ -124,14 +124,14 @@ fn test_i32x4_constructors() { #[test] fn test_i32x4_basic_ops() { - let a = I32x4::new(6, 29, -40, 2 ); - let b = I32x4::new(10, -5, 10, 46); + 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)); } diff --git a/simd/src/x86/mod.rs b/simd/src/x86/mod.rs index a8215b88..5aadde51 100644 --- a/simd/src/x86/mod.rs +++ b/simd/src/x86/mod.rs @@ -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 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)) } } } diff --git a/simd/src/x86/swizzle_i32x4.rs b/simd/src/x86/swizzle_i32x4.rs index 01ed65c5..2a51b1b7 100644 --- a/simd/src/x86/swizzle_i32x4.rs +++ b/simd/src/x86/swizzle_i32x4.rs @@ -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, + ))) } } }