Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions crates/core_simd/src/masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ where
let bytes: [u8; N] = mem::transmute_copy(&array);
let bools: Simd<i8, N> =
core::intrinsics::simd::simd_ne(Simd::from_array(bytes), Simd::splat(0u8));
Mask::from_int_unchecked(core::intrinsics::simd::simd_cast(bools))
Mask::from_simd_unchecked(core::intrinsics::simd::simd_cast(bools))
}
}

Expand All @@ -175,7 +175,7 @@ where
// This would be hypothetically valid as an "in-place" transmute,
// but these are "dependently-sized" types, so copy elision it is!
unsafe {
let mut bytes: Simd<i8, N> = core::intrinsics::simd::simd_cast(self.to_int());
let mut bytes: Simd<i8, N> = core::intrinsics::simd::simd_cast(self.to_simd());
bytes &= Simd::splat(1i8);
mem::transmute_copy(&bytes)
}
Expand All @@ -188,11 +188,11 @@ where
/// All elements must be either 0 or -1.
#[inline]
#[must_use = "method returns a new mask and does not mutate the original value"]
pub unsafe fn from_int_unchecked(value: Simd<T, N>) -> Self {
pub unsafe fn from_simd_unchecked(value: Simd<T, N>) -> Self {
// Safety: the caller must confirm this invariant
unsafe {
core::intrinsics::assume(<T as Sealed>::valid(value));
Self(mask_impl::Mask::from_int_unchecked(value))
Self(mask_impl::Mask::from_simd_unchecked(value))
}
}

Expand All @@ -204,18 +204,18 @@ where
#[inline]
#[must_use = "method returns a new mask and does not mutate the original value"]
#[track_caller]
pub fn from_int(value: Simd<T, N>) -> Self {
pub fn from_simd(value: Simd<T, N>) -> Self {
assert!(T::valid(value), "all values must be either 0 or -1",);
// Safety: the validity has been checked
unsafe { Self::from_int_unchecked(value) }
unsafe { Self::from_simd_unchecked(value) }
}

/// Converts the mask to a vector of integers, where 0 represents `false` and -1
/// represents `true`.
#[inline]
#[must_use = "method returns a new vector and does not mutate the original value"]
pub fn to_int(self) -> Simd<T, N> {
self.0.to_int()
pub fn to_simd(self) -> Simd<T, N> {
self.0.to_simd()
}

/// Converts the mask to a mask of any other element size.
Expand Down Expand Up @@ -352,7 +352,7 @@ where
// Safety: the input and output are integer vectors
let index: Simd<T, N> = unsafe { core::intrinsics::simd::simd_cast(index) };

let masked_index = self.select(index, Self::splat(true).to_int());
let masked_index = self.select(index, Self::splat(true).to_simd());

// Safety: the input and output are integer vectors
let masked_index: Simd<T::Unsigned, N> =
Expand Down
4 changes: 2 additions & 2 deletions crates/core_simd/src/masks/bitmask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ where

#[inline]
#[must_use = "method returns a new vector and does not mutate the original value"]
pub(crate) fn to_int(self) -> Simd<T, N> {
pub(crate) fn to_simd(self) -> Simd<T, N> {
unsafe {
core::intrinsics::simd::simd_select_bitmask(
self.0,
Expand All @@ -117,7 +117,7 @@ where

#[inline]
#[must_use = "method returns a new mask and does not mutate the original value"]
pub(crate) unsafe fn from_int_unchecked(value: Simd<T, N>) -> Self {
pub(crate) unsafe fn from_simd_unchecked(value: Simd<T, N>) -> Self {
unsafe { Self(core::intrinsics::simd::simd_bitmask(value), PhantomData) }
}

Expand Down
12 changes: 6 additions & 6 deletions crates/core_simd/src/masks/full_masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ where

#[inline]
#[must_use = "method returns a new vector and does not mutate the original value"]
pub(crate) fn to_int(self) -> Simd<T, N> {
pub(crate) fn to_simd(self) -> Simd<T, N> {
self.0
}

#[inline]
#[must_use = "method returns a new mask and does not mutate the original value"]
pub(crate) unsafe fn from_int_unchecked(value: Simd<T, N>) -> Self {
pub(crate) unsafe fn from_simd_unchecked(value: Simd<T, N>) -> Self {
Self(value)
}

Expand All @@ -145,7 +145,7 @@ where
where
LaneCount<M>: SupportedLaneCount,
{
let resized = self.to_int().resize::<M>(T::FALSE);
let resized = self.to_simd().resize::<M>(T::FALSE);

// Safety: `resized` is an integer vector with length M, which must match T
let bitmask: U = unsafe { core::intrinsics::simd::simd_bitmask(resized) };
Expand Down Expand Up @@ -180,7 +180,7 @@ where
};

// SAFETY: `mask` only contains `T::TRUE` or `T::FALSE`
unsafe { Self::from_int_unchecked(mask.resize::<N>(T::FALSE)) }
unsafe { Self::from_simd_unchecked(mask.resize::<N>(T::FALSE)) }
}

#[inline]
Expand Down Expand Up @@ -223,14 +223,14 @@ where
#[must_use = "method returns a new bool and does not mutate the original value"]
pub(crate) fn any(self) -> bool {
// Safety: use `self` as an integer vector
unsafe { core::intrinsics::simd::simd_reduce_any(self.to_int()) }
unsafe { core::intrinsics::simd::simd_reduce_any(self.to_simd()) }
}

#[inline]
#[must_use = "method returns a new bool and does not mutate the original value"]
pub(crate) fn all(self) -> bool {
// Safety: use `self` as an integer vector
unsafe { core::intrinsics::simd::simd_reduce_all(self.to_int()) }
unsafe { core::intrinsics::simd::simd_reduce_all(self.to_simd()) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/core_simd/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where
{
// Safety: The mask has been cast to a vector of integers,
// and the operands to select between are vectors of the same type and length.
unsafe { core::intrinsics::simd::simd_select(self.to_int(), true_values, false_values) }
unsafe { core::intrinsics::simd::simd_select(self.to_simd(), true_values, false_values) }
}

/// Choose elements from two masks.
Expand Down
8 changes: 4 additions & 4 deletions crates/core_simd/src/simd/cmp/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ macro_rules! impl_number {
fn simd_eq(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_eq(self, other)) }
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_eq(self, other)) }
}

#[inline]
fn simd_ne(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_ne(self, other)) }
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_ne(self, other)) }
}
}
)*
Expand All @@ -59,14 +59,14 @@ macro_rules! impl_mask {
fn simd_eq(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Self::from_int_unchecked(core::intrinsics::simd::simd_eq(self.to_int(), other.to_int())) }
unsafe { Self::from_simd_unchecked(core::intrinsics::simd::simd_eq(self.to_simd(), other.to_simd())) }
}

#[inline]
fn simd_ne(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Self::from_int_unchecked(core::intrinsics::simd::simd_ne(self.to_int(), other.to_int())) }
unsafe { Self::from_simd_unchecked(core::intrinsics::simd::simd_ne(self.to_simd(), other.to_simd())) }
}
}
)*
Expand Down
24 changes: 12 additions & 12 deletions crates/core_simd/src/simd/cmp/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,28 @@ macro_rules! impl_integer {
fn simd_lt(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_lt(self, other)) }
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_lt(self, other)) }
}

#[inline]
fn simd_le(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_le(self, other)) }
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_le(self, other)) }
}

#[inline]
fn simd_gt(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_gt(self, other)) }
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_gt(self, other)) }
}

#[inline]
fn simd_ge(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_ge(self, other)) }
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_ge(self, other)) }
}
}

Expand Down Expand Up @@ -122,28 +122,28 @@ macro_rules! impl_float {
fn simd_lt(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_lt(self, other)) }
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_lt(self, other)) }
}

#[inline]
fn simd_le(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_le(self, other)) }
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_le(self, other)) }
}

#[inline]
fn simd_gt(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_gt(self, other)) }
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_gt(self, other)) }
}

#[inline]
fn simd_ge(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_ge(self, other)) }
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_ge(self, other)) }
}
}
)*
Expand All @@ -163,28 +163,28 @@ macro_rules! impl_mask {
fn simd_lt(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Self::from_int_unchecked(core::intrinsics::simd::simd_lt(self.to_int(), other.to_int())) }
unsafe { Self::from_simd_unchecked(core::intrinsics::simd::simd_lt(self.to_simd(), other.to_simd())) }
}

#[inline]
fn simd_le(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Self::from_int_unchecked(core::intrinsics::simd::simd_le(self.to_int(), other.to_int())) }
unsafe { Self::from_simd_unchecked(core::intrinsics::simd::simd_le(self.to_simd(), other.to_simd())) }
}

#[inline]
fn simd_gt(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Self::from_int_unchecked(core::intrinsics::simd::simd_gt(self.to_int(), other.to_int())) }
unsafe { Self::from_simd_unchecked(core::intrinsics::simd::simd_gt(self.to_simd(), other.to_simd())) }
}

#[inline]
fn simd_ge(self, other: Self) -> Self::Mask {
// Safety: `self` is a vector, and the result of the comparison
// is always a valid mask.
unsafe { Self::from_int_unchecked(core::intrinsics::simd::simd_ge(self.to_int(), other.to_int())) }
unsafe { Self::from_simd_unchecked(core::intrinsics::simd::simd_ge(self.to_simd(), other.to_simd())) }
}
}

