Struct Mask

#[repr(transparent)]
pub struct Mask<T, const N: usize>(pub(in ::core_simd::masks) Simd<T, N>)
where
    T: MaskElement,;

A SIMD vector mask for N elements of width specified by Element.

Masks represent boolean inclusion/exclusion on a per-element basis.

The layout of this type is unspecified, and may change between platforms and/or Rust versions, and code should not assume that it is equivalent to [T; N].

N cannot be 0 and may be at most 64. This limit may be increased in the future.

Fields

0: Simd<T, N>

Implementations

impl<T, const N: usize> Mask<T, N> where T: MaskElement,

const fn splat(value: bool) -> Self

Constructs a mask by setting all elements to the given value.

fn from_array(array: [bool; N]) -> Self

Converts an array of bools to a SIMD mask.

fn to_array(self) -> [bool; N]

Converts a SIMD mask to an array of bools.

unsafe fn from_simd_unchecked(value: Simd<T, N>) -> Self

Converts a vector of integers to a mask, where 0 represents false and -1 represents true.

Safety

All elements must be either 0 or -1.

fn from_simd(value: Simd<T, N>) -> Self

Converts a vector of integers to a mask, where 0 represents false and -1 represents true.

Panics

Panics if any element is not 0 or -1.

fn to_simd(self) -> Simd<T, N>

Converts the mask to a vector of integers, where 0 represents false and -1 represents true.

fn cast<U: MaskElement>(self) -> Mask<U, N>

Converts the mask to a mask of any other element size.

unsafe fn test_unchecked(&self, index: usize) -> bool

Tests the value of the specified element.

Safety

index must be less than self.len().

fn test(&self, index: usize) -> bool

Tests the value of the specified element.

Panics

Panics if index is greater than or equal to the number of elements in the vector.

unsafe fn set_unchecked(&mut self, index: usize, value: bool)

Sets the value of the specified element.

Safety

index must be less than self.len().

fn set(&mut self, index: usize, value: bool)

Sets the value of the specified element.

Panics

Panics if index is greater than or equal to the number of elements in the vector.

fn any(self) -> bool

Returns true if any element is set, or false otherwise.

fn all(self) -> bool

Returns true if all elements are set, or false otherwise.

fn to_bitmask(self) -> u64

Creates a bitmask from a mask.

Each bit is set if the corresponding element in the mask is true.

fn from_bitmask(bitmask: u64) -> Self

Creates a mask from a bitmask.

For each bit, if it is set, the corresponding element in the mask is set to true. If the mask contains more than 64 elements, the remainder are set to false.

fn first_set(self) -> Option<usize>

Finds the index of the first set element.

# #![feature(portable_simd)]
# #[cfg(feature = "as_crate")] use core_simd::simd;
# #[cfg(not(feature = "as_crate"))] use core::simd;
# use simd::mask32x8;
assert_eq!(mask32x8::splat(false).first_set(), None);
assert_eq!(mask32x8::splat(true).first_set(), Some(0));

let mask = mask32x8::from_array([false, true, false, false, true, false, false, true]);
assert_eq!(mask.first_set(), Some(1));
fn last_set(self) -> Option<usize>

Finds the index of the last set element.

# #![feature(portable_simd)]
# #[cfg(feature = "as_crate")] use core_simd::simd;
# #[cfg(not(feature = "as_crate"))] use core::simd;
# use simd::mask32x8;
assert_eq!(mask32x8::splat(false).last_set(), None);
assert_eq!(mask32x8::splat(true).last_set(), Some(7));

let mask = mask32x8::from_array([false, true, false, false, true, false, true, false]);
assert_eq!(mask.last_set(), Some(6));

impl<T, const N: usize> Mask<T, N> where T: MaskElement,

fn reverse(self) -> Self

Reverse the order of the elements in the mask.

fn rotate_elements_left<const OFFSET: usize>(self) -> Self

Rotates the mask such that the first OFFSET elements of the slice move to the end while the last self.len() - OFFSET elements move to the front. After calling rotate_elements_left, the element previously at index OFFSET will become the first element in the slice.

fn rotate_elements_right<const OFFSET: usize>(self) -> Self

Rotates the mask such that the first self.len() - OFFSET elements of the mask move to the end while the last OFFSET elements move to the front. After calling rotate_elements_right, the element previously at index self.len() - OFFSET will become the first element in the slice.

fn shift_elements_left<const OFFSET: usize>(self, padding: bool) -> Self

Shifts the mask elements to the left by OFFSET, filling in with padding from the right.

fn shift_elements_right<const OFFSET: usize>(self, padding: bool) -> Self

