Convert all vectors to a single type
This commit is contained in:
parent
c36d17de4d
commit
054f25f2b0
4 changed files with 101 additions and 70 deletions
|
|
@ -12,9 +12,85 @@ pub use uint::*;
|
|||
// Vectors of pointers are not for public use at the current time.
|
||||
pub(crate) mod ptr;
|
||||
|
||||
use crate::{LaneCount, SupportedLaneCount};
|
||||
|
||||
/// A SIMD vector of `LANES` elements of type `Element`.
|
||||
#[repr(simd)]
|
||||
pub struct Simd<Element, const LANES: usize>([Element; LANES])
|
||||
where
|
||||
Element: SimdElement,
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
|
||||
mod sealed {
|
||||
pub trait Sealed {}
|
||||
}
|
||||
use sealed::Sealed;
|
||||
|
||||
/// Marker trait for types that may be used as SIMD vector elements.
|
||||
pub unsafe trait SimdElement: Sealed {
|
||||
/// The mask element type corresponding to this element type.
|
||||
type Mask: SimdElement;
|
||||
}
|
||||
|
||||
impl Sealed for u8 {}
|
||||
unsafe impl SimdElement for u8 {
|
||||
type Mask = u8;
|
||||
}
|
||||
|
||||
impl Sealed for u16 {}
|
||||
unsafe impl SimdElement for u16 {
|
||||
type Mask = u16;
|
||||
}
|
||||
|
||||
impl Sealed for u32 {}
|
||||
unsafe impl SimdElement for u32 {
|
||||
type Mask = u32;
|
||||
}
|
||||
|
||||
impl Sealed for u64 {}
|
||||
unsafe impl SimdElement for u64 {
|
||||
type Mask = u64;
|
||||
}
|
||||
|
||||
impl Sealed for usize {}
|
||||
unsafe impl SimdElement for usize {
|
||||
type Mask = usize;
|
||||
}
|
||||
|
||||
impl Sealed for i8 {}
|
||||
unsafe impl SimdElement for i8 {
|
||||
type Mask = i8;
|
||||
}
|
||||
|
||||
impl Sealed for i16 {}
|
||||
unsafe impl SimdElement for i16 {
|
||||
type Mask = i16;
|
||||
}
|
||||
|
||||
impl Sealed for i32 {}
|
||||
unsafe impl SimdElement for i32 {
|
||||
type Mask = i32;
|
||||
}
|
||||
|
||||
impl Sealed for i64 {}
|
||||
unsafe impl SimdElement for i64 {
|
||||
type Mask = i64;
|
||||
}
|
||||
|
||||
impl Sealed for isize {}
|
||||
unsafe impl SimdElement for isize {
|
||||
type Mask = isize;
|
||||
}
|
||||
|
||||
impl Sealed for f32 {}
|
||||
unsafe impl SimdElement for f32 {
|
||||
type Mask = i32;
|
||||
}
|
||||
|
||||
impl Sealed for f64 {}
|
||||
unsafe impl SimdElement for f64 {
|
||||
type Mask = i64;
|
||||
}
|
||||
|
||||
/// A representation of a vector as an "array" with indices, implementing
|
||||
/// operations applicable to any vector type based solely on "having lanes",
|
||||
|
|
|
|||
|
|
@ -187,19 +187,12 @@ macro_rules! impl_float_vector {
|
|||
}
|
||||
|
||||
/// A SIMD vector of containing `LANES` `f32` values.
|
||||
#[repr(simd)]
|
||||
pub struct SimdF32<const LANES: usize>([f32; LANES])
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
|
||||
impl_float_vector! { SimdF32, f32, SimdU32, Mask32, SimdI32 }
|
||||
pub type SimdF32<const LANES: usize> = crate::Simd<f32, LANES>;
|
||||
|
||||
/// A SIMD vector of containing `LANES` `f64` values.
|
||||
#[repr(simd)]
|
||||
pub struct SimdF64<const LANES: usize>([f64; LANES])
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
pub type SimdF64<const LANES: usize> = crate::Simd<f64, LANES>;
|
||||
|
||||
impl_float_vector! { SimdF32, f32, SimdU32, Mask32, SimdI32 }
|
||||
impl_float_vector! { SimdF64, f64, SimdU64, Mask64, SimdI64 }
|
||||
|
||||
/// Vector of two `f32` values
|
||||
|
|
|
|||
|
|
@ -62,44 +62,25 @@ macro_rules! impl_integer_vector {
|
|||
}
|
||||
}
|
||||
|
||||
/// A SIMD vector of containing `LANES` `isize` values.
|
||||
#[repr(simd)]
|
||||
pub struct SimdIsize<const LANES: usize>([isize; LANES])
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
|
||||
impl_integer_vector! { SimdIsize, isize, MaskSize, SimdIsize }
|
||||
/// A SIMD vector of containing `LANES` `i8` values.
|
||||
pub type SimdI8<const LANES: usize> = crate::Simd<i8, LANES>;
|
||||
|
||||
/// A SIMD vector of containing `LANES` `i16` values.
|
||||
#[repr(simd)]
|
||||
pub struct SimdI16<const LANES: usize>([i16; LANES])
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
|
||||
impl_integer_vector! { SimdI16, i16, Mask16, SimdI16 }
|
||||
pub type SimdI16<const LANES: usize> = crate::Simd<i16, LANES>;
|
||||
|
||||
/// A SIMD vector of containing `LANES` `i32` values.
|
||||
#[repr(simd)]
|
||||
pub struct SimdI32<const LANES: usize>([i32; LANES])
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
|
||||
impl_integer_vector! { SimdI32, i32, Mask32, SimdI32 }
|
||||
pub type SimdI32<const LANES: usize> = crate::Simd<i32, LANES>;
|
||||
|
||||
/// A SIMD vector of containing `LANES` `i64` values.
|
||||
#[repr(simd)]
|
||||
pub struct SimdI64<const LANES: usize>([i64; LANES])
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
pub type SimdI64<const LANES: usize> = crate::Simd<i64, LANES>;
|
||||
|
||||
/// A SIMD vector of containing `LANES` `isize` values.
|
||||
pub type SimdIsize<const LANES: usize> = crate::Simd<isize, LANES>;
|
||||
|
||||
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 }
|
||||
|
||||
/// A SIMD vector of containing `LANES` `i8` values.
|
||||
#[repr(simd)]
|
||||
pub struct SimdI8<const LANES: usize>([i8; LANES])
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
|
||||
impl_integer_vector! { SimdI8, i8, Mask8, SimdI8 }
|
||||
|
||||
/// Vector of two `isize` values
|
||||
|
|
|
|||
|
|
@ -33,44 +33,25 @@ macro_rules! impl_unsigned_vector {
|
|||
}
|
||||
}
|
||||
|
||||
/// A SIMD vector of containing `LANES` `usize` values.
|
||||
#[repr(simd)]
|
||||
pub struct SimdUsize<const LANES: usize>([usize; LANES])
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
|
||||
impl_unsigned_vector! { SimdUsize, usize }
|
||||
/// A SIMD vector of containing `LANES` `u8` values.
|
||||
pub type SimdU8<const LANES: usize> = crate::Simd<u8, LANES>;
|
||||
|
||||
/// A SIMD vector of containing `LANES` `u16` values.
|
||||
#[repr(simd)]
|
||||
pub struct SimdU16<const LANES: usize>([u16; LANES])
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
|
||||
impl_unsigned_vector! { SimdU16, u16 }
|
||||
pub type SimdU16<const LANES: usize> = crate::Simd<u16, LANES>;
|
||||
|
||||
/// A SIMD vector of containing `LANES` `u32` values.
|
||||
#[repr(simd)]
|
||||
pub struct SimdU32<const LANES: usize>([u32; LANES])
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
|
||||
impl_unsigned_vector! { SimdU32, u32 }
|
||||
pub type SimdU32<const LANES: usize> = crate::Simd<u32, LANES>;
|
||||
|
||||
/// A SIMD vector of containing `LANES` `u64` values.
|
||||
#[repr(simd)]
|
||||
pub struct SimdU64<const LANES: usize>([u64; LANES])
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
pub type SimdU64<const LANES: usize> = crate::Simd<u64, LANES>;
|
||||
|
||||
/// A SIMD vector of containing `LANES` `usize` values.
|
||||
pub type SimdUsize<const LANES: usize> = crate::Simd<usize, LANES>;
|
||||
|
||||
impl_unsigned_vector! { SimdUsize, usize }
|
||||
impl_unsigned_vector! { SimdU16, u16 }
|
||||
impl_unsigned_vector! { SimdU32, u32 }
|
||||
impl_unsigned_vector! { SimdU64, u64 }
|
||||
|
||||
/// A SIMD vector of containing `LANES` `u8` values.
|
||||
#[repr(simd)]
|
||||
pub struct SimdU8<const LANES: usize>([u8; LANES])
|
||||
where
|
||||
LaneCount<LANES>: SupportedLaneCount;
|
||||
|
||||
impl_unsigned_vector! { SimdU8, u8 }
|
||||
|
||||
/// Vector of two `usize` values
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue