diff --git a/crates/core_simd/src/lib.rs b/crates/core_simd/src/lib.rs index eb580dcf14d..2f0f851a92f 100644 --- a/crates/core_simd/src/lib.rs +++ b/crates/core_simd/src/lib.rs @@ -12,8 +12,6 @@ #![unstable(feature = "portable_simd", issue = "86656")] //! Portable SIMD module. -#[macro_use] -mod first; #[macro_use] mod permute; #[macro_use] diff --git a/crates/core_simd/src/vector.rs b/crates/core_simd/src/vector.rs index a7adca80f8b..2bc7c1cd2b7 100644 --- a/crates/core_simd/src/vector.rs +++ b/crates/core_simd/src/vector.rs @@ -1,3 +1,6 @@ +#[macro_use] +mod vector_impl; + mod float; mod int; mod uint; @@ -31,101 +34,3 @@ pub trait Vector: sealed::Sealed { #[must_use] fn splat(val: Self::Scalar) -> Self; } - -macro_rules! impl_vector_for { - ($simd:ident {type Scalar = $scalar:ident;}) => { - impl_vector_for! { $simd<1> { type Scalar = $scalar; type BitMask = u8; } } - impl_vector_for! { $simd<2> { type Scalar = $scalar; type BitMask = u8; } } - impl_vector_for! { $simd<4> { type Scalar = $scalar; type BitMask = u8; } } - impl_vector_for! { $simd<8> { type Scalar = $scalar; type BitMask = u8; } } - impl_vector_for! { $simd<16> { type Scalar = $scalar; type BitMask = u16; } } - impl_vector_for! { $simd<32> { type Scalar = $scalar; type BitMask = u32; } } - }; - ($simd:ident<$lanes:literal> {type Scalar = $scalar:ident; type BitMask = $bitmask:ident; }) => { - impl sealed::Sealed for $simd<$lanes> {} - - impl Vector for $simd<$lanes> { - type Scalar = $scalar; - const LANES: usize = $lanes; - - type BitMask = $bitmask; - - #[inline] - fn splat(val: Self::Scalar) -> Self { - Self::splat(val) - } - } - }; -} - -impl_vector_for! { - SimdUsize { - type Scalar = usize; - } -} - -impl_vector_for! { - SimdIsize { - type Scalar = isize; - } -} - -impl_vector_for! { - SimdI8 { - type Scalar = i8; - } -} - -impl_vector_for! { - SimdI16 { - type Scalar = i16; - } -} - -impl_vector_for! { - SimdI32 { - type Scalar = i32; - } -} - -impl_vector_for! { - SimdI64 { - type Scalar = i64; - } -} - -impl_vector_for! { - SimdU8 { - type Scalar = u8; - } -} - -impl_vector_for! { - SimdU16 { - type Scalar = u16; - } -} - -impl_vector_for! { - SimdU32 { - type Scalar = u32; - } -} - -impl_vector_for! { - SimdU64 { - type Scalar = u64; - } -} - -impl_vector_for! { - SimdF32 { - type Scalar = f32; - } -} - -impl_vector_for! { - SimdF64 { - type Scalar = f64; - } -} diff --git a/crates/core_simd/src/first.rs b/crates/core_simd/src/vector/vector_impl.rs similarity index 90% rename from crates/core_simd/src/first.rs rename to crates/core_simd/src/vector/vector_impl.rs index 4560a0a1467..e166a93670b 100644 --- a/crates/core_simd/src/first.rs +++ b/crates/core_simd/src/vector/vector_impl.rs @@ -1,6 +1,36 @@ +macro_rules! impl_vector_trait { + ($simd:ident {type Scalar = $scalar:ty;}) => { + impl_vector_trait! { $simd<1> { type Scalar = $scalar; type BitMask = u8; } } + impl_vector_trait! { $simd<2> { type Scalar = $scalar; type BitMask = u8; } } + impl_vector_trait! { $simd<4> { type Scalar = $scalar; type BitMask = u8; } } + impl_vector_trait! { $simd<8> { type Scalar = $scalar; type BitMask = u8; } } + impl_vector_trait! { $simd<16> { type Scalar = $scalar; type BitMask = u16; } } + impl_vector_trait! { $simd<32> { type Scalar = $scalar; type BitMask = u32; } } + }; + ($simd:ident<$lanes:literal> {type Scalar = $scalar:ty; type BitMask = $bitmask:ident; }) => { + impl crate::vector::sealed::Sealed for $simd<$lanes> {} + + impl crate::vector::Vector for $simd<$lanes> { + type Scalar = $scalar; + const LANES: usize = $lanes; + + type BitMask = $bitmask; + + #[inline] + fn splat(val: Self::Scalar) -> Self { + Self::splat(val) + } + } + }; +} + /// Implements common traits on the specified vector `$name`, holding multiple `$lanes` of `$type`. macro_rules! impl_vector { { $name:ident, $type:ty } => { + impl_vector_trait! { + $name { type Scalar = $type; } + } + impl $name where Self: crate::Vector { /// Construct a SIMD vector by setting all lanes to the given value. pub const fn splat(value: $type) -> Self {