Shifts the mask elements to the right by OFFSET, filling in with padding from the left.

fn interleave(self, other: Self) -> (Self, Self)

Interleave two masks.

The resulting masks contain elements taken alternatively from self and other, first filling the first result, and then the second.

The reverse of this operation is Mask::deinterleave.

# #![feature(portable_simd)]
# #[cfg(feature = "as_crate")] use core_simd::simd;
# #[cfg(not(feature = "as_crate"))] use core::simd;
# use simd::mask32x4;
let a = mask32x4::from_array([false, true, false, true]);
let b = mask32x4::from_array([false, false, true, true]);
let (x, y) = a.interleave(b);
assert_eq!(x.to_array(), [false, false, true, false]);
assert_eq!(y.to_array(), [false, true, true, true]);
fn deinterleave(self, other: Self) -> (Self, Self)

Deinterleave two masks.

The first result takes every other element of self and then other, starting with the first element.

The second result takes every other element of self and then other, starting with the second element.

The reverse of this operation is Mask::interleave.

# #![feature(portable_simd)]
# #[cfg(feature = "as_crate")] use core_simd::simd;
# #[cfg(not(feature = "as_crate"))] use core::simd;
# use simd::mask32x4;
let a = mask32x4::from_array([false, true, false, true]);
let b = mask32x4::from_array([false, false, true, true]);
let (x, y) = a.deinterleave(b);
assert_eq!(x.to_array(), [false, false, false, true]);
assert_eq!(y.to_array(), [true, true, false, true]);
fn resize<const M: usize>(self, value: bool) -> Mask<T, M>

Resize a mask.

If M > N, extends the length of a mask, setting the new elements to value. If M < N, truncates the mask to the first M elements.

# #![feature(portable_simd)]
# #[cfg(feature = "as_crate")] use core_simd::simd;
# #[cfg(not(feature = "as_crate"))] use core::simd;
# use simd::mask32x4;
let x = mask32x4::from_array([false, true, true, false]);
assert_eq!(x.resize::<8>(true).to_array(), [false, true, true, false, true, true, true, true]);
assert_eq!(x.resize::<2>(true).to_array(), [false, true]);
fn extract<const START: usize, const LEN: usize>(self) -> Mask<T, LEN>

Extract a vector from another vector.

# #![feature(portable_simd)]
# #[cfg(feature = "as_crate")] use core_simd::simd;
# #[cfg(not(feature = "as_crate"))] use core::simd;
# use simd::mask32x4;
let x = mask32x4::from_array([false, true, true, false]);
assert_eq!(x.extract::<1, 2>().to_array(), [true, true]);

Trait Implementations

impl<T, U, const N: usize> Select<Mask<T, N>> for Mask<U, N> where T: MaskElement, U: MaskElement,

fn select(self, true_values: Mask<T, N>, false_values: Mask<T, N>) -> Mask<T, N>

impl<T, U, const N: usize> Select<Simd<T, N>> for Mask<U, N> where T: SimdElement, U: MaskElement,

fn select(self, true_values: Simd<T, N>, false_values: Simd<T, N>) -> Simd<T, N>

impl<T, const N: usize> BitAnd for Mask<T, N> where T: MaskElement,

type Output = Mask<T, N>;
fn bitand(self, rhs: Self) -> Self

impl<T, const N: usize> BitAnd<bool> for Mask<T, N> where T: MaskElement,

type Output = Mask<T, N>;
fn bitand(self, rhs: bool) -> Self

impl<T, const N: usize> BitAndAssign for Mask<T, N> where T: MaskElement,

fn bitand_assign(&mut self, rhs: Self)

impl<T, const N: usize> BitAndAssign<bool> for Mask<T, N> where T: MaskElement,

fn bitand_assign(&mut self, rhs: bool)

impl<T, const N: usize> BitOr for Mask<T, N> where T: MaskElement,

type Output = Mask<T, N>;
fn bitor(self, rhs: Self) -> Self

impl<T, const N: usize> BitOr<bool> for Mask<T, N> where T: MaskElement,

type Output = Mask<T, N>;
fn bitor(self, rhs: bool) -> Self

impl<T, const N: usize> BitOrAssign for Mask<T, N> where T: MaskElement,

fn bitor_assign(&mut self, rhs: Self)

impl<T, const N: usize> BitOrAssign<bool> for Mask<T, N> where T: MaskElement,

fn bitor_assign(&mut self, rhs: bool)

impl<T, const N: usize> BitXor for Mask<T, N> where T: MaskElement,

type Output = Mask<T, N>;
fn bitxor(self, rhs: Self) -> Self::Output

impl<T, const N: usize> BitXor<bool> for Mask<T, N> where T: MaskElement,

type Output = Mask<T, N>;
fn bitxor(self, rhs: bool) -> Self::Output

impl<T, const N: usize> BitXorAssign for Mask<T, N> where T: MaskElement,

fn bitxor_assign(&mut self, rhs: Self)

impl<T, const N: usize> BitXorAssign<bool> for Mask<T, N> where T: MaskElement,

fn bitxor_assign(&mut self, rhs: bool)

impl<T, const N: usize> Clone for Mask<T, N> where T: MaskElement,

fn clone(&self) -> Self

impl<T, const N: usize> Copy for Mask<T, N> where T: MaskElement,

impl<T, const N: usize> Debug for Mask<T, N> where T: MaskElement + Debug,

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<T, const N: usize> Default for Mask<T, N> where T: MaskElement,

fn default() -> Self

impl<T, const N: usize> From<[bool; N]> for Mask<T, N> where T: MaskElement,

fn from(array: [bool; N]) -> Self

impl<T, const N: usize> Not for Mask<T, N> where T: MaskElement,

type Output = Mask<T, N>;
fn not(self) -> Self::Output

impl<T, const N: usize> PartialEq for Mask<T, N> where T: MaskElement + PartialEq,

fn eq(&self, other: &Self) -> bool

impl<T, const N: usize> PartialOrd for Mask<T, N> where T: MaskElement + PartialOrd,

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

impl<const N: usize> From<Mask<i16, N>> for Mask<i32, N>

fn from(value: Mask<i16, N>) -> Self

impl<const N: usize> From<Mask<i16, N>> for Mask<i64, N>

fn from(value: Mask<i16, N>) -> Self

impl<const N: usize> From<Mask<i16, N>> for Mask<i8, N>

fn from(value: Mask<i16, N>) -> Self

impl<const N: usize> From<Mask<i16, N>> for Mask<isize, N>

fn from(value: Mask<i16, N>) -> Self

impl<const N: usize> From<Mask<i32, N>> for Mask<i16, N>

fn from(value: Mask<i32, N>) -> Self

impl<const N: usize> From<Mask<i32, N>> for Mask<i64, N>

fn from(value: Mask<i32, N>) -> Self

impl<const N: usize> From<Mask<i32, N>> for Mask<i8, N>

fn from(value: Mask<i32, N>) -> Self

impl<const N: usize> From<Mask<i32, N>> for Mask<isize, N>

fn from(value: Mask<i32, N>) -> Self

impl<const N: usize> From<Mask<i64, N>> for Mask<i16, N>

fn from(value: Mask<i64, N>) -> Self

impl<const N: usize> From<Mask<i64, N>> for Mask<i32, N>

fn from(value: Mask<i64, N>) -> Self

impl<const N: usize> From<Mask<i64, N>> for Mask<i8, N>

fn from(value: Mask<i64, N>) -> Self

impl<const N: usize> From<Mask<i64, N>> for Mask<isize, N>

fn from(value: Mask<i64, N>) -> Self

impl<const N: usize> From<Mask<i8, N>> for Mask<i16, N>

fn from(value: Mask<i8, N>) -> Self

impl<const N: usize> From<Mask<i8, N>> for Mask<i32, N>

fn from(value: Mask<i8, N>) -> Self

impl<const N: usize> From<Mask<i8, N>> for Mask<i64, N>

fn from(value: Mask<i8, N>) -> Self

impl<const N: usize> From<Mask<i8, N>> for Mask<isize, N>

fn from(value: Mask<i8, N>) -> Self

impl<const N: usize> From<Mask<isize, N>> for Mask<i16, N>

fn from(value: Mask<isize, N>) -> Self

impl<const N: usize> From<Mask<isize, N>> for Mask<i32, N>

fn from(value: Mask<isize, N>) -> Self

impl<const N: usize> From<Mask<isize, N>> for Mask<i64, N>

fn from(value: Mask<isize, N>) -> Self

impl<const N: usize> From<Mask<isize, N>> for Mask<i8, N>

fn from(value: Mask<isize, N>) -> Self

impl<const N: usize> SimdOrd for Mask<i16, N>

fn simd_max(self, other: Self) -> Self
fn simd_min(self, other: Self) -> Self
fn simd_clamp(self, min: Self, max: Self) -> Self

impl<const N: usize> SimdOrd for Mask<i32, N>

fn simd_max(self, other: Self) -> Self
fn simd_min(self, other: Self) -> Self
fn simd_clamp(self, min: Self, max: Self) -> Self

impl<const N: usize> SimdOrd for Mask<i64, N>

fn simd_max(self, other: Self) -> Self
fn simd_min(self, other: Self) -> Self
fn simd_clamp(self, min: Self, max: Self) -> Self

impl<const N: usize> SimdOrd for Mask<i8, N>

fn simd_max(self, other: Self) -> Self
fn simd_min(self, other: Self) -> Self
fn simd_clamp(self, min: Self, max: Self) -> Self

impl<const N: usize> SimdOrd for Mask<isize, N>

fn simd_max(self, other: Self) -> Self
fn simd_min(self, other: Self) -> Self
fn simd_clamp(self, min: Self, max: Self) -> Self

impl<const N: usize> SimdPartialEq for Mask<i16, N>

type Mask = Mask<i16, N>;
fn simd_eq(self, other: Self) -> Self::Mask
fn simd_ne(self, other: Self) -> Self::Mask

impl<const N: usize> SimdPartialEq for Mask<i32, N>

type Mask = Mask<i32, N>;
fn simd_eq(self, other: Self) -> Self::Mask
fn simd_ne(self, other: Self) -> Self::Mask

impl<const N: usize> SimdPartialEq for Mask<i64, N>

type Mask = Mask<i64, N>;
fn simd_eq(self, other: Self) -> Self::Mask
fn simd_ne(self, other: Self) -> Self::Mask

impl<const N: usize> SimdPartialEq for Mask<i8, N>

type Mask = Mask<i8, N>;
fn simd_eq(self, other: Self) -> Self::Mask
fn simd_ne(self, other: Self) -> Self::Mask

impl<const N: usize> SimdPartialEq for Mask<isize, N>

type Mask = Mask<isize, N>;
fn simd_eq(self, other: Self) -> Self::Mask
fn simd_ne(self, other: Self) -> Self::Mask

impl<const N: usize> SimdPartialOrd for Mask<i16, N>

fn simd_lt(self, other: Self) -> Self::Mask
fn simd_le(self, other: Self) -> Self::Mask
fn simd_gt(self, other: Self) -> Self::Mask
fn simd_ge(self, other: Self) -> Self::Mask

impl<const N: usize> SimdPartialOrd for Mask<i32, N>

fn simd_lt(self, other: Self) -> Self::Mask
fn simd_le(self, other: Self) -> Self::Mask
fn simd_gt(self, other: Self) -> Self::Mask
fn simd_ge(self, other: Self) -> Self::Mask

impl<const N: usize> SimdPartialOrd for Mask<i64, N>

fn simd_lt(self, other: Self) -> Self::Mask
fn simd_le(self, other: Self) -> Self::Mask
fn simd_gt(self, other: Self) -> Self::Mask
fn simd_ge(self, other: Self) -> Self::Mask

impl<const N: usize> SimdPartialOrd for Mask<i8, N>

fn simd_lt(self, other: Self) -> Self::Mask
fn simd_le(self, other: Self) -> Self::Mask
fn simd_gt(self, other: Self) -> Self::Mask
fn simd_ge(self, other: Self) -> Self::Mask

impl<const N: usize> SimdPartialOrd for Mask<isize, N>

fn simd_lt(self, other: Self) -> Self::Mask
fn simd_le(self, other: Self) -> Self::Mask
fn simd_gt(self, other: Self) -> Self::Mask
fn simd_ge(self, other: Self) -> Self::Mask

Auto Trait Implementations

impl<T, const N: usize> Freeze for Mask<T, N> where Simd<T, N>: Freeze,

impl<T, const N: usize> RefUnwindSafe for Mask<T, N> where Simd<T, N>: RefUnwindSafe,

impl<T, const N: usize> Send for Mask<T, N> where Simd<T, N>: Send,

impl<T, const N: usize> Sync for Mask<T, N> where Simd<T, N>: Sync,

impl<T, const N: usize> Unpin for Mask<T, N> where Simd<T, N>: Unpin,

impl<T, const N: usize> UnsafeUnpin for Mask<T, N> where Simd<T, N>: UnsafeUnpin,

impl<T, const N: usize> UnwindSafe for Mask<T, N> where Simd<T, N>: UnwindSafe,

Blanket Implementations

impl<T> Any for Mask<T, N> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Mask<T, N> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Mask<T, N> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Mask<T, N> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for Mask<T, N>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Printable for Mask<T, N> where T: Copy + Debug,

impl<T> SizeHint for Mask<T, N> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for Mask<T, N>

impl<T, U> Into<U> for Mask<T, N> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Mask<T, N> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for Mask<T, N> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>