From b25ed7f86d457d64194740730136bf72e9b92aaf Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sat, 18 Sep 2021 18:31:49 -0700 Subject: [PATCH] Restructure crate as core module Aligns module with rust-lang/library/core, creating an... unusual architecture that is easier to pull in as a module, as core itself can have no dependencies (as we haven't built core yet). --- crates/core_simd/src/comparisons.rs | 15 ++++++----- crates/core_simd/src/core_simd_docs.md | 4 +++ crates/core_simd/src/fmt.rs | 17 +++++++----- crates/core_simd/src/intrinsics.rs | 6 ++--- crates/core_simd/src/iter.rs | 4 +-- crates/core_simd/src/lib.rs | 31 +++------------------- crates/core_simd/src/masks.rs | 12 +++++---- crates/core_simd/src/masks/bitmask.rs | 11 +++----- crates/core_simd/src/masks/full_masks.rs | 19 +++++++------- crates/core_simd/src/math.rs | 11 ++++---- crates/core_simd/src/mod.rs | 33 ++++++++++++++++++++++++ crates/core_simd/src/ops.rs | 25 +++++++++--------- crates/core_simd/src/permute.rs | 9 ++++--- crates/core_simd/src/reduction.rs | 28 +++++++++++--------- crates/core_simd/src/round.rs | 15 ++++++----- crates/core_simd/src/select.rs | 5 ++-- crates/core_simd/src/to_bytes.rs | 10 +++---- crates/core_simd/src/vector.rs | 11 ++++---- crates/core_simd/src/vector/float.rs | 9 ++++--- crates/core_simd/src/vector/int.rs | 2 +- crates/core_simd/src/vector/ptr.rs | 2 +- crates/core_simd/src/vector/uint.rs | 2 +- crates/core_simd/src/vendor/arm.rs | 2 +- crates/core_simd/src/vendor/powerpc.rs | 2 +- crates/core_simd/src/vendor/wasm32.rs | 2 +- crates/core_simd/src/vendor/x86.rs | 2 +- 26 files changed, 159 insertions(+), 130 deletions(-) create mode 100644 crates/core_simd/src/core_simd_docs.md create mode 100644 crates/core_simd/src/mod.rs diff --git a/crates/core_simd/src/comparisons.rs b/crates/core_simd/src/comparisons.rs index 601576e094fa..8c51baca8ede 100644 --- a/crates/core_simd/src/comparisons.rs +++ b/crates/core_simd/src/comparisons.rs @@ -1,4 +1,5 @@ -use crate::{LaneCount, Mask, Simd, SimdElement, SupportedLaneCount}; +use crate::simd::intrinsics; +use crate::simd::{LaneCount, Mask, Simd, SimdElement, SupportedLaneCount}; impl Simd where @@ -8,13 +9,13 @@ where /// Test if each lane is equal to the corresponding lane in `other`. #[inline] pub fn lanes_eq(self, other: Self) -> Mask { - unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_eq(self, other)) } + unsafe { Mask::from_int_unchecked(intrinsics::simd_eq(self, other)) } } /// Test if each lane is not equal to the corresponding lane in `other`. #[inline] pub fn lanes_ne(self, other: Self) -> Mask { - unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_ne(self, other)) } + unsafe { Mask::from_int_unchecked(intrinsics::simd_ne(self, other)) } } } @@ -26,24 +27,24 @@ where /// Test if each lane is less than the corresponding lane in `other`. #[inline] pub fn lanes_lt(self, other: Self) -> Mask { - unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_lt(self, other)) } + unsafe { Mask::from_int_unchecked(intrinsics::simd_lt(self, other)) } } /// Test if each lane is greater than the corresponding lane in `other`. #[inline] pub fn lanes_gt(self, other: Self) -> Mask { - unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_gt(self, other)) } + unsafe { Mask::from_int_unchecked(intrinsics::simd_gt(self, other)) } } /// Test if each lane is less than or equal to the corresponding lane in `other`. #[inline] pub fn lanes_le(self, other: Self) -> Mask { - unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_le(self, other)) } + unsafe { Mask::from_int_unchecked(intrinsics::simd_le(self, other)) } } /// Test if each lane is greater than or equal to the corresponding lane in `other`. #[inline] pub fn lanes_ge(self, other: Self) -> Mask { - unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_ge(self, other)) } + unsafe { Mask::from_int_unchecked(intrinsics::simd_ge(self, other)) } } } diff --git a/crates/core_simd/src/core_simd_docs.md b/crates/core_simd/src/core_simd_docs.md new file mode 100644 index 000000000000..15e8ed0253e1 --- /dev/null +++ b/crates/core_simd/src/core_simd_docs.md @@ -0,0 +1,4 @@ +Portable SIMD module. + +This module offers a portable abstraction for SIMD operations +that is not bound to any particular hardware architecture. diff --git a/crates/core_simd/src/fmt.rs b/crates/core_simd/src/fmt.rs index c3947c92f2a9..dbd9839c4bfe 100644 --- a/crates/core_simd/src/fmt.rs +++ b/crates/core_simd/src/fmt.rs @@ -1,17 +1,20 @@ +use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount}; +use core::fmt; + macro_rules! impl_fmt_trait { { $($trait:ident,)* } => { $( - impl core::fmt::$trait for crate::Simd + impl fmt::$trait for Simd where - crate::LaneCount: crate::SupportedLaneCount, - T: crate::SimdElement + core::fmt::$trait, + LaneCount: SupportedLaneCount, + T: SimdElement + fmt::$trait, { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { #[repr(transparent)] - struct Wrapper<'a, T: core::fmt::$trait>(&'a T); + struct Wrapper<'a, T: fmt::$trait>(&'a T); - impl core::fmt::Debug for Wrapper<'_, T> { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + impl fmt::Debug for Wrapper<'_, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } diff --git a/crates/core_simd/src/intrinsics.rs b/crates/core_simd/src/intrinsics.rs index 916c0dadf752..3ed9845d608e 100644 --- a/crates/core_simd/src/intrinsics.rs +++ b/crates/core_simd/src/intrinsics.rs @@ -91,9 +91,9 @@ extern "platform-intrinsic" { pub(crate) fn simd_bitmask(x: T) -> U; // select - pub(crate) fn simd_select(m: T, a: U, b: U) -> U; + pub(crate) fn simd_select(m: M, a: T, b: T) -> T; #[allow(unused)] - pub(crate) fn simd_select_bitmask(m: T, a: U, b: U) -> U; + pub(crate) fn simd_select_bitmask(m: M, a: T, b: T) -> T; } #[cfg(feature = "std")] @@ -114,4 +114,4 @@ mod std { } #[cfg(feature = "std")] -pub(crate) use crate::intrinsics::std::*; +pub(crate) use crate::simd::intrinsics::std::*; diff --git a/crates/core_simd/src/iter.rs b/crates/core_simd/src/iter.rs index f403f4d90473..3275b4db8e49 100644 --- a/crates/core_simd/src/iter.rs +++ b/crates/core_simd/src/iter.rs @@ -1,4 +1,4 @@ -use crate::{LaneCount, Simd, SupportedLaneCount}; +use crate::simd::{LaneCount, Simd, SupportedLaneCount}; use core::{ iter::{Product, Sum}, ops::{Add, Mul}, @@ -15,7 +15,7 @@ macro_rules! impl_traits { } } - impl core::iter::Product for Simd<$type, LANES> + impl Product for Simd<$type, LANES> where LaneCount: SupportedLaneCount, { diff --git a/crates/core_simd/src/lib.rs b/crates/core_simd/src/lib.rs index 7f07aa6393e2..279999b09e2f 100644 --- a/crates/core_simd/src/lib.rs +++ b/crates/core_simd/src/lib.rs @@ -14,31 +14,6 @@ #![unstable(feature = "portable_simd", issue = "86656")] //! Portable SIMD module. -#[macro_use] -mod permute; -#[macro_use] -mod reduction; - -mod select; -pub use select::Select; - -#[cfg(feature = "generic_const_exprs")] -mod to_bytes; - -mod comparisons; -mod fmt; -mod intrinsics; -mod iter; -mod math; -mod ops; -mod round; -mod vendor; - -mod lane_count; -pub use lane_count::*; - -mod masks; -pub use masks::*; - -mod vector; -pub use vector::*; +#[path = "mod.rs"] +mod core_simd; +pub use self::core_simd::simd::*; diff --git a/crates/core_simd/src/masks.rs b/crates/core_simd/src/masks.rs index ebd394cd0408..c4d6e1883483 100644 --- a/crates/core_simd/src/masks.rs +++ b/crates/core_simd/src/masks.rs @@ -12,7 +12,9 @@ )] mod mask_impl; -use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount}; +use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount}; +use core::cmp::Ordering; +use core::fmt; /// Marker trait for types that may be used as SIMD mask elements. pub unsafe trait MaskElement: SimdElement { @@ -251,17 +253,17 @@ where LaneCount: SupportedLaneCount, { #[inline] - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { self.0.partial_cmp(&other.0) } } -impl core::fmt::Debug for Mask +impl fmt::Debug for Mask where - T: MaskElement + core::fmt::Debug, + T: MaskElement + fmt::Debug, LaneCount: SupportedLaneCount, { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list() .entries((0..LANES).map(|lane| self.test(lane))) .finish() diff --git a/crates/core_simd/src/masks/bitmask.rs b/crates/core_simd/src/masks/bitmask.rs index bc68b5076748..0691c6ecd218 100644 --- a/crates/core_simd/src/masks/bitmask.rs +++ b/crates/core_simd/src/masks/bitmask.rs @@ -1,4 +1,5 @@ -use crate::{LaneCount, MaskElement, Simd, SupportedLaneCount}; +use crate::simd::intrinsics; +use crate::simd::{LaneCount, Simd, SupportedLaneCount}; use core::marker::PhantomData; /// A mask where each lane is represented by a single bit. @@ -99,11 +100,7 @@ where unsafe { let mask: as SupportedLaneCount>::IntBitMask = core::mem::transmute_copy(&self); - crate::intrinsics::simd_select_bitmask( - mask, - Simd::splat(T::TRUE), - Simd::splat(T::FALSE), - ) + intrinsics::simd_select_bitmask(mask, Simd::splat(T::TRUE), Simd::splat(T::FALSE)) } } @@ -115,7 +112,7 @@ where core::mem::size_of::< as SupportedLaneCount>::IntBitMask>(), ); let mask: as SupportedLaneCount>::IntBitMask = - crate::intrinsics::simd_bitmask(value); + intrinsics::simd_bitmask(value); Self(core::mem::transmute_copy(&mask), PhantomData) } diff --git a/crates/core_simd/src/masks/full_masks.rs b/crates/core_simd/src/masks/full_masks.rs index 5b783a7b6a12..b653bce05b9e 100644 --- a/crates/core_simd/src/masks/full_masks.rs +++ b/crates/core_simd/src/masks/full_masks.rs @@ -1,7 +1,8 @@ //! Masks that take up full SIMD vector registers. use super::MaskElement; -use crate::{LaneCount, Simd, SupportedLaneCount}; +use crate::simd::intrinsics; +use crate::simd::{LaneCount, Simd, SupportedLaneCount}; #[repr(transparent)] pub struct Mask(Simd) @@ -98,7 +99,7 @@ where where U: MaskElement, { - unsafe { Mask(crate::intrinsics::simd_cast(self.0)) } + unsafe { Mask(intrinsics::simd_cast(self.0)) } } #[cfg(feature = "generic_const_exprs")] @@ -111,7 +112,7 @@ where LaneCount::::BITMASK_LEN, ); let bitmask: as SupportedLaneCount>::IntBitMask = - crate::intrinsics::simd_bitmask(self.0); + intrinsics::simd_bitmask(self.0); let mut bitmask: [u8; LaneCount::::BITMASK_LEN] = core::mem::transmute_copy(&bitmask); @@ -149,7 +150,7 @@ where let bitmask: as SupportedLaneCount>::IntBitMask = core::mem::transmute_copy(&bitmask); - Self::from_int_unchecked(crate::intrinsics::simd_select_bitmask( + Self::from_int_unchecked(intrinsics::simd_select_bitmask( bitmask, Self::splat(true).to_int(), Self::splat(false).to_int(), @@ -159,12 +160,12 @@ where #[inline] pub fn any(self) -> bool { - unsafe { crate::intrinsics::simd_reduce_any(self.to_int()) } + unsafe { intrinsics::simd_reduce_any(self.to_int()) } } #[inline] pub fn all(self) -> bool { - unsafe { crate::intrinsics::simd_reduce_all(self.to_int()) } + unsafe { intrinsics::simd_reduce_all(self.to_int()) } } } @@ -186,7 +187,7 @@ where type Output = Self; #[inline] fn bitand(self, rhs: Self) -> Self { - unsafe { Self(crate::intrinsics::simd_and(self.0, rhs.0)) } + unsafe { Self(intrinsics::simd_and(self.0, rhs.0)) } } } @@ -198,7 +199,7 @@ where type Output = Self; #[inline] fn bitor(self, rhs: Self) -> Self { - unsafe { Self(crate::intrinsics::simd_or(self.0, rhs.0)) } + unsafe { Self(intrinsics::simd_or(self.0, rhs.0)) } } } @@ -210,7 +211,7 @@ where type Output = Self; #[inline] fn bitxor(self, rhs: Self) -> Self { - unsafe { Self(crate::intrinsics::simd_xor(self.0, rhs.0)) } + unsafe { Self(intrinsics::simd_xor(self.0, rhs.0)) } } } diff --git a/crates/core_simd/src/math.rs b/crates/core_simd/src/math.rs index 7affecbafd68..6ee5efdb981c 100644 --- a/crates/core_simd/src/math.rs +++ b/crates/core_simd/src/math.rs @@ -1,4 +1,5 @@ -use crate::{LaneCount, Simd, SupportedLaneCount}; +use crate::simd::intrinsics::{simd_saturating_add, simd_saturating_sub}; +use crate::simd::{LaneCount, Simd, SupportedLaneCount}; macro_rules! impl_uint_arith { ($($ty:ty),+) => { @@ -20,7 +21,7 @@ macro_rules! impl_uint_arith { /// ``` #[inline] pub fn saturating_add(self, second: Self) -> Self { - unsafe { crate::intrinsics::simd_saturating_add(self, second) } + unsafe { simd_saturating_add(self, second) } } /// Lanewise saturating subtract. @@ -38,7 +39,7 @@ macro_rules! impl_uint_arith { /// assert_eq!(sat, Simd::splat(0)); #[inline] pub fn saturating_sub(self, second: Self) -> Self { - unsafe { crate::intrinsics::simd_saturating_sub(self, second) } + unsafe { simd_saturating_sub(self, second) } } })+ } @@ -64,7 +65,7 @@ macro_rules! impl_int_arith { /// ``` #[inline] pub fn saturating_add(self, second: Self) -> Self { - unsafe { crate::intrinsics::simd_saturating_add(self, second) } + unsafe { simd_saturating_add(self, second) } } /// Lanewise saturating subtract. @@ -82,7 +83,7 @@ macro_rules! impl_int_arith { /// assert_eq!(sat, Simd::from_array([MIN, MIN, MIN, 0])); #[inline] pub fn saturating_sub(self, second: Self) -> Self { - unsafe { crate::intrinsics::simd_saturating_sub(self, second) } + unsafe { simd_saturating_sub(self, second) } } /// Lanewise absolute value, implemented in Rust. diff --git a/crates/core_simd/src/mod.rs b/crates/core_simd/src/mod.rs new file mode 100644 index 000000000000..251091c1dc3e --- /dev/null +++ b/crates/core_simd/src/mod.rs @@ -0,0 +1,33 @@ +#[macro_use] +mod permute; +#[macro_use] +mod reduction; + +mod select; + +#[cfg(feature = "generic_const_exprs")] +mod to_bytes; + +mod comparisons; +mod fmt; +mod intrinsics; +mod iter; +mod math; +mod ops; +mod round; +mod vendor; + +mod lane_count; + +mod masks; + +mod vector; + +#[doc = include_str!("core_simd_docs.md")] +pub mod simd { + pub use crate::core_simd::lane_count::*; + pub use crate::core_simd::masks::*; + pub use crate::core_simd::select::Select; + pub use crate::core_simd::vector::*; + pub(crate) use crate::core_simd::*; +} diff --git a/crates/core_simd/src/ops.rs b/crates/core_simd/src/ops.rs index 900315660005..5d7af474caf7 100644 --- a/crates/core_simd/src/ops.rs +++ b/crates/core_simd/src/ops.rs @@ -1,4 +1,5 @@ -use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount}; +use crate::simd::intrinsics; +use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount}; impl core::ops::Index for Simd where @@ -208,7 +209,7 @@ macro_rules! impl_op { { type Output = Self; fn neg(self) -> Self::Output { - unsafe { crate::intrinsics::simd_neg(self) } + unsafe { intrinsics::simd_neg(self) } } } } @@ -226,7 +227,7 @@ macro_rules! impl_op { #[inline] fn $trait_fn(self, rhs: Self) -> Self::Output { unsafe { - crate::intrinsics::$intrinsic(self, rhs) + intrinsics::$intrinsic(self, rhs) } } } @@ -268,7 +269,7 @@ macro_rules! impl_op { #[inline] fn $assign_trait_fn(&mut self, rhs: Self) { unsafe { - *self = crate::intrinsics::$intrinsic(*self, rhs); + *self = intrinsics::$intrinsic(*self, rhs); } } } @@ -338,7 +339,7 @@ macro_rules! impl_unsigned_int_ops { .any(|(x,y)| *x == <$scalar>::MIN && *y == -1 as _) { panic!("attempt to divide with overflow"); } - unsafe { crate::intrinsics::simd_div(self, rhs) } + unsafe { intrinsics::simd_div(self, rhs) } } } } @@ -361,7 +362,7 @@ macro_rules! impl_unsigned_int_ops { panic!("attempt to divide with overflow"); } let rhs = Self::splat(rhs); - unsafe { crate::intrinsics::simd_div(self, rhs) } + unsafe { intrinsics::simd_div(self, rhs) } } } } @@ -428,7 +429,7 @@ macro_rules! impl_unsigned_int_ops { .any(|(x,y)| *x == <$scalar>::MIN && *y == -1 as _) { panic!("attempt to calculate the remainder with overflow"); } - unsafe { crate::intrinsics::simd_rem(self, rhs) } + unsafe { intrinsics::simd_rem(self, rhs) } } } } @@ -451,7 +452,7 @@ macro_rules! impl_unsigned_int_ops { panic!("attempt to calculate the remainder with overflow"); } let rhs = Self::splat(rhs); - unsafe { crate::intrinsics::simd_rem(self, rhs) } + unsafe { intrinsics::simd_rem(self, rhs) } } } } @@ -512,7 +513,7 @@ macro_rules! impl_unsigned_int_ops { { panic!("attempt to shift left with overflow"); } - unsafe { crate::intrinsics::simd_shl(self, rhs) } + unsafe { intrinsics::simd_shl(self, rhs) } } } } @@ -530,7 +531,7 @@ macro_rules! impl_unsigned_int_ops { panic!("attempt to shift left with overflow"); } let rhs = Self::splat(rhs); - unsafe { crate::intrinsics::simd_shl(self, rhs) } + unsafe { intrinsics::simd_shl(self, rhs) } } } } @@ -577,7 +578,7 @@ macro_rules! impl_unsigned_int_ops { { panic!("attempt to shift with overflow"); } - unsafe { crate::intrinsics::simd_shr(self, rhs) } + unsafe { intrinsics::simd_shr(self, rhs) } } } } @@ -595,7 +596,7 @@ macro_rules! impl_unsigned_int_ops { panic!("attempt to shift with overflow"); } let rhs = Self::splat(rhs); - unsafe { crate::intrinsics::simd_shr(self, rhs) } + unsafe { intrinsics::simd_shr(self, rhs) } } } } diff --git a/crates/core_simd/src/permute.rs b/crates/core_simd/src/permute.rs index cc58778b6b4b..206519340b3a 100644 --- a/crates/core_simd/src/permute.rs +++ b/crates/core_simd/src/permute.rs @@ -1,8 +1,11 @@ +use crate::simd::intrinsics; +use crate::simd::{Simd, SimdElement}; + macro_rules! impl_shuffle_lane { { $fn:ident, $n:literal } => { - impl crate::Simd + impl Simd where - T: crate::SimdElement, + T: SimdElement, { /// A const SIMD shuffle that takes 2 SIMD vectors and produces another vector, using /// the indices in the const parameter. The first or "self" vector will have its lanes @@ -24,7 +27,7 @@ macro_rules! impl_shuffle_lane { /// ``` #[inline] pub fn shuffle(self, second: Self) -> Self { - unsafe { crate::intrinsics::$fn(self, second, IDX) } + unsafe { intrinsics::$fn(self, second, IDX) } } /// Reverse the order of the lanes in the vector. diff --git a/crates/core_simd/src/reduction.rs b/crates/core_simd/src/reduction.rs index 943d2856e359..db0640aae790 100644 --- a/crates/core_simd/src/reduction.rs +++ b/crates/core_simd/src/reduction.rs @@ -1,4 +1,8 @@ -use crate::{LaneCount, Simd, SupportedLaneCount}; +use crate::simd::intrinsics::{ + simd_reduce_add_ordered, simd_reduce_and, simd_reduce_max, simd_reduce_min, + simd_reduce_mul_ordered, simd_reduce_or, simd_reduce_xor, +}; +use crate::simd::{LaneCount, Simd, SupportedLaneCount}; macro_rules! impl_integer_reductions { { $scalar:ty } => { @@ -9,46 +13,46 @@ macro_rules! impl_integer_reductions { /// Horizontal wrapping add. Returns the sum of the lanes of the vector, with wrapping addition. #[inline] pub fn horizontal_sum(self) -> $scalar { - unsafe { crate::intrinsics::simd_reduce_add_ordered(self, 0) } + unsafe { simd_reduce_add_ordered(self, 0) } } /// Horizontal wrapping multiply. Returns the product of the lanes of the vector, with wrapping multiplication. #[inline] pub fn horizontal_product(self) -> $scalar { - unsafe { crate::intrinsics::simd_reduce_mul_ordered(self, 1) } + unsafe { simd_reduce_mul_ordered(self, 1) } } /// Horizontal bitwise "and". Returns the cumulative bitwise "and" across the lanes of /// the vector. #[inline] pub fn horizontal_and(self) -> $scalar { - unsafe { crate::intrinsics::simd_reduce_and(self) } + unsafe { simd_reduce_and(self) } } /// Horizontal bitwise "or". Returns the cumulative bitwise "or" across the lanes of /// the vector. #[inline] pub fn horizontal_or(self) -> $scalar { - unsafe { crate::intrinsics::simd_reduce_or(self) } + unsafe { simd_reduce_or(self) } } /// Horizontal bitwise "xor". Returns the cumulative bitwise "xor" across the lanes of /// the vector. #[inline] pub fn horizontal_xor(self) -> $scalar { - unsafe { crate::intrinsics::simd_reduce_xor(self) } + unsafe { simd_reduce_xor(self) } } /// Horizontal maximum. Returns the maximum lane in the vector. #[inline] pub fn horizontal_max(self) -> $scalar { - unsafe { crate::intrinsics::simd_reduce_max(self) } + unsafe { simd_reduce_max(self) } } /// Horizontal minimum. Returns the minimum lane in the vector. #[inline] pub fn horizontal_min(self) -> $scalar { - unsafe { crate::intrinsics::simd_reduce_min(self) } + unsafe { simd_reduce_min(self) } } } } @@ -79,7 +83,7 @@ macro_rules! impl_float_reductions { if cfg!(all(target_arch = "x86", not(target_feature = "sse2"))) { self.as_array().iter().sum() } else { - unsafe { crate::intrinsics::simd_reduce_add_ordered(self, 0.) } + unsafe { simd_reduce_add_ordered(self, 0.) } } } @@ -90,7 +94,7 @@ macro_rules! impl_float_reductions { if cfg!(all(target_arch = "x86", not(target_feature = "sse2"))) { self.as_array().iter().product() } else { - unsafe { crate::intrinsics::simd_reduce_mul_ordered(self, 1.) } + unsafe { simd_reduce_mul_ordered(self, 1.) } } } @@ -100,7 +104,7 @@ macro_rules! impl_float_reductions { /// return either. This function will not return `NaN` unless all lanes are `NaN`. #[inline] pub fn horizontal_max(self) -> $scalar { - unsafe { crate::intrinsics::simd_reduce_max(self) } + unsafe { simd_reduce_max(self) } } /// Horizontal minimum. Returns the minimum lane in the vector. @@ -109,7 +113,7 @@ macro_rules! impl_float_reductions { /// return either. This function will not return `NaN` unless all lanes are `NaN`. #[inline] pub fn horizontal_min(self) -> $scalar { - unsafe { crate::intrinsics::simd_reduce_min(self) } + unsafe { simd_reduce_min(self) } } } } diff --git a/crates/core_simd/src/round.rs b/crates/core_simd/src/round.rs index 96d46b9a1232..3bb10d0ed0bf 100644 --- a/crates/core_simd/src/round.rs +++ b/crates/core_simd/src/round.rs @@ -1,4 +1,5 @@ -use crate::{LaneCount, Simd, SupportedLaneCount}; +use crate::simd::intrinsics; +use crate::simd::{LaneCount, Simd, SupportedLaneCount}; macro_rules! implement { { @@ -13,28 +14,28 @@ macro_rules! implement { #[must_use = "method returns a new vector and does not mutate the original value"] #[inline] pub fn ceil(self) -> Self { - unsafe { crate::intrinsics::simd_ceil(self) } + unsafe { intrinsics::simd_ceil(self) } } /// Returns the largest integer value less than or equal to each lane. #[must_use = "method returns a new vector and does not mutate the original value"] #[inline] pub fn floor(self) -> Self { - unsafe { crate::intrinsics::simd_floor(self) } + unsafe { intrinsics::simd_floor(self) } } /// Rounds to the nearest integer value. Ties round toward zero. #[must_use = "method returns a new vector and does not mutate the original value"] #[inline] pub fn round(self) -> Self { - unsafe { crate::intrinsics::simd_round(self) } + unsafe { intrinsics::simd_round(self) } } /// Returns the floating point's integer value, with its fractional part removed. #[must_use = "method returns a new vector and does not mutate the original value"] #[inline] pub fn trunc(self) -> Self { - unsafe { crate::intrinsics::simd_trunc(self) } + unsafe { intrinsics::simd_trunc(self) } } /// Returns the floating point's fractional value, with its integer part removed. @@ -60,14 +61,14 @@ macro_rules! implement { /// * Be representable in the return type, after truncating off its fractional part #[inline] pub unsafe fn to_int_unchecked(self) -> Simd<$int_type, LANES> { - crate::intrinsics::simd_cast(self) + intrinsics::simd_cast(self) } /// Creates a floating-point vector from an integer vector. Rounds values that are /// not exactly representable. #[inline] pub fn round_from_int(value: Simd<$int_type, LANES>) -> Self { - unsafe { crate::intrinsics::simd_cast(value) } + unsafe { intrinsics::simd_cast(value) } } } } diff --git a/crates/core_simd/src/select.rs b/crates/core_simd/src/select.rs index 0951639c9426..596621c5676b 100644 --- a/crates/core_simd/src/select.rs +++ b/crates/core_simd/src/select.rs @@ -1,4 +1,5 @@ -use crate::{LaneCount, Mask, MaskElement, Simd, SimdElement, SupportedLaneCount}; +use crate::simd::intrinsics; +use crate::simd::{LaneCount, Mask, MaskElement, Simd, SimdElement, SupportedLaneCount}; mod sealed { pub trait Sealed {} @@ -25,7 +26,7 @@ where { #[inline] fn select(mask: Mask, true_values: Self, false_values: Self) -> Self { - unsafe { crate::intrinsics::simd_select(mask.to_int(), true_values, false_values) } + unsafe { intrinsics::simd_select(mask.to_int(), true_values, false_values) } } } diff --git a/crates/core_simd/src/to_bytes.rs b/crates/core_simd/src/to_bytes.rs index bd818f532118..8d9b3e8ff85e 100644 --- a/crates/core_simd/src/to_bytes.rs +++ b/crates/core_simd/src/to_bytes.rs @@ -1,19 +1,19 @@ macro_rules! impl_to_bytes { { $ty:ty, $size:literal } => { - impl crate::Simd<$ty, LANES> + impl crate::simd::Simd<$ty, LANES> where - crate::LaneCount: crate::SupportedLaneCount, - crate::LaneCount<{{ $size * LANES }}>: crate::SupportedLaneCount, + crate::simd::LaneCount: crate::simd::SupportedLaneCount, + crate::simd::LaneCount<{{ $size * LANES }}>: crate::simd::SupportedLaneCount, { /// Return the memory representation of this integer as a byte array in native byte /// order. - pub fn to_ne_bytes(self) -> crate::Simd { + pub fn to_ne_bytes(self) -> crate::simd::Simd { unsafe { core::mem::transmute_copy(&self) } } /// Create a native endian integer value from its memory representation as a byte array /// in native endianness. - pub fn from_ne_bytes(bytes: crate::Simd) -> Self { + pub fn from_ne_bytes(bytes: crate::simd::Simd) -> Self { unsafe { core::mem::transmute_copy(&bytes) } } } diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs index 07e8a6c5926c..fb3518fa13d7 100644 --- a/crates/core_simd/src/vector.rs +++ b/crates/core_simd/src/vector.rs @@ -9,7 +9,8 @@ pub use uint::*; // Vectors of pointers are not for public use at the current time. pub(crate) mod ptr; -use crate::{LaneCount, Mask, MaskElement, SupportedLaneCount}; +use crate::simd::intrinsics; +use crate::simd::{LaneCount, Mask, MaskElement, SupportedLaneCount}; /// A SIMD vector of `LANES` elements of type `T`. #[repr(simd)] @@ -108,11 +109,11 @@ where or: Self, ) -> Self { let mask = (mask & idxs.lanes_lt(Simd::splat(slice.len()))).to_int(); - let base_ptr = crate::vector::ptr::SimdConstPtr::splat(slice.as_ptr()); + let base_ptr = crate::simd::ptr::SimdConstPtr::splat(slice.as_ptr()); // Ferris forgive me, I have done pointer arithmetic here. let ptrs = base_ptr.wrapping_add(idxs); // SAFETY: The ptrs have been bounds-masked to prevent memory-unsafe reads insha'allah - unsafe { crate::intrinsics::simd_gather(or, ptrs, mask) } + unsafe { intrinsics::simd_gather(or, ptrs, mask) } } /// SIMD scatter: write a SIMD vector's values into a slice, using potentially discontiguous indices. @@ -168,11 +169,11 @@ where // 3. &mut [T] which will become our base ptr. unsafe { // Now Entering ☢️ *mut T Zone - let base_ptr = crate::vector::ptr::SimdMutPtr::splat(slice.as_mut_ptr()); + let base_ptr = crate::simd::ptr::SimdMutPtr::splat(slice.as_mut_ptr()); // Ferris forgive me, I have done pointer arithmetic here. let ptrs = base_ptr.wrapping_add(idxs); // The ptrs have been bounds-masked to prevent memory-unsafe writes insha'allah - crate::intrinsics::simd_scatter(self, ptrs, mask) + intrinsics::simd_scatter(self, ptrs, mask) // Cleared ☢️ *mut T Zone } } diff --git a/crates/core_simd/src/vector/float.rs b/crates/core_simd/src/vector/float.rs index 6ef88ddebc68..21a6c43e153a 100644 --- a/crates/core_simd/src/vector/float.rs +++ b/crates/core_simd/src/vector/float.rs @@ -1,6 +1,7 @@ #![allow(non_camel_case_types)] -use crate::{LaneCount, Mask, Simd, SupportedLaneCount}; +use crate::simd::intrinsics; +use crate::simd::{LaneCount, Mask, Simd, SupportedLaneCount}; /// Implements inherent methods for a float vector containing multiple /// `$lanes` of float `$type`, which uses `$bits_ty` as its binary @@ -31,7 +32,7 @@ macro_rules! impl_float_vector { /// equivalently-indexed lane in `self`. #[inline] pub fn abs(self) -> Self { - unsafe { crate::intrinsics::simd_fabs(self) } + unsafe { intrinsics::simd_fabs(self) } } /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error, @@ -43,7 +44,7 @@ macro_rules! impl_float_vector { /// hardware in mind. #[inline] pub fn mul_add(self, a: Self, b: Self) -> Self { - unsafe { crate::intrinsics::simd_fma(self, a, b) } + unsafe { intrinsics::simd_fma(self, a, b) } } /// Produces a vector where every lane has the square root value @@ -51,7 +52,7 @@ macro_rules! impl_float_vector { #[inline] #[cfg(feature = "std")] pub fn sqrt(self) -> Self { - unsafe { crate::intrinsics::simd_fsqrt(self) } + unsafe { intrinsics::simd_fsqrt(self) } } /// Takes the reciprocal (inverse) of each lane, `1/x`. diff --git a/crates/core_simd/src/vector/int.rs b/crates/core_simd/src/vector/int.rs index 5f435e16b687..3eac02a27618 100644 --- a/crates/core_simd/src/vector/int.rs +++ b/crates/core_simd/src/vector/int.rs @@ -1,6 +1,6 @@ #![allow(non_camel_case_types)] -use crate::{LaneCount, Mask, Simd, SupportedLaneCount}; +use crate::simd::{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 { diff --git a/crates/core_simd/src/vector/ptr.rs b/crates/core_simd/src/vector/ptr.rs index fc4082a4b555..ac9b98ca031a 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, Simd, SupportedLaneCount}; +use crate::simd::{LaneCount, Simd, SupportedLaneCount}; use core::mem; /// A vector of *const T. diff --git a/crates/core_simd/src/vector/uint.rs b/crates/core_simd/src/vector/uint.rs index b3dd199a5463..ed91fc3640e7 100644 --- a/crates/core_simd/src/vector/uint.rs +++ b/crates/core_simd/src/vector/uint.rs @@ -1,6 +1,6 @@ #![allow(non_camel_case_types)] -use crate::Simd; +use crate::simd::Simd; /// Vector of two `usize` values pub type usizex2 = Simd; diff --git a/crates/core_simd/src/vendor/arm.rs b/crates/core_simd/src/vendor/arm.rs index e39173a9c3c4..3e9487dfb33d 100644 --- a/crates/core_simd/src/vendor/arm.rs +++ b/crates/core_simd/src/vendor/arm.rs @@ -1,4 +1,4 @@ -use crate::*; +use crate::simd::*; #[cfg(target_arch = "arm")] use core::arch::arm::*; diff --git a/crates/core_simd/src/vendor/powerpc.rs b/crates/core_simd/src/vendor/powerpc.rs index 248764efd516..92f97d471b6e 100644 --- a/crates/core_simd/src/vendor/powerpc.rs +++ b/crates/core_simd/src/vendor/powerpc.rs @@ -1,4 +1,4 @@ -use crate::*; +use crate::simd::*; #[cfg(target_arch = "powerpc")] use core::arch::powerpc::*; diff --git a/crates/core_simd/src/vendor/wasm32.rs b/crates/core_simd/src/vendor/wasm32.rs index ef67572b534d..ef3baf885b0f 100644 --- a/crates/core_simd/src/vendor/wasm32.rs +++ b/crates/core_simd/src/vendor/wasm32.rs @@ -1,4 +1,4 @@ -use crate::*; +use crate::simd::*; use core::arch::wasm32::v128; from_transmute! { unsafe u8x16 => v128 } diff --git a/crates/core_simd/src/vendor/x86.rs b/crates/core_simd/src/vendor/x86.rs index 0090c3756481..d3c19ccc539a 100644 --- a/crates/core_simd/src/vendor/x86.rs +++ b/crates/core_simd/src/vendor/x86.rs @@ -1,4 +1,4 @@ -use crate::*; +use crate::simd::*; #[cfg(any(target_arch = "x86"))] use core::arch::x86::*;