From 275889f7f464614069e88ea8efbf41c560da0a06 Mon Sep 17 00:00:00 2001 From: Caleb Zulawski Date: Sat, 7 Aug 2021 21:06:40 +0000 Subject: [PATCH] Remove remaining usage of aliases --- crates/core_simd/src/permute.rs | 22 +++++------ crates/core_simd/src/vector.rs | 58 ++++++++++++++-------------- crates/core_simd/src/vector/float.rs | 48 +++++++++++------------ crates/core_simd/src/vector/int.rs | 20 +++++----- crates/core_simd/src/vector/ptr.rs | 10 ++--- crates/core_simd/tests/permute.rs | 10 ++--- crates/core_simd/tests/to_bytes.rs | 6 +-- 7 files changed, 87 insertions(+), 87 deletions(-) diff --git a/crates/core_simd/src/permute.rs b/crates/core_simd/src/permute.rs index 4e377d68915b..e1a085fd76db 100644 --- a/crates/core_simd/src/permute.rs +++ b/crates/core_simd/src/permute.rs @@ -15,12 +15,12 @@ macro_rules! impl_shuffle_lane { /// /// ``` /// #![feature(portable_simd)] - /// # use core_simd::*; - /// let a = f32x4::from_array([1.0, 2.0, 3.0, 4.0]); - /// let b = f32x4::from_array([5.0, 6.0, 7.0, 8.0]); + /// # use core_simd::Simd; + /// let a = Simd::from_array([1.0, 2.0, 3.0, 4.0]); + /// let b = Simd::from_array([5.0, 6.0, 7.0, 8.0]); /// const IDXS: [u32; 4] = [4,0,3,7]; - /// let c = f32x4::shuffle::(a,b); - /// assert_eq!(f32x4::from_array([5.0, 1.0, 4.0, 8.0]), c); + /// let c = Simd::<_, 4>::shuffle::(a,b); + /// assert_eq!(Simd::from_array([5.0, 1.0, 4.0, 8.0]), c); /// ``` #[inline] pub fn shuffle(self, second: Self) -> Self { @@ -56,9 +56,9 @@ macro_rules! impl_shuffle_lane { /// /// ``` /// #![feature(portable_simd)] - /// # use core_simd::SimdU32; - /// let a = SimdU32::from_array([0, 1, 2, 3]); - /// let b = SimdU32::from_array([4, 5, 6, 7]); + /// # use core_simd::Simd; + /// let a = Simd::from_array([0, 1, 2, 3]); + /// let b = Simd::from_array([4, 5, 6, 7]); /// let (x, y) = a.interleave(b); /// assert_eq!(x.to_array(), [0, 4, 1, 5]); /// assert_eq!(y.to_array(), [2, 6, 3, 7]); @@ -108,9 +108,9 @@ macro_rules! impl_shuffle_lane { /// /// ``` /// #![feature(portable_simd)] - /// # use core_simd::SimdU32; - /// let a = SimdU32::from_array([0, 4, 1, 5]); - /// let b = SimdU32::from_array([2, 6, 3, 7]); + /// # use core_simd::Simd; + /// let a = Simd::from_array([0, 4, 1, 5]); + /// let b = Simd::from_array([2, 6, 3, 7]); /// let (x, y) = a.deinterleave(b); /// assert_eq!(x.to_array(), [0, 1, 2, 3]); /// assert_eq!(y.to_array(), [4, 5, 6, 7]); diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs index 03c2f93a9c29..26c9bc0af6e1 100644 --- a/crates/core_simd/src/vector.rs +++ b/crates/core_simd/src/vector.rs @@ -9,7 +9,7 @@ pub use uint::*; // Vectors of pointers are not for public use at the current time. pub(crate) mod ptr; -use crate::{LaneCount, MaskElement, SupportedLaneCount}; +use crate::{LaneCount, Mask, MaskElement, SupportedLaneCount}; /// A SIMD vector of `LANES` elements of type `Element`. #[repr(simd)] @@ -54,16 +54,16 @@ where /// # #![feature(portable_simd)] /// # use core_simd::*; /// let vec: Vec = vec![10, 11, 12, 13, 14, 15, 16, 17, 18]; - /// let idxs = SimdUsize::<4>::from_array([9, 3, 0, 5]); - /// let alt = SimdI32::from_array([-5, -4, -3, -2]); + /// let idxs = Simd::from_array([9, 3, 0, 5]); + /// let alt = Simd::from_array([-5, -4, -3, -2]); /// - /// let result = SimdI32::<4>::gather_or(&vec, idxs, alt); // Note the lane that is out-of-bounds. - /// assert_eq!(result, SimdI32::from_array([-5, 13, 10, 15])); + /// let result = Simd::gather_or(&vec, idxs, alt); // Note the lane that is out-of-bounds. + /// assert_eq!(result, Simd::from_array([-5, 13, 10, 15])); /// ``` #[must_use] #[inline] - pub fn gather_or(slice: &[Element], idxs: crate::SimdUsize, or: Self) -> Self { - Self::gather_select(slice, crate::MaskSize::splat(true), idxs, or) + pub fn gather_or(slice: &[Element], idxs: Simd, or: Self) -> Self { + Self::gather_select(slice, Mask::splat(true), idxs, or) } /// SIMD gather: construct a SIMD vector by reading from a slice, using potentially discontiguous indices. @@ -72,14 +72,14 @@ where /// # #![feature(portable_simd)] /// # use core_simd::*; /// let vec: Vec = vec![10, 11, 12, 13, 14, 15, 16, 17, 18]; - /// let idxs = SimdUsize::<4>::from_array([9, 3, 0, 5]); + /// let idxs = Simd::from_array([9, 3, 0, 5]); /// - /// let result = SimdI32::<4>::gather_or_default(&vec, idxs); // Note the lane that is out-of-bounds. - /// assert_eq!(result, SimdI32::from_array([0, 13, 10, 15])); + /// let result = Simd::gather_or_default(&vec, idxs); // Note the lane that is out-of-bounds. + /// assert_eq!(result, Simd::from_array([0, 13, 10, 15])); /// ``` #[must_use] #[inline] - pub fn gather_or_default(slice: &[Element], idxs: crate::SimdUsize) -> Self + pub fn gather_or_default(slice: &[Element], idxs: Simd) -> Self where Element: Default, { @@ -92,22 +92,22 @@ where /// # #![feature(portable_simd)] /// # use core_simd::*; /// let vec: Vec = vec![10, 11, 12, 13, 14, 15, 16, 17, 18]; - /// let idxs = SimdUsize::<4>::from_array([9, 3, 0, 5]); - /// let alt = SimdI32::from_array([-5, -4, -3, -2]); - /// let mask = MaskSize::from_array([true, true, true, false]); // Note the mask of the last lane. + /// let idxs = Simd::from_array([9, 3, 0, 5]); + /// let alt = Simd::from_array([-5, -4, -3, -2]); + /// let mask = Mask::from_array([true, true, true, false]); // Note the mask of the last lane. /// - /// let result = SimdI32::<4>::gather_select(&vec, mask, idxs, alt); // Note the lane that is out-of-bounds. - /// assert_eq!(result, SimdI32::from_array([-5, 13, 10, -2])); + /// let result = Simd::gather_select(&vec, mask, idxs, alt); // Note the lane that is out-of-bounds. + /// assert_eq!(result, Simd::from_array([-5, 13, 10, -2])); /// ``` #[must_use] #[inline] pub fn gather_select( slice: &[Element], - mask: crate::MaskSize, - idxs: crate::SimdUsize, + mask: Mask, + idxs: Simd, or: Self, ) -> Self { - let mask = (mask & idxs.lanes_lt(crate::SimdUsize::splat(slice.len()))).to_int(); + let mask = (mask & idxs.lanes_lt(Simd::splat(slice.len()))).to_int(); let base_ptr = crate::vector::ptr::SimdConstPtr::splat(slice.as_ptr()); // Ferris forgive me, I have done pointer arithmetic here. let ptrs = base_ptr.wrapping_add(idxs); @@ -122,15 +122,15 @@ where /// # #![feature(portable_simd)] /// # use core_simd::*; /// let mut vec: Vec = vec![10, 11, 12, 13, 14, 15, 16, 17, 18]; - /// let idxs = SimdUsize::<4>::from_array([9, 3, 0, 0]); - /// let vals = SimdI32::from_array([-27, 82, -41, 124]); + /// let idxs = Simd::from_array([9, 3, 0, 0]); + /// let vals = Simd::from_array([-27, 82, -41, 124]); /// /// vals.scatter(&mut vec, idxs); // index 0 receives two writes. /// assert_eq!(vec, vec![124, 11, 12, 82, 14, 15, 16, 17, 18]); /// ``` #[inline] - pub fn scatter(self, slice: &mut [Element], idxs: crate::SimdUsize) { - self.scatter_select(slice, crate::MaskSize::splat(true), idxs) + pub fn scatter(self, slice: &mut [Element], idxs: Simd) { + self.scatter_select(slice, Mask::splat(true), idxs) } /// SIMD scatter: write a SIMD vector's values into a slice, using potentially discontiguous indices. @@ -140,9 +140,9 @@ where /// # #![feature(portable_simd)] /// # use core_simd::*; /// let mut vec: Vec = vec![10, 11, 12, 13, 14, 15, 16, 17, 18]; - /// let idxs = SimdUsize::<4>::from_array([9, 3, 0, 0]); - /// let vals = SimdI32::from_array([-27, 82, -41, 124]); - /// let mask = MaskSize::from_array([true, true, true, false]); // Note the mask of the last lane. + /// let idxs = Simd::from_array([9, 3, 0, 0]); + /// let vals = Simd::from_array([-27, 82, -41, 124]); + /// let mask = Mask::from_array([true, true, true, false]); // Note the mask of the last lane. /// /// vals.scatter_select(&mut vec, mask, idxs); // index 0's second write is masked, thus omitted. /// assert_eq!(vec, vec![-41, 11, 12, 82, 14, 15, 16, 17, 18]); @@ -151,11 +151,11 @@ where pub fn scatter_select( self, slice: &mut [Element], - mask: crate::MaskSize, - idxs: crate::SimdUsize, + mask: Mask, + idxs: Simd, ) { // We must construct our scatter mask before we derive a pointer! - let mask = (mask & idxs.lanes_lt(crate::SimdUsize::splat(slice.len()))).to_int(); + let mask = (mask & idxs.lanes_lt(Simd::splat(slice.len()))).to_int(); // SAFETY: This block works with *mut T derived from &mut 'a [T], // which means it is delicate in Rust's borrowing model, circa 2021: // &mut 'a [T] asserts uniqueness, so deriving &'a [T] invalidates live *mut Ts! diff --git a/crates/core_simd/src/vector/float.rs b/crates/core_simd/src/vector/float.rs index 840ad049d2e3..96aacdfcca10 100644 --- a/crates/core_simd/src/vector/float.rs +++ b/crates/core_simd/src/vector/float.rs @@ -1,29 +1,29 @@ #![allow(non_camel_case_types)] -use crate::{LaneCount, SupportedLaneCount}; +use crate::{LaneCount, Mask, Simd, SupportedLaneCount}; -/// Implements inherent methods for a float vector `$name` containing multiple +/// Implements inherent methods for a float vector containing multiple /// `$lanes` of float `$type`, which uses `$bits_ty` as its binary -/// representation. Called from `define_float_vector!`. +/// representation. macro_rules! impl_float_vector { - { $name:ident, $type:ident, $bits_ty:ident, $mask_ty:ident, $mask_impl_ty:ident } => { - impl $name + { $type:ty, $bits_ty:ty, $mask_ty:ty } => { + impl Simd<$type, LANES> where LaneCount: SupportedLaneCount, { /// Raw transmutation to an unsigned integer vector type with the /// same size and number of lanes. #[inline] - pub fn to_bits(self) -> crate::$bits_ty { - assert_eq!(core::mem::size_of::(), core::mem::size_of::>()); + pub fn to_bits(self) -> Simd<$bits_ty, LANES> { + assert_eq!(core::mem::size_of::(), core::mem::size_of::>()); unsafe { core::mem::transmute_copy(&self) } } /// Raw transmutation from an unsigned integer vector type with the /// same size and number of lanes. #[inline] - pub fn from_bits(bits: crate::$bits_ty) -> Self { - assert_eq!(core::mem::size_of::(), core::mem::size_of::>()); + pub fn from_bits(bits: Simd<$bits_ty, LANES>) -> Self { + assert_eq!(core::mem::size_of::(), core::mem::size_of::>()); unsafe { core::mem::transmute_copy(&bits) } } @@ -64,58 +64,58 @@ macro_rules! impl_float_vector { #[inline] pub fn to_degrees(self) -> Self { // to_degrees uses a special constant for better precision, so extract that constant - self * Self::splat($type::to_degrees(1.)) + self * Self::splat(<$type>::to_degrees(1.)) } /// Converts each lane from degrees to radians. #[inline] pub fn to_radians(self) -> Self { - self * Self::splat($type::to_radians(1.)) + self * Self::splat(<$type>::to_radians(1.)) } /// Returns true for each lane if it has a positive sign, including /// `+0.0`, `NaN`s with positive sign bit and positive infinity. #[inline] - pub fn is_sign_positive(self) -> crate::$mask_ty { + pub fn is_sign_positive(self) -> Mask<$mask_ty, LANES> { !self.is_sign_negative() } /// Returns true for each lane if it has a negative sign, including /// `-0.0`, `NaN`s with negative sign bit and negative infinity. #[inline] - pub fn is_sign_negative(self) -> crate::$mask_ty { - let sign_bits = self.to_bits() & crate::$bits_ty::splat((!0 >> 1) + 1); - sign_bits.lanes_gt(crate::$bits_ty::splat(0)) + pub fn is_sign_negative(self) -> Mask<$mask_ty, LANES> { + let sign_bits = self.to_bits() & Simd::splat((!0 >> 1) + 1); + sign_bits.lanes_gt(Simd::splat(0)) } /// Returns true for each lane if its value is `NaN`. #[inline] - pub fn is_nan(self) -> crate::$mask_ty { + pub fn is_nan(self) -> Mask<$mask_ty, LANES> { self.lanes_ne(self) } /// Returns true for each lane if its value is positive infinity or negative infinity. #[inline] - pub fn is_infinite(self) -> crate::$mask_ty { + pub fn is_infinite(self) -> Mask<$mask_ty, LANES> { self.abs().lanes_eq(Self::splat(<$type>::INFINITY)) } /// Returns true for each lane if its value is neither infinite nor `NaN`. #[inline] - pub fn is_finite(self) -> crate::$mask_ty { + pub fn is_finite(self) -> Mask<$mask_ty, LANES> { self.abs().lanes_lt(Self::splat(<$type>::INFINITY)) } /// Returns true for each lane if its value is subnormal. #[inline] - pub fn is_subnormal(self) -> crate::$mask_ty { - self.abs().lanes_ne(Self::splat(0.0)) & (self.to_bits() & Self::splat(<$type>::INFINITY).to_bits()).lanes_eq(crate::$bits_ty::splat(0)) + pub fn is_subnormal(self) -> Mask<$mask_ty, LANES> { + self.abs().lanes_ne(Self::splat(0.0)) & (self.to_bits() & Self::splat(<$type>::INFINITY).to_bits()).lanes_eq(Simd::splat(0)) } /// Returns true for each lane if its value is neither neither zero, infinite, /// subnormal, or `NaN`. #[inline] - pub fn is_normal(self) -> crate::$mask_ty { + pub fn is_normal(self) -> Mask<$mask_ty, LANES> { !(self.abs().lanes_eq(Self::splat(0.0)) | self.is_nan() | self.is_subnormal() | self.is_infinite()) } @@ -126,7 +126,7 @@ macro_rules! impl_float_vector { /// * `NAN` if the number is `NAN` #[inline] pub fn signum(self) -> Self { - self.is_nan().select(Self::splat($type::NAN), Self::splat(1.0).copysign(self)) + self.is_nan().select(Self::splat(<$type>::NAN), Self::splat(1.0).copysign(self)) } /// Returns each lane with the magnitude of `self` and the sign of `sign`. @@ -189,8 +189,8 @@ pub type SimdF32 = crate::Simd; /// A SIMD vector of containing `LANES` `f64` values. pub type SimdF64 = crate::Simd; -impl_float_vector! { SimdF32, f32, SimdU32, Mask32, SimdI32 } -impl_float_vector! { SimdF64, f64, SimdU64, Mask64, SimdI64 } +impl_float_vector! { f32, u32, i32 } +impl_float_vector! { f64, u64, i64 } /// Vector of two `f32` values pub type f32x2 = SimdF32<2>; diff --git a/crates/core_simd/src/vector/int.rs b/crates/core_simd/src/vector/int.rs index 3dad2abbe7cc..38d90ad62c0d 100644 --- a/crates/core_simd/src/vector/int.rs +++ b/crates/core_simd/src/vector/int.rs @@ -1,23 +1,23 @@ #![allow(non_camel_case_types)] -use crate::{LaneCount, SupportedLaneCount}; +use crate::{LaneCount, Mask, Simd, SupportedLaneCount}; /// Implements additional integer traits (Eq, Ord, Hash) on the specified vector `$name`, holding multiple `$lanes` of `$type`. macro_rules! impl_integer_vector { - { $name:ident, $type:ty, $mask_ty:ident, $mask_impl_ty:ident } => { - impl $name + { $type:ty } => { + impl Simd<$type, LANES> where LaneCount: SupportedLaneCount, { /// Returns true for each positive lane and false if it is zero or negative. #[inline] - pub fn is_positive(self) -> crate::$mask_ty { + pub fn is_positive(self) -> Mask<$type, LANES> { self.lanes_gt(Self::splat(0)) } /// Returns true for each negative lane and false if it is zero or positive. #[inline] - pub fn is_negative(self) -> crate::$mask_ty { + pub fn is_negative(self) -> Mask<$type, LANES> { self.lanes_lt(Self::splat(0)) } @@ -51,11 +51,11 @@ pub type SimdI64 = crate::Simd; /// A SIMD vector of containing `LANES` `isize` values. pub type SimdIsize = crate::Simd; -impl_integer_vector! { SimdIsize, isize, MaskSize, SimdIsize } -impl_integer_vector! { SimdI16, i16, Mask16, SimdI16 } -impl_integer_vector! { SimdI32, i32, Mask32, SimdI32 } -impl_integer_vector! { SimdI64, i64, Mask64, SimdI64 } -impl_integer_vector! { SimdI8, i8, Mask8, SimdI8 } +impl_integer_vector! { isize } +impl_integer_vector! { i16 } +impl_integer_vector! { i32 } +impl_integer_vector! { i64 } +impl_integer_vector! { i8 } /// Vector of two `isize` values pub type isizex2 = SimdIsize<2>; diff --git a/crates/core_simd/src/vector/ptr.rs b/crates/core_simd/src/vector/ptr.rs index 9dd1bfd0f365..fc4082a4b555 100644 --- a/crates/core_simd/src/vector/ptr.rs +++ b/crates/core_simd/src/vector/ptr.rs @@ -1,5 +1,5 @@ //! Private implementation details of public gather/scatter APIs. -use crate::{LaneCount, SimdUsize, SupportedLaneCount}; +use crate::{LaneCount, Simd, SupportedLaneCount}; use core::mem; /// A vector of *const T. @@ -20,9 +20,9 @@ where #[inline] #[must_use] - pub fn wrapping_add(self, addend: SimdUsize) -> Self { + pub fn wrapping_add(self, addend: Simd) -> Self { unsafe { - let x: SimdUsize = mem::transmute_copy(&self); + let x: Simd = mem::transmute_copy(&self); mem::transmute_copy(&{ x + (addend * mem::size_of::()) }) } } @@ -46,9 +46,9 @@ where #[inline] #[must_use] - pub fn wrapping_add(self, addend: SimdUsize) -> Self { + pub fn wrapping_add(self, addend: Simd) -> Self { unsafe { - let x: SimdUsize = mem::transmute_copy(&self); + let x: Simd = mem::transmute_copy(&self); mem::transmute_copy(&{ x + (addend * mem::size_of::()) }) } } diff --git a/crates/core_simd/tests/permute.rs b/crates/core_simd/tests/permute.rs index 4c771002528f..ea52e8f5ca73 100644 --- a/crates/core_simd/tests/permute.rs +++ b/crates/core_simd/tests/permute.rs @@ -1,6 +1,6 @@ #![feature(portable_simd)] -use core_simd::SimdU32; +use core_simd::Simd; #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; @@ -11,7 +11,7 @@ wasm_bindgen_test_configure!(run_in_browser); #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn simple_shuffle() { - let a = SimdU32::from_array([2, 4, 1, 9]); + let a = Simd::from_array([2, 4, 1, 9]); let b = a; assert_eq!(a.shuffle::<{ [3, 1, 4, 6] }>(b).to_array(), [9, 4, 2, 1]); } @@ -19,15 +19,15 @@ fn simple_shuffle() { #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn reverse() { - let a = SimdU32::from_array([0, 1, 2, 3, 4, 5, 6, 7]); + let a = Simd::from_array([0, 1, 2, 3, 4, 5, 6, 7]); assert_eq!(a.reverse().to_array(), [7, 6, 5, 4, 3, 2, 1, 0]); } #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn interleave() { - let a = SimdU32::from_array([0, 1, 2, 3, 4, 5, 6, 7]); - let b = SimdU32::from_array([8, 9, 10, 11, 12, 13, 14, 15]); + let a = Simd::from_array([0, 1, 2, 3, 4, 5, 6, 7]); + let b = Simd::from_array([8, 9, 10, 11, 12, 13, 14, 15]); let (lo, hi) = a.interleave(b); assert_eq!(lo.to_array(), [0, 8, 1, 9, 2, 10, 3, 11]); assert_eq!(hi.to_array(), [4, 12, 5, 13, 6, 14, 7, 15]); diff --git a/crates/core_simd/tests/to_bytes.rs b/crates/core_simd/tests/to_bytes.rs index 22c97c95d927..c66c9d5bd36f 100644 --- a/crates/core_simd/tests/to_bytes.rs +++ b/crates/core_simd/tests/to_bytes.rs @@ -2,13 +2,13 @@ #![allow(incomplete_features)] #![cfg(feature = "const_evaluatable_checked")] -use core_simd::SimdU32; +use core_simd::Simd; #[test] fn byte_convert() { - let int = SimdU32::from_array([0xdeadbeef, 0x8badf00d]); + let int = Simd::::from_array([0xdeadbeef, 0x8badf00d]); let bytes = int.to_ne_bytes(); assert_eq!(int[0].to_ne_bytes(), bytes[..4]); assert_eq!(int[1].to_ne_bytes(), bytes[4..]); - assert_eq!(SimdU32::from_ne_bytes(bytes), int); + assert_eq!(Simd::::from_ne_bytes(bytes), int); }