Move vector implementation

This commit is contained in:
Caleb Zulawski 2021-06-29 22:08:50 +00:00
parent 529ffe05d6
commit f93bef35f3
3 changed files with 33 additions and 100 deletions

View File

@ -12,8 +12,6 @@
#![unstable(feature = "portable_simd", issue = "86656")]
//! Portable SIMD module.
#[macro_use]
mod first;
#[macro_use]
mod permute;
#[macro_use]

View File

@ -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;
}
}

View File

@ -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<const LANES: usize> $name<LANES> where Self: crate::Vector {
/// Construct a SIMD vector by setting all lanes to the given value.
pub const fn splat(value: $type) -> Self {