Expand Down
30 changes: 16 additions & 14 deletions crates/core_simd/src/swizzle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub trait Swizzle<const N: usize> {
LaneCount<M>: SupportedLaneCount,
{
// SAFETY: all elements of this mask come from another mask
unsafe { Mask::from_int_unchecked(Self::swizzle(mask.to_int())) }
unsafe { Mask::from_simd_unchecked(Self::swizzle(mask.to_simd())) }
}

/// Creates a new mask from the elements of `first` and `second`.
Expand All @@ -181,7 +181,9 @@ pub trait Swizzle<const N: usize> {
LaneCount<M>: SupportedLaneCount,
{
// SAFETY: all elements of this mask come from another mask
unsafe { Mask::from_int_unchecked(Self::concat_swizzle(first.to_int(), second.to_int())) }
unsafe {
Mask::from_simd_unchecked(Self::concat_swizzle(first.to_simd(), second.to_simd()))
}
}
}

Expand Down Expand Up @@ -524,7 +526,7 @@ where
#[must_use = "method returns a new vector and does not mutate the original inputs"]
pub fn reverse(self) -> Self {
// Safety: swizzles are safe for masks
unsafe { Self::from_int_unchecked(self.to_int().reverse()) }
unsafe { Self::from_simd_unchecked(self.to_simd().reverse()) }
}

/// Rotates the mask such that the first `OFFSET` elements of the slice move to the end
Expand All @@ -534,7 +536,7 @@ where
#[must_use = "method returns a new vector and does not mutate the original inputs"]
pub fn rotate_elements_left<const OFFSET: usize>(self) -> Self {
// Safety: swizzles are safe for masks
unsafe { Self::from_int_unchecked(self.to_int().rotate_elements_left::<OFFSET>()) }
unsafe { Self::from_simd_unchecked(self.to_simd().rotate_elements_left::<OFFSET>()) }
}

/// Rotates the mask such that the first `self.len() - OFFSET` elements of the mask move to
Expand All @@ -544,7 +546,7 @@ where
#[must_use = "method returns a new vector and does not mutate the original inputs"]
pub fn rotate_elements_right<const OFFSET: usize>(self) -> Self {
// Safety: swizzles are safe for masks
unsafe { Self::from_int_unchecked(self.to_int().rotate_elements_right::<OFFSET>()) }
unsafe { Self::from_simd_unchecked(self.to_simd().rotate_elements_right::<OFFSET>()) }
}

/// Shifts the mask elements to the left by `OFFSET`, filling in with
Expand All @@ -554,7 +556,7 @@ where
pub fn shift_elements_left<const OFFSET: usize>(self, padding: bool) -> Self {
// Safety: swizzles are safe for masks
unsafe {
Self::from_int_unchecked(self.to_int().shift_elements_left::<OFFSET>(if padding {
Self::from_simd_unchecked(self.to_simd().shift_elements_left::<OFFSET>(if padding {
T::TRUE
} else {
T::FALSE
Expand All @@ -569,7 +571,7 @@ where
pub fn shift_elements_right<const OFFSET: usize>(self, padding: bool) -> Self {
// Safety: swizzles are safe for masks
unsafe {
Self::from_int_unchecked(self.to_int().shift_elements_right::<OFFSET>(if padding {
Self::from_simd_unchecked(self.to_simd().shift_elements_right::<OFFSET>(if padding {
T::TRUE
} else {
T::FALSE
Expand Down Expand Up @@ -598,9 +600,9 @@ where
#[inline]
#[must_use = "method returns a new vector and does not mutate the original inputs"]
pub fn interleave(self, other: Self) -> (Self, Self) {
let (lo, hi) = self.to_int().interleave(other.to_int());
let (lo, hi) = self.to_simd().interleave(other.to_simd());
// Safety: swizzles are safe for masks
unsafe { (Self::from_int_unchecked(lo), Self::from_int_unchecked(hi)) }
unsafe { (Self::from_simd_unchecked(lo), Self::from_simd_unchecked(hi)) }
}

/// Deinterleave two masks.
Expand All @@ -627,12 +629,12 @@ where
#[inline]
#[must_use = "method returns a new vector and does not mutate the original inputs"]
pub fn deinterleave(self, other: Self) -> (Self, Self) {
let (even, odd) = self.to_int().deinterleave(other.to_int());
let (even, odd) = self.to_simd().deinterleave(other.to_simd());
// Safety: swizzles are safe for masks
unsafe {
(
Self::from_int_unchecked(even),
Self::from_int_unchecked(odd),
Self::from_simd_unchecked(even),
Self::from_simd_unchecked(odd),
)
}
}
Expand All @@ -659,7 +661,7 @@ where
{
// Safety: swizzles are safe for masks
unsafe {
Mask::<T, M>::from_int_unchecked(self.to_int().resize::<M>(if value {
Mask::<T, M>::from_simd_unchecked(self.to_simd().resize::<M>(if value {
T::TRUE
} else {
T::FALSE
Expand All @@ -684,6 +686,6 @@ where
LaneCount<LEN>: SupportedLaneCount,
{
// Safety: swizzles are safe for masks
unsafe { Mask::<T, LEN>::from_int_unchecked(self.to_int().extract::<START, LEN>()) }
unsafe { Mask::<T, LEN>::from_simd_unchecked(self.to_simd().extract::<START, LEN>()) }
}
}
Loading
Loading