2020-10-13 00:28:03 -05:00
|
|
|
//! Types and traits associated with masking lanes of vectors.
|
2021-04-18 14:26:07 -05:00
|
|
|
//! Types representing
|
2020-12-13 22:58:33 -06:00
|
|
|
#![allow(non_camel_case_types)]
|
2020-10-13 00:28:03 -05:00
|
|
|
|
2021-04-28 21:41:09 -05:00
|
|
|
#[cfg_attr(
|
|
|
|
not(all(target_arch = "x86_64", target_feature = "avx512f")),
|
2021-06-29 16:48:54 -05:00
|
|
|
path = "masks/full_masks.rs"
|
2021-04-28 21:41:09 -05:00
|
|
|
)]
|
|
|
|
#[cfg_attr(
|
|
|
|
all(target_arch = "x86_64", target_feature = "avx512f"),
|
2021-06-29 16:48:54 -05:00
|
|
|
path = "masks/bitmask.rs"
|
2021-04-28 21:41:09 -05:00
|
|
|
)]
|
2021-04-18 14:26:07 -05:00
|
|
|
mod mask_impl;
|
2021-02-03 23:31:57 -06:00
|
|
|
|
2021-09-18 20:31:49 -05:00
|
|
|
use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
|
|
|
|
use core::cmp::Ordering;
|
|
|
|
use core::fmt;
|
2021-02-03 23:31:57 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Marker trait for types that may be used as SIMD mask elements.
|
|
|
|
pub unsafe trait MaskElement: SimdElement {
|
|
|
|
#[doc(hidden)]
|
|
|
|
fn valid<const LANES: usize>(values: Simd<Self, LANES>) -> bool
|
|
|
|
where
|
|
|
|
LaneCount<LANES>: SupportedLaneCount;
|
2021-03-06 01:14:58 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
#[doc(hidden)]
|
|
|
|
fn eq(self, other: Self) -> bool;
|
2021-03-06 01:14:58 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
#[doc(hidden)]
|
|
|
|
const TRUE: Self;
|
2021-04-18 14:26:07 -05:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
#[doc(hidden)]
|
|
|
|
const FALSE: Self;
|
|
|
|
}
|
2021-04-18 23:31:43 -05:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
macro_rules! impl_element {
|
|
|
|
{ $ty:ty } => {
|
|
|
|
unsafe impl MaskElement for $ty {
|
|
|
|
fn valid<const LANES: usize>(value: Simd<Self, LANES>) -> bool
|
|
|
|
where
|
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
(value.lanes_eq(Simd::splat(0)) | value.lanes_eq(Simd::splat(-1))).all()
|
2021-04-18 23:31:43 -05:00
|
|
|
}
|
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
fn eq(self, other: Self) -> bool { self == other }
|
2021-04-18 23:31:43 -05:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
const TRUE: Self = -1;
|
|
|
|
const FALSE: Self = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-18 23:31:43 -05:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
impl_element! { i8 }
|
|
|
|
impl_element! { i16 }
|
|
|
|
impl_element! { i32 }
|
|
|
|
impl_element! { i64 }
|
|
|
|
impl_element! { isize }
|
|
|
|
|
|
|
|
/// A SIMD vector mask for `LANES` elements of width specified by `Element`.
|
|
|
|
///
|
|
|
|
/// The layout of this type is unspecified.
|
|
|
|
#[repr(transparent)]
|
2021-08-16 15:38:30 -05:00
|
|
|
pub struct Mask<T, const LANES: usize>(mask_impl::Mask<T, LANES>)
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount;
|
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> Copy for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
}
|
2021-02-03 23:31:57 -06:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> Clone for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
*self
|
|
|
|
}
|
|
|
|
}
|
2021-04-18 23:31:43 -05:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
/// Construct a mask by setting all lanes to the given value.
|
|
|
|
pub fn splat(value: bool) -> Self {
|
|
|
|
Self(mask_impl::Mask::splat(value))
|
|
|
|
}
|
2021-06-21 16:05:43 -05:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Converts an array to a SIMD vector.
|
|
|
|
pub fn from_array(array: [bool; LANES]) -> Self {
|
|
|
|
let mut vector = Self::splat(false);
|
|
|
|
for (i, v) in array.iter().enumerate() {
|
|
|
|
vector.set(i, *v);
|
2021-02-03 23:31:57 -06:00
|
|
|
}
|
2021-08-06 23:30:24 -05:00
|
|
|
vector
|
|
|
|
}
|
2021-02-03 23:31:57 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Converts a SIMD vector to an array.
|
|
|
|
pub fn to_array(self) -> [bool; LANES] {
|
|
|
|
let mut array = [false; LANES];
|
|
|
|
for (i, v) in array.iter_mut().enumerate() {
|
|
|
|
*v = self.test(i);
|
2021-03-06 01:14:58 -06:00
|
|
|
}
|
2021-08-06 23:30:24 -05:00
|
|
|
array
|
|
|
|
}
|
2021-03-06 01:14:58 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Converts a vector of integers to a mask, where 0 represents `false` and -1
|
|
|
|
/// represents `true`.
|
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
/// All lanes must be either 0 or -1.
|
|
|
|
#[inline]
|
2021-08-16 15:38:30 -05:00
|
|
|
pub unsafe fn from_int_unchecked(value: Simd<T, LANES>) -> Self {
|
2021-08-06 23:30:24 -05:00
|
|
|
Self(mask_impl::Mask::from_int_unchecked(value))
|
|
|
|
}
|
2021-03-06 01:14:58 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Converts a vector of integers to a mask, where 0 represents `false` and -1
|
|
|
|
/// represents `true`.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
/// Panics if any lane is not 0 or -1.
|
|
|
|
#[inline]
|
2021-08-16 15:38:30 -05:00
|
|
|
pub fn from_int(value: Simd<T, LANES>) -> Self {
|
|
|
|
assert!(T::valid(value), "all values must be either 0 or -1",);
|
2021-08-06 23:30:24 -05:00
|
|
|
unsafe { Self::from_int_unchecked(value) }
|
|
|
|
}
|
2021-02-03 23:31:57 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Converts the mask to a vector of integers, where 0 represents `false` and -1
|
|
|
|
/// represents `true`.
|
|
|
|
#[inline]
|
2021-08-16 15:38:30 -05:00
|
|
|
pub fn to_int(self) -> Simd<T, LANES> {
|
2021-08-06 23:30:24 -05:00
|
|
|
self.0.to_int()
|
|
|
|
}
|
2021-02-03 23:31:57 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Tests the value of the specified lane.
|
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
/// `lane` must be less than `LANES`.
|
|
|
|
#[inline]
|
|
|
|
pub unsafe fn test_unchecked(&self, lane: usize) -> bool {
|
|
|
|
self.0.test_unchecked(lane)
|
|
|
|
}
|
2021-02-03 23:31:57 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Tests the value of the specified lane.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
/// Panics if `lane` is greater than or equal to the number of lanes in the vector.
|
|
|
|
#[inline]
|
|
|
|
pub fn test(&self, lane: usize) -> bool {
|
|
|
|
assert!(lane < LANES, "lane index out of range");
|
|
|
|
unsafe { self.test_unchecked(lane) }
|
|
|
|
}
|
2021-02-03 23:31:57 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Sets the value of the specified lane.
|
|
|
|
///
|
|
|
|
/// # Safety
|
|
|
|
/// `lane` must be less than `LANES`.
|
|
|
|
#[inline]
|
|
|
|
pub unsafe fn set_unchecked(&mut self, lane: usize, value: bool) {
|
|
|
|
self.0.set_unchecked(lane, value);
|
|
|
|
}
|
2021-02-03 23:31:57 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Sets the value of the specified lane.
|
|
|
|
///
|
|
|
|
/// # Panics
|
|
|
|
/// Panics if `lane` is greater than or equal to the number of lanes in the vector.
|
|
|
|
#[inline]
|
|
|
|
pub fn set(&mut self, lane: usize, value: bool) {
|
|
|
|
assert!(lane < LANES, "lane index out of range");
|
|
|
|
unsafe {
|
|
|
|
self.set_unchecked(lane, value);
|
2021-02-03 23:31:57 -06:00
|
|
|
}
|
2021-08-06 23:30:24 -05:00
|
|
|
}
|
2021-02-03 23:31:57 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Convert this mask to a bitmask, with one bit set per lane.
|
2021-09-08 19:01:16 -05:00
|
|
|
#[cfg(feature = "generic_const_exprs")]
|
2021-08-06 23:30:24 -05:00
|
|
|
pub fn to_bitmask(self) -> [u8; LaneCount::<LANES>::BITMASK_LEN] {
|
|
|
|
self.0.to_bitmask()
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Convert a bitmask to a mask.
|
2021-09-08 19:01:16 -05:00
|
|
|
#[cfg(feature = "generic_const_exprs")]
|
2021-08-06 23:30:24 -05:00
|
|
|
pub fn from_bitmask(bitmask: [u8; LaneCount::<LANES>::BITMASK_LEN]) -> Self {
|
|
|
|
Self(mask_impl::Mask::from_bitmask(bitmask))
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Returns true if any lane is set, or false otherwise.
|
|
|
|
#[inline]
|
|
|
|
pub fn any(self) -> bool {
|
|
|
|
self.0.any()
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
/// Returns true if all lanes are set, or false otherwise.
|
|
|
|
#[inline]
|
|
|
|
pub fn all(self) -> bool {
|
|
|
|
self.0.all()
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-06 23:30:24 -05:00
|
|
|
// vector/array conversion
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> From<[bool; LANES]> for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
fn from(array: [bool; LANES]) -> Self {
|
|
|
|
Self::from_array(array)
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> From<Mask<T, LANES>> for [bool; LANES]
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
2021-08-16 15:38:30 -05:00
|
|
|
fn from(vector: Mask<T, LANES>) -> Self {
|
2021-08-06 23:30:24 -05:00
|
|
|
vector.to_array()
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> Default for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::splat(false)
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> PartialEq for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement + PartialEq,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
self.0 == other.0
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> PartialOrd for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement + PartialOrd,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
#[inline]
|
2021-09-18 20:31:49 -05:00
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
2021-08-06 23:30:24 -05:00
|
|
|
self.0.partial_cmp(&other.0)
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-09-18 20:31:49 -05:00
|
|
|
impl<T, const LANES: usize> fmt::Debug for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-09-18 20:31:49 -05:00
|
|
|
T: MaskElement + fmt::Debug,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
2021-09-18 20:31:49 -05:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2021-08-06 23:30:24 -05:00
|
|
|
f.debug_list()
|
|
|
|
.entries((0..LANES).map(|lane| self.test(lane)))
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitAnd for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
type Output = Self;
|
|
|
|
#[inline]
|
|
|
|
fn bitand(self, rhs: Self) -> Self {
|
|
|
|
Self(self.0 & rhs.0)
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitAnd<bool> for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
type Output = Self;
|
|
|
|
#[inline]
|
|
|
|
fn bitand(self, rhs: bool) -> Self {
|
|
|
|
self & Self::splat(rhs)
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitAnd<Mask<T, LANES>> for bool
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
2021-08-16 15:38:30 -05:00
|
|
|
type Output = Mask<T, LANES>;
|
2021-08-06 23:30:24 -05:00
|
|
|
#[inline]
|
2021-08-16 15:38:30 -05:00
|
|
|
fn bitand(self, rhs: Mask<T, LANES>) -> Mask<T, LANES> {
|
2021-08-06 23:30:24 -05:00
|
|
|
Mask::splat(self) & rhs
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitOr for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
type Output = Self;
|
|
|
|
#[inline]
|
|
|
|
fn bitor(self, rhs: Self) -> Self {
|
|
|
|
Self(self.0 | rhs.0)
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitOr<bool> for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
type Output = Self;
|
|
|
|
#[inline]
|
|
|
|
fn bitor(self, rhs: bool) -> Self {
|
|
|
|
self | Self::splat(rhs)
|
|
|
|
}
|
|
|
|
}
|
2020-11-22 14:18:31 -06:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitOr<Mask<T, LANES>> for bool
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
2021-08-16 15:38:30 -05:00
|
|
|
type Output = Mask<T, LANES>;
|
2021-08-06 23:30:24 -05:00
|
|
|
#[inline]
|
2021-08-16 15:38:30 -05:00
|
|
|
fn bitor(self, rhs: Mask<T, LANES>) -> Mask<T, LANES> {
|
2021-08-06 23:30:24 -05:00
|
|
|
Mask::splat(self) | rhs
|
|
|
|
}
|
2020-12-13 22:58:33 -06:00
|
|
|
}
|
2020-10-13 00:28:03 -05:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitXor for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
type Output = Self;
|
|
|
|
#[inline]
|
|
|
|
fn bitxor(self, rhs: Self) -> Self::Output {
|
|
|
|
Self(self.0 ^ rhs.0)
|
|
|
|
}
|
2020-12-13 22:58:33 -06:00
|
|
|
}
|
2020-10-13 00:28:03 -05:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitXor<bool> for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
type Output = Self;
|
|
|
|
#[inline]
|
|
|
|
fn bitxor(self, rhs: bool) -> Self::Output {
|
|
|
|
self ^ Self::splat(rhs)
|
|
|
|
}
|
2020-12-13 22:58:33 -06:00
|
|
|
}
|
2020-10-13 00:28:03 -05:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitXor<Mask<T, LANES>> for bool
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
2021-08-16 15:38:30 -05:00
|
|
|
type Output = Mask<T, LANES>;
|
2021-08-06 23:30:24 -05:00
|
|
|
#[inline]
|
2021-08-16 15:38:30 -05:00
|
|
|
fn bitxor(self, rhs: Mask<T, LANES>) -> Self::Output {
|
2021-08-06 23:30:24 -05:00
|
|
|
Mask::splat(self) ^ rhs
|
|
|
|
}
|
2020-12-13 22:58:33 -06:00
|
|
|
}
|
2020-10-13 00:28:03 -05:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::Not for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
2021-08-16 15:38:30 -05:00
|
|
|
type Output = Mask<T, LANES>;
|
2021-08-06 23:30:24 -05:00
|
|
|
#[inline]
|
|
|
|
fn not(self) -> Self::Output {
|
|
|
|
Self(!self.0)
|
|
|
|
}
|
2020-12-13 22:58:33 -06:00
|
|
|
}
|
2020-10-13 00:28:03 -05:00
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitAndAssign for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn bitand_assign(&mut self, rhs: Self) {
|
|
|
|
self.0 = self.0 & rhs.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitAndAssign<bool> for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn bitand_assign(&mut self, rhs: bool) {
|
|
|
|
*self &= Self::splat(rhs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitOrAssign for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn bitor_assign(&mut self, rhs: Self) {
|
|
|
|
self.0 = self.0 | rhs.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitOrAssign<bool> for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn bitor_assign(&mut self, rhs: bool) {
|
|
|
|
*self |= Self::splat(rhs);
|
|
|
|
}
|
2020-12-13 22:58:33 -06:00
|
|
|
}
|
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitXorAssign for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn bitxor_assign(&mut self, rhs: Self) {
|
|
|
|
self.0 = self.0 ^ rhs.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-16 15:38:30 -05:00
|
|
|
impl<T, const LANES: usize> core::ops::BitXorAssign<bool> for Mask<T, LANES>
|
2021-08-06 23:30:24 -05:00
|
|
|
where
|
2021-08-16 15:38:30 -05:00
|
|
|
T: MaskElement,
|
2021-08-06 23:30:24 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn bitxor_assign(&mut self, rhs: bool) {
|
|
|
|
*self ^= Self::splat(rhs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-13 22:58:33 -06:00
|
|
|
/// Vector of eight 8-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask8x8 = Mask<i8, 8>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of 16 8-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask8x16 = Mask<i8, 16>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of 32 8-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask8x32 = Mask<i8, 32>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of 16 8-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask8x64 = Mask<i8, 64>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of four 16-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask16x4 = Mask<i16, 4>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of eight 16-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask16x8 = Mask<i16, 8>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of 16 16-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask16x16 = Mask<i16, 16>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of 32 16-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask16x32 = Mask<i32, 32>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of two 32-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask32x2 = Mask<i32, 2>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of four 32-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask32x4 = Mask<i32, 4>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of eight 32-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask32x8 = Mask<i32, 8>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of 16 32-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask32x16 = Mask<i32, 16>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of two 64-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask64x2 = Mask<i64, 2>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of four 64-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask64x4 = Mask<i64, 4>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of eight 64-bit masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type mask64x8 = Mask<i64, 8>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of two pointer-width masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type masksizex2 = Mask<isize, 2>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of four pointer-width masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type masksizex4 = Mask<isize, 4>;
|
2020-12-13 22:58:33 -06:00
|
|
|
|
|
|
|
/// Vector of eight pointer-width masks
|
2021-08-07 16:22:10 -05:00
|
|
|
pub type masksizex8 = Mask<isize, 8>;
|
2021-06-11 17:48:05 -05:00
|
|
|
|
|
|
|
macro_rules! impl_from {
|
2021-08-07 14:28:27 -05:00
|
|
|
{ $from:ty => $($to:ty),* } => {
|
2021-06-11 17:48:05 -05:00
|
|
|
$(
|
2021-08-07 14:28:27 -05:00
|
|
|
impl<const LANES: usize> From<Mask<$from, LANES>> for Mask<$to, LANES>
|
2021-06-11 17:48:05 -05:00
|
|
|
where
|
2021-08-07 14:28:27 -05:00
|
|
|
LaneCount<LANES>: SupportedLaneCount,
|
2021-06-11 17:48:05 -05:00
|
|
|
{
|
2021-08-07 14:28:27 -05:00
|
|
|
fn from(value: Mask<$from, LANES>) -> Self {
|
2021-08-06 23:30:24 -05:00
|
|
|
Self(value.0.convert())
|
2021-06-11 17:48:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
2021-08-07 14:28:27 -05:00
|
|
|
impl_from! { i8 => i16, i32, i64, isize }
|
|
|
|
impl_from! { i16 => i32, i64, isize, i8 }
|
|
|
|
impl_from! { i32 => i64, isize, i8, i16 }
|
|
|
|
impl_from! { i64 => isize, i8, i16, i32 }
|
|
|
|
impl_from! { isize => i8, i16, i32, i64 }
|