Rename element type variable

This commit is contained in:
Caleb Zulawski 2021-08-16 16:38:30 -04:00
parent cf653c7b93
commit 4aafd8e779
9 changed files with 212 additions and 216 deletions

View file

@ -1,49 +1,49 @@
use crate::{LaneCount, Mask, Simd, SimdElement, SupportedLaneCount};
impl<Element, const LANES: usize> Simd<Element, LANES>
impl<T, const LANES: usize> Simd<T, LANES>
where
Element: SimdElement + PartialEq,
T: SimdElement + PartialEq,
LaneCount<LANES>: SupportedLaneCount,
{
/// Test if each lane is equal to the corresponding lane in `other`.
#[inline]
pub fn lanes_eq(self, other: Self) -> Mask<Element::Mask, LANES> {
pub fn lanes_eq(self, other: Self) -> Mask<T::Mask, LANES> {
unsafe { Mask::from_int_unchecked(crate::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<Element::Mask, LANES> {
pub fn lanes_ne(self, other: Self) -> Mask<T::Mask, LANES> {
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_ne(self, other)) }
}
}
impl<Element, const LANES: usize> Simd<Element, LANES>
impl<T, const LANES: usize> Simd<T, LANES>
where
Element: SimdElement + PartialOrd,
T: SimdElement + PartialOrd,
LaneCount<LANES>: SupportedLaneCount,
{
/// Test if each lane is less than the corresponding lane in `other`.
#[inline]
pub fn lanes_lt(self, other: Self) -> Mask<Element::Mask, LANES> {
pub fn lanes_lt(self, other: Self) -> Mask<T::Mask, LANES> {
unsafe { Mask::from_int_unchecked(crate::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<Element::Mask, LANES> {
pub fn lanes_gt(self, other: Self) -> Mask<T::Mask, LANES> {
unsafe { Mask::from_int_unchecked(crate::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<Element::Mask, LANES> {
pub fn lanes_le(self, other: Self) -> Mask<T::Mask, LANES> {
unsafe { Mask::from_int_unchecked(crate::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<Element::Mask, LANES> {
pub fn lanes_ge(self, other: Self) -> Mask<T::Mask, LANES> {
unsafe { Mask::from_int_unchecked(crate::intrinsics::simd_ge(self, other)) }
}
}

View file

@ -1,10 +1,10 @@
macro_rules! impl_fmt_trait {
{ $($trait:ident,)* } => {
$(
impl<Element, const LANES: usize> core::fmt::$trait for crate::Simd<Element, LANES>
impl<T, const LANES: usize> core::fmt::$trait for crate::Simd<T, LANES>
where
crate::LaneCount<LANES>: crate::SupportedLaneCount,
Element: crate::SimdElement + core::fmt::$trait,
T: crate::SimdElement + core::fmt::$trait,
{
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
#[repr(transparent)]

View file

@ -59,21 +59,21 @@ impl_element! { isize }
///
/// The layout of this type is unspecified.
#[repr(transparent)]
pub struct Mask<Element, const LANES: usize>(mask_impl::Mask<Element, LANES>)
pub struct Mask<T, const LANES: usize>(mask_impl::Mask<T, LANES>)
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount;
impl<Element, const LANES: usize> Copy for Mask<Element, LANES>
impl<T, const LANES: usize> Copy for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
}
impl<Element, const LANES: usize> Clone for Mask<Element, LANES>
impl<T, const LANES: usize> Clone for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
fn clone(&self) -> Self {
@ -81,9 +81,9 @@ where
}
}
impl<Element, const LANES: usize> Mask<Element, LANES>
impl<T, const LANES: usize> Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
/// Construct a mask by setting all lanes to the given value.
@ -115,7 +115,7 @@ where
/// # Safety
/// All lanes must be either 0 or -1.
#[inline]
pub unsafe fn from_int_unchecked(value: Simd<Element, LANES>) -> Self {
pub unsafe fn from_int_unchecked(value: Simd<T, LANES>) -> Self {
Self(mask_impl::Mask::from_int_unchecked(value))
}
@ -125,15 +125,15 @@ where
/// # Panics
/// Panics if any lane is not 0 or -1.
#[inline]
pub fn from_int(value: Simd<Element, LANES>) -> Self {
assert!(Element::valid(value), "all values must be either 0 or -1",);
pub fn from_int(value: Simd<T, LANES>) -> Self {
assert!(T::valid(value), "all values must be either 0 or -1",);
unsafe { Self::from_int_unchecked(value) }
}
/// Converts the mask to a vector of integers, where 0 represents `false` and -1
/// represents `true`.
#[inline]
pub fn to_int(self) -> Simd<Element, LANES> {
pub fn to_int(self) -> Simd<T, LANES> {
self.0.to_int()
}
@ -201,9 +201,9 @@ where
}
// vector/array conversion
impl<Element, const LANES: usize> From<[bool; LANES]> for Mask<Element, LANES>
impl<T, const LANES: usize> From<[bool; LANES]> for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
fn from(array: [bool; LANES]) -> Self {
@ -211,19 +211,19 @@ where
}
}
impl<Element, const LANES: usize> From<Mask<Element, LANES>> for [bool; LANES]
impl<T, const LANES: usize> From<Mask<T, LANES>> for [bool; LANES]
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
fn from(vector: Mask<Element, LANES>) -> Self {
fn from(vector: Mask<T, LANES>) -> Self {
vector.to_array()
}
}
impl<Element, const LANES: usize> Default for Mask<Element, LANES>
impl<T, const LANES: usize> Default for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
@ -232,9 +232,9 @@ where
}
}
impl<Element, const LANES: usize> PartialEq for Mask<Element, LANES>
impl<T, const LANES: usize> PartialEq for Mask<T, LANES>
where
Element: MaskElement + PartialEq,
T: MaskElement + PartialEq,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
@ -243,9 +243,9 @@ where
}
}
impl<Element, const LANES: usize> PartialOrd for Mask<Element, LANES>
impl<T, const LANES: usize> PartialOrd for Mask<T, LANES>
where
Element: MaskElement + PartialOrd,
T: MaskElement + PartialOrd,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
@ -254,9 +254,9 @@ where
}
}
impl<Element, const LANES: usize> core::fmt::Debug for Mask<Element, LANES>
impl<T, const LANES: usize> core::fmt::Debug for Mask<T, LANES>
where
Element: MaskElement + core::fmt::Debug,
T: MaskElement + core::fmt::Debug,
LaneCount<LANES>: SupportedLaneCount,
{
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
@ -266,9 +266,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitAnd for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitAnd for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
@ -278,9 +278,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitAnd<bool> for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitAnd<bool> for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
@ -290,21 +290,21 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitAnd<Mask<Element, LANES>> for bool
impl<T, const LANES: usize> core::ops::BitAnd<Mask<T, LANES>> for bool
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Mask<Element, LANES>;
type Output = Mask<T, LANES>;
#[inline]
fn bitand(self, rhs: Mask<Element, LANES>) -> Mask<Element, LANES> {
fn bitand(self, rhs: Mask<T, LANES>) -> Mask<T, LANES> {
Mask::splat(self) & rhs
}
}
impl<Element, const LANES: usize> core::ops::BitOr for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitOr for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
@ -314,9 +314,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitOr<bool> for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitOr<bool> for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
@ -326,21 +326,21 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitOr<Mask<Element, LANES>> for bool
impl<T, const LANES: usize> core::ops::BitOr<Mask<T, LANES>> for bool
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Mask<Element, LANES>;
type Output = Mask<T, LANES>;
#[inline]
fn bitor(self, rhs: Mask<Element, LANES>) -> Mask<Element, LANES> {
fn bitor(self, rhs: Mask<T, LANES>) -> Mask<T, LANES> {
Mask::splat(self) | rhs
}
}
impl<Element, const LANES: usize> core::ops::BitXor for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitXor for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
@ -350,9 +350,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitXor<bool> for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitXor<bool> for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
@ -362,33 +362,33 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitXor<Mask<Element, LANES>> for bool
impl<T, const LANES: usize> core::ops::BitXor<Mask<T, LANES>> for bool
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Mask<Element, LANES>;
type Output = Mask<T, LANES>;
#[inline]
fn bitxor(self, rhs: Mask<Element, LANES>) -> Self::Output {
fn bitxor(self, rhs: Mask<T, LANES>) -> Self::Output {
Mask::splat(self) ^ rhs
}
}
impl<Element, const LANES: usize> core::ops::Not for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::Not for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Mask<Element, LANES>;
type Output = Mask<T, LANES>;
#[inline]
fn not(self) -> Self::Output {
Self(!self.0)
}
}
impl<Element, const LANES: usize> core::ops::BitAndAssign for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitAndAssign for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
@ -397,9 +397,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitAndAssign<bool> for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitAndAssign<bool> for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
@ -408,9 +408,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitOrAssign for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitOrAssign for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
@ -419,9 +419,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitOrAssign<bool> for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitOrAssign<bool> for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
@ -430,9 +430,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitXorAssign for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitXorAssign for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
@ -441,9 +441,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitXorAssign<bool> for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitXorAssign<bool> for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]

View file

@ -3,24 +3,24 @@ use core::marker::PhantomData;
/// A mask where each lane is represented by a single bit.
#[repr(transparent)]
pub struct Mask<Element, const LANES: usize>(
pub struct Mask<T, const LANES: usize>(
<LaneCount<LANES> as SupportedLaneCount>::BitMask,
PhantomData<Element>,
PhantomData<T>,
)
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount;
impl<Element, const LANES: usize> Copy for Mask<Element, LANES>
impl<T, const LANES: usize> Copy for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
}
impl<Element, const LANES: usize> Clone for Mask<Element, LANES>
impl<T, const LANES: usize> Clone for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
fn clone(&self) -> Self {
@ -28,9 +28,9 @@ where
}
}
impl<Element, const LANES: usize> PartialEq for Mask<Element, LANES>
impl<T, const LANES: usize> PartialEq for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
fn eq(&self, other: &Self) -> bool {
@ -38,9 +38,9 @@ where
}
}
impl<Element, const LANES: usize> PartialOrd for Mask<Element, LANES>
impl<T, const LANES: usize> PartialOrd for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
@ -48,16 +48,16 @@ where
}
}
impl<Element, const LANES: usize> Eq for Mask<Element, LANES>
impl<T, const LANES: usize> Eq for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
}
impl<Element, const LANES: usize> Ord for Mask<Element, LANES>
impl<T, const LANES: usize> Ord for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
@ -65,9 +65,9 @@ where
}
}
impl<Element, const LANES: usize> Mask<Element, LANES>
impl<T, const LANES: usize> Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
@ -95,20 +95,20 @@ where
}
#[inline]
pub fn to_int(self) -> Simd<Element, LANES> {
pub fn to_int(self) -> Simd<T, LANES> {
unsafe {
let mask: <LaneCount<LANES> as SupportedLaneCount>::IntBitMask =
core::mem::transmute_copy(&self);
crate::intrinsics::simd_select_bitmask(
mask,
Simd::splat(Element::TRUE),
Simd::splat(Element::FALSE),
Simd::splat(T::TRUE),
Simd::splat(T::FALSE),
)
}
}
#[inline]
pub unsafe fn from_int_unchecked(value: Simd<Element, LANES>) -> Self {
pub unsafe fn from_int_unchecked(value: Simd<T, LANES>) -> Self {
// TODO remove the transmute when rustc is more flexible
assert_eq!(
core::mem::size_of::<<LaneCount::<LANES> as SupportedLaneCount>::BitMask>(),
@ -132,9 +132,9 @@ where
}
#[inline]
pub fn convert<T>(self) -> Mask<T, LANES>
pub fn convert<U>(self) -> Mask<U, LANES>
where
T: MaskElement,
U: MaskElement,
{
unsafe { core::mem::transmute_copy(&self) }
}
@ -150,9 +150,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitAnd for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitAnd for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
<LaneCount<LANES> as SupportedLaneCount>::BitMask: AsRef<[u8]> + AsMut<[u8]>,
{
@ -166,9 +166,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitOr for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitOr for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
<LaneCount<LANES> as SupportedLaneCount>::BitMask: AsRef<[u8]> + AsMut<[u8]>,
{
@ -182,9 +182,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitXor for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitXor for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
@ -197,9 +197,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::Not for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::Not for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;

View file

@ -4,21 +4,21 @@ use super::MaskElement;
use crate::{LaneCount, Simd, SupportedLaneCount};
#[repr(transparent)]
pub struct Mask<Element, const LANES: usize>(Simd<Element, LANES>)
pub struct Mask<T, const LANES: usize>(Simd<T, LANES>)
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount;
impl<Element, const LANES: usize> Copy for Mask<Element, LANES>
impl<T, const LANES: usize> Copy for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
}
impl<Element, const LANES: usize> Clone for Mask<Element, LANES>
impl<T, const LANES: usize> Clone for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
@ -27,9 +27,9 @@ where
}
}
impl<Element, const LANES: usize> PartialEq for Mask<Element, LANES>
impl<T, const LANES: usize> PartialEq for Mask<T, LANES>
where
Element: MaskElement + PartialEq,
T: MaskElement + PartialEq,
LaneCount<LANES>: SupportedLaneCount,
{
fn eq(&self, other: &Self) -> bool {
@ -37,9 +37,9 @@ where
}
}
impl<Element, const LANES: usize> PartialOrd for Mask<Element, LANES>
impl<T, const LANES: usize> PartialOrd for Mask<T, LANES>
where
Element: MaskElement + PartialOrd,
T: MaskElement + PartialOrd,
LaneCount<LANES>: SupportedLaneCount,
{
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
@ -47,16 +47,16 @@ where
}
}
impl<Element, const LANES: usize> Eq for Mask<Element, LANES>
impl<T, const LANES: usize> Eq for Mask<T, LANES>
where
Element: MaskElement + Eq,
T: MaskElement + Eq,
LaneCount<LANES>: SupportedLaneCount,
{
}
impl<Element, const LANES: usize> Ord for Mask<Element, LANES>
impl<T, const LANES: usize> Ord for Mask<T, LANES>
where
Element: MaskElement + Ord,
T: MaskElement + Ord,
LaneCount<LANES>: SupportedLaneCount,
{
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
@ -64,43 +64,39 @@ where
}
}
impl<Element, const LANES: usize> Mask<Element, LANES>
impl<T, const LANES: usize> Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
pub fn splat(value: bool) -> Self {
Self(Simd::splat(if value {
Element::TRUE
} else {
Element::FALSE
}))
Self(Simd::splat(if value { T::TRUE } else { T::FALSE }))
}
#[inline]
pub unsafe fn test_unchecked(&self, lane: usize) -> bool {
Element::eq(self.0[lane], Element::TRUE)
T::eq(self.0[lane], T::TRUE)
}
#[inline]
pub unsafe fn set_unchecked(&mut self, lane: usize, value: bool) {
self.0[lane] = if value { Element::TRUE } else { Element::FALSE }
self.0[lane] = if value { T::TRUE } else { T::FALSE }
}
#[inline]
pub fn to_int(self) -> Simd<Element, LANES> {
pub fn to_int(self) -> Simd<T, LANES> {
self.0
}
#[inline]
pub unsafe fn from_int_unchecked(value: Simd<Element, LANES>) -> Self {
pub unsafe fn from_int_unchecked(value: Simd<T, LANES>) -> Self {
Self(value)
}
#[inline]
pub fn convert<T>(self) -> Mask<T, LANES>
pub fn convert<U>(self) -> Mask<U, LANES>
where
T: MaskElement,
U: MaskElement,
{
unsafe { Mask(crate::intrinsics::simd_cast(self.0)) }
}
@ -170,19 +166,19 @@ where
}
}
impl<Element, const LANES: usize> core::convert::From<Mask<Element, LANES>> for Simd<Element, LANES>
impl<T, const LANES: usize> core::convert::From<Mask<T, LANES>> for Simd<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
fn from(value: Mask<Element, LANES>) -> Self {
fn from(value: Mask<T, LANES>) -> Self {
value.0
}
}
impl<Element, const LANES: usize> core::ops::BitAnd for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitAnd for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
@ -192,9 +188,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitOr for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitOr for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
@ -204,9 +200,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::BitXor for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::BitXor for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;
@ -216,9 +212,9 @@ where
}
}
impl<Element, const LANES: usize> core::ops::Not for Mask<Element, LANES>
impl<T, const LANES: usize> core::ops::Not for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
type Output = Self;

View file

@ -1,10 +1,10 @@
use crate::{LaneCount, Simd, SimdElement, SupportedLaneCount};
impl<I, Element, const LANES: usize> core::ops::Index<I> for Simd<Element, LANES>
impl<I, T, const LANES: usize> core::ops::Index<I> for Simd<T, LANES>
where
Element: SimdElement,
T: SimdElement,
LaneCount<LANES>: SupportedLaneCount,
I: core::slice::SliceIndex<[Element]>,
I: core::slice::SliceIndex<[T]>,
{
type Output = I::Output;
fn index(&self, index: I) -> &Self::Output {
@ -12,11 +12,11 @@ where
}
}
impl<I, Element, const LANES: usize> core::ops::IndexMut<I> for Simd<Element, LANES>
impl<I, T, const LANES: usize> core::ops::IndexMut<I> for Simd<T, LANES>
where
Element: SimdElement,
T: SimdElement,
LaneCount<LANES>: SupportedLaneCount,
I: core::slice::SliceIndex<[Element]>,
I: core::slice::SliceIndex<[T]>,
{
fn index_mut(&mut self, index: I) -> &mut Self::Output {
&mut self.as_mut_array()[index]

View file

@ -1,8 +1,8 @@
macro_rules! impl_shuffle_lane {
{ $fn:ident, $n:literal } => {
impl<Element> crate::Simd<Element, $n>
impl<T> crate::Simd<T, $n>
where
Element: crate::SimdElement,
T: crate::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

View file

@ -11,34 +11,34 @@ pub trait Select<Mask>: Sealed {
fn select(mask: Mask, true_values: Self, false_values: Self) -> Self;
}
impl<Element, const LANES: usize> Sealed for Simd<Element, LANES>
impl<T, const LANES: usize> Sealed for Simd<T, LANES>
where
Element: SimdElement,
T: SimdElement,
LaneCount<LANES>: SupportedLaneCount,
{
}
impl<Element, const LANES: usize> Select<Mask<Element::Mask, LANES>> for Simd<Element, LANES>
impl<T, const LANES: usize> Select<Mask<T::Mask, LANES>> for Simd<T, LANES>
where
Element: SimdElement,
T: SimdElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[inline]
fn select(mask: Mask<Element::Mask, LANES>, true_values: Self, false_values: Self) -> Self {
fn select(mask: Mask<T::Mask, LANES>, true_values: Self, false_values: Self) -> Self {
unsafe { crate::intrinsics::simd_select(mask.to_int(), true_values, false_values) }
}
}
impl<Element, const LANES: usize> Sealed for Mask<Element, LANES>
impl<T, const LANES: usize> Sealed for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
}
impl<Element, const LANES: usize> Select<Self> for Mask<Element, LANES>
impl<T, const LANES: usize> Select<Self> for Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
#[doc(hidden)]
@ -48,9 +48,9 @@ where
}
}
impl<Element, const LANES: usize> Mask<Element, LANES>
impl<T, const LANES: usize> Mask<T, LANES>
where
Element: MaskElement,
T: MaskElement,
LaneCount<LANES>: SupportedLaneCount,
{
/// Choose lanes from two vectors.

View file

@ -11,40 +11,40 @@ pub(crate) mod ptr;
use crate::{LaneCount, Mask, MaskElement, SupportedLaneCount};
/// A SIMD vector of `LANES` elements of type `Element`.
/// A SIMD vector of `LANES` elements of type `T`.
#[repr(simd)]
pub struct Simd<Element, const LANES: usize>([Element; LANES])
pub struct Simd<T, const LANES: usize>([T; LANES])
where
Element: SimdElement,
T: SimdElement,
LaneCount<LANES>: SupportedLaneCount;
impl<Element, const LANES: usize> Simd<Element, LANES>
impl<T, const LANES: usize> Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement,
T: SimdElement,
{
/// Construct a SIMD vector by setting all lanes to the given value.
pub const fn splat(value: Element) -> Self {
pub const fn splat(value: T) -> Self {
Self([value; LANES])
}
/// Returns an array reference containing the entire SIMD vector.
pub const fn as_array(&self) -> &[Element; LANES] {
pub const fn as_array(&self) -> &[T; LANES] {
&self.0
}
/// Returns a mutable array reference containing the entire SIMD vector.
pub fn as_mut_array(&mut self) -> &mut [Element; LANES] {
pub fn as_mut_array(&mut self) -> &mut [T; LANES] {
&mut self.0
}
/// Converts an array to a SIMD vector.
pub const fn from_array(array: [Element; LANES]) -> Self {
pub const fn from_array(array: [T; LANES]) -> Self {
Self(array)
}
/// Converts a SIMD vector to an array.
pub const fn to_array(self) -> [Element; LANES] {
pub const fn to_array(self) -> [T; LANES] {
self.0
}
@ -62,7 +62,7 @@ where
/// ```
#[must_use]
#[inline]
pub fn gather_or(slice: &[Element], idxs: Simd<usize, LANES>, or: Self) -> Self {
pub fn gather_or(slice: &[T], idxs: Simd<usize, LANES>, or: Self) -> Self {
Self::gather_select(slice, Mask::splat(true), idxs, or)
}
@ -79,11 +79,11 @@ where
/// ```
#[must_use]
#[inline]
pub fn gather_or_default(slice: &[Element], idxs: Simd<usize, LANES>) -> Self
pub fn gather_or_default(slice: &[T], idxs: Simd<usize, LANES>) -> Self
where
Element: Default,
T: Default,
{
Self::gather_or(slice, idxs, Self::splat(Element::default()))
Self::gather_or(slice, idxs, Self::splat(T::default()))
}
/// SIMD gather: construct a SIMD vector by reading from a slice, using potentially discontiguous indices.
@ -102,7 +102,7 @@ where
#[must_use]
#[inline]
pub fn gather_select(
slice: &[Element],
slice: &[T],
mask: Mask<isize, LANES>,
idxs: Simd<usize, LANES>,
or: Self,
@ -129,7 +129,7 @@ where
/// assert_eq!(vec, vec![124, 11, 12, 82, 14, 15, 16, 17, 18]);
/// ```
#[inline]
pub fn scatter(self, slice: &mut [Element], idxs: Simd<usize, LANES>) {
pub fn scatter(self, slice: &mut [T], idxs: Simd<usize, LANES>) {
self.scatter_select(slice, Mask::splat(true), idxs)
}
@ -150,7 +150,7 @@ where
#[inline]
pub fn scatter_select(
self,
slice: &mut [Element],
slice: &mut [T],
mask: Mask<isize, LANES>,
idxs: Simd<usize, LANES>,
) {
@ -178,16 +178,16 @@ where
}
}
impl<Element, const LANES: usize> Copy for Simd<Element, LANES>
impl<T, const LANES: usize> Copy for Simd<T, LANES>
where
Element: SimdElement,
T: SimdElement,
LaneCount<LANES>: SupportedLaneCount,
{
}
impl<Element, const LANES: usize> Clone for Simd<Element, LANES>
impl<T, const LANES: usize> Clone for Simd<T, LANES>
where
Element: SimdElement,
T: SimdElement,
LaneCount<LANES>: SupportedLaneCount,
{
fn clone(&self) -> Self {
@ -195,21 +195,21 @@ where
}
}
impl<Element, const LANES: usize> Default for Simd<Element, LANES>
impl<T, const LANES: usize> Default for Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement + Default,
T: SimdElement + Default,
{
#[inline]
fn default() -> Self {
Self::splat(Element::default())
Self::splat(T::default())
}
}
impl<Element, const LANES: usize> PartialEq for Simd<Element, LANES>
impl<T, const LANES: usize> PartialEq for Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement + PartialEq,
T: SimdElement + PartialEq,
{
#[inline]
fn eq(&self, other: &Self) -> bool {
@ -218,10 +218,10 @@ where
}
}
impl<Element, const LANES: usize> PartialOrd for Simd<Element, LANES>
impl<T, const LANES: usize> PartialOrd for Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement + PartialOrd,
T: SimdElement + PartialOrd,
{
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
@ -230,17 +230,17 @@ where
}
}
impl<Element, const LANES: usize> Eq for Simd<Element, LANES>
impl<T, const LANES: usize> Eq for Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement + Eq,
T: SimdElement + Eq,
{
}
impl<Element, const LANES: usize> Ord for Simd<Element, LANES>
impl<T, const LANES: usize> Ord for Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement + Ord,
T: SimdElement + Ord,
{
#[inline]
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
@ -249,10 +249,10 @@ where
}
}
impl<Element, const LANES: usize> core::hash::Hash for Simd<Element, LANES>
impl<T, const LANES: usize> core::hash::Hash for Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement + core::hash::Hash,
T: SimdElement + core::hash::Hash,
{
#[inline]
fn hash<H>(&self, state: &mut H)
@ -264,68 +264,68 @@ where
}
// array references
impl<Element, const LANES: usize> AsRef<[Element; LANES]> for Simd<Element, LANES>
impl<T, const LANES: usize> AsRef<[T; LANES]> for Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement,
T: SimdElement,
{
#[inline]
fn as_ref(&self) -> &[Element; LANES] {
fn as_ref(&self) -> &[T; LANES] {
&self.0
}
}
impl<Element, const LANES: usize> AsMut<[Element; LANES]> for Simd<Element, LANES>
impl<T, const LANES: usize> AsMut<[T; LANES]> for Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement,
T: SimdElement,
{
#[inline]
fn as_mut(&mut self) -> &mut [Element; LANES] {
fn as_mut(&mut self) -> &mut [T; LANES] {
&mut self.0
}
}
// slice references
impl<Element, const LANES: usize> AsRef<[Element]> for Simd<Element, LANES>
impl<T, const LANES: usize> AsRef<[T]> for Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement,
T: SimdElement,
{
#[inline]
fn as_ref(&self) -> &[Element] {
fn as_ref(&self) -> &[T] {
&self.0
}
}
impl<Element, const LANES: usize> AsMut<[Element]> for Simd<Element, LANES>
impl<T, const LANES: usize> AsMut<[T]> for Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement,
T: SimdElement,
{
#[inline]
fn as_mut(&mut self) -> &mut [Element] {
fn as_mut(&mut self) -> &mut [T] {
&mut self.0
}
}
// vector/array conversion
impl<Element, const LANES: usize> From<[Element; LANES]> for Simd<Element, LANES>
impl<T, const LANES: usize> From<[T; LANES]> for Simd<T, LANES>
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement,
T: SimdElement,
{
fn from(array: [Element; LANES]) -> Self {
fn from(array: [T; LANES]) -> Self {
Self(array)
}
}
impl<Element, const LANES: usize> From<Simd<Element, LANES>> for [Element; LANES]
impl<T, const LANES: usize> From<Simd<T, LANES>> for [T; LANES]
where
LaneCount<LANES>: SupportedLaneCount,
Element: SimdElement,
T: SimdElement,
{
fn from(vector: Simd<Element, LANES>) -> Self {
fn from(vector: Simd<T, LANES>) -> Self {
vector.to_array()
}
}