Skip to content

Commit 936d58b

Browse files
Merge pull request #478 from okaneco/rename_mask_int_to_simd
Rename `int` to `simd` in `Mask` functions
2 parents 295ba3b + 3a70dd6 commit 936d58b

File tree

9 files changed

+58
-56
lines changed

9 files changed

+58
-56
lines changed

crates/core_simd/src/masks.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ where
157157
let bytes: [u8; N] = mem::transmute_copy(&array);
158158
let bools: Simd<i8, N> =
159159
core::intrinsics::simd::simd_ne(Simd::from_array(bytes), Simd::splat(0u8));
160-
Mask::from_int_unchecked(core::intrinsics::simd::simd_cast(bools))
160+
Mask::from_simd_unchecked(core::intrinsics::simd::simd_cast(bools))
161161
}
162162
}
163163

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

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

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

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

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

357357
// Safety: the input and output are integer vectors
358358
let masked_index: Simd<T::Unsigned, N> =

crates/core_simd/src/masks/bitmask.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ where
105105

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

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

crates/core_simd/src/masks/full_masks.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ where
120120

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

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

@@ -145,7 +145,7 @@ where
145145
where
146146
LaneCount<M>: SupportedLaneCount,
147147
{
148-
let resized = self.to_int().resize::<M>(T::FALSE);
148+
let resized = self.to_simd().resize::<M>(T::FALSE);
149149

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

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

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

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

crates/core_simd/src/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ where
2828
{
2929
// Safety: The mask has been cast to a vector of integers,
3030
// and the operands to select between are vectors of the same type and length.
31-
unsafe { core::intrinsics::simd::simd_select(self.to_int(), true_values, false_values) }
31+
unsafe { core::intrinsics::simd::simd_select(self.to_simd(), true_values, false_values) }
3232
}
3333

3434
/// Choose elements from two masks.

crates/core_simd/src/simd/cmp/eq.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ macro_rules! impl_number {
3030
fn simd_eq(self, other: Self) -> Self::Mask {
3131
// Safety: `self` is a vector, and the result of the comparison
3232
// is always a valid mask.
33-
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_eq(self, other)) }
33+
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_eq(self, other)) }
3434
}
3535

3636
#[inline]
3737
fn simd_ne(self, other: Self) -> Self::Mask {
3838
// Safety: `self` is a vector, and the result of the comparison
3939
// is always a valid mask.
40-
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_ne(self, other)) }
40+
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_ne(self, other)) }
4141
}
4242
}
4343
)*
@@ -59,14 +59,14 @@ macro_rules! impl_mask {
5959
fn simd_eq(self, other: Self) -> Self::Mask {
6060
// Safety: `self` is a vector, and the result of the comparison
6161
// is always a valid mask.
62-
unsafe { Self::from_int_unchecked(core::intrinsics::simd::simd_eq(self.to_int(), other.to_int())) }
62+
unsafe { Self::from_simd_unchecked(core::intrinsics::simd::simd_eq(self.to_simd(), other.to_simd())) }
6363
}
6464

6565
#[inline]
6666
fn simd_ne(self, other: Self) -> Self::Mask {
6767
// Safety: `self` is a vector, and the result of the comparison
6868
// is always a valid mask.
69-
unsafe { Self::from_int_unchecked(core::intrinsics::simd::simd_ne(self.to_int(), other.to_int())) }
69+
unsafe { Self::from_simd_unchecked(core::intrinsics::simd::simd_ne(self.to_simd(), other.to_simd())) }
7070
}
7171
}
7272
)*

crates/core_simd/src/simd/cmp/ord.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,28 @@ macro_rules! impl_integer {
5656
fn simd_lt(self, other: Self) -> Self::Mask {
5757
// Safety: `self` is a vector, and the result of the comparison
5858
// is always a valid mask.
59-
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_lt(self, other)) }
59+
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_lt(self, other)) }
6060
}
6161

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

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

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

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

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

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

142142
#[inline]
143143
fn simd_ge(self, other: Self) -> Self::Mask {
144144
// Safety: `self` is a vector, and the result of the comparison
145145
// is always a valid mask.
146-
unsafe { Mask::from_int_unchecked(core::intrinsics::simd::simd_ge(self, other)) }
146+
unsafe { Mask::from_simd_unchecked(core::intrinsics::simd::simd_ge(self, other)) }
147147
}
148148
}
149149
)*
@@ -163,28 +163,28 @@ macro_rules! impl_mask {
163163
fn simd_lt(self, other: Self) -> Self::Mask {
164164
// Safety: `self` is a vector, and the result of the comparison
165165
// is always a valid mask.
166-
unsafe { Self::from_int_unchecked(core::intrinsics::simd::simd_lt(self.to_int(), other.to_int())) }
166+
unsafe { Self::from_simd_unchecked(core::intrinsics::simd::simd_lt(self.to_simd(), other.to_simd())) }
167167
}
168168

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

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

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

crates/core_simd/src/swizzle.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub trait Swizzle<const N: usize> {
165165
LaneCount<M>: SupportedLaneCount,
166166
{
167167
// SAFETY: all elements of this mask come from another mask
168-
unsafe { Mask::from_int_unchecked(Self::swizzle(mask.to_int())) }
168+
unsafe { Mask::from_simd_unchecked(Self::swizzle(mask.to_simd())) }
169169
}
170170

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

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

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

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

550552
/// Shifts the mask elements to the left by `OFFSET`, filling in with
@@ -554,7 +556,7 @@ where
554556
pub fn shift_elements_left<const OFFSET: usize>(self, padding: bool) -> Self {
555557
// Safety: swizzles are safe for masks
556558
unsafe {
557-
Self::from_int_unchecked(self.to_int().shift_elements_left::<OFFSET>(if padding {
559+
Self::from_simd_unchecked(self.to_simd().shift_elements_left::<OFFSET>(if padding {
558560
T::TRUE
559561
} else {
560562
T::FALSE
@@ -569,7 +571,7 @@ where
569571
pub fn shift_elements_right<const OFFSET: usize>(self, padding: bool) -> Self {
570572
// Safety: swizzles are safe for masks
571573
unsafe {
572-
Self::from_int_unchecked(self.to_int().shift_elements_right::<OFFSET>(if padding {
574+
Self::from_simd_unchecked(self.to_simd().shift_elements_right::<OFFSET>(if padding {
573575
T::TRUE
574576
} else {
575577
T::FALSE
@@ -598,9 +600,9 @@ where
598600
#[inline]
599601
#[must_use = "method returns a new vector and does not mutate the original inputs"]
600602
pub fn interleave(self, other: Self) -> (Self, Self) {
601-
let (lo, hi) = self.to_int().interleave(other.to_int());
603+
let (lo, hi) = self.to_simd().interleave(other.to_simd());
602604
// Safety: swizzles are safe for masks
603-
unsafe { (Self::from_int_unchecked(lo), Self::from_int_unchecked(hi)) }
605+
unsafe { (Self::from_simd_unchecked(lo), Self::from_simd_unchecked(hi)) }
604606
}
605607

606608
/// Deinterleave two masks.
@@ -627,12 +629,12 @@ where
627629
#[inline]
628630
#[must_use = "method returns a new vector and does not mutate the original inputs"]
629631
pub fn deinterleave(self, other: Self) -> (Self, Self) {
630-
let (even, odd) = self.to_int().deinterleave(other.to_int());
632+
let (even, odd) = self.to_simd().deinterleave(other.to_simd());
631633
// Safety: swizzles are safe for masks
632634
unsafe {
633635
(
634-
Self::from_int_unchecked(even),
635-
Self::from_int_unchecked(odd),
636+
Self::from_simd_unchecked(even),
637+
Self::from_simd_unchecked(odd),
636638
)
637639
}
638640
}
@@ -659,7 +661,7 @@ where
659661
{
660662
// Safety: swizzles are safe for masks
661663
unsafe {
662-
Mask::<T, M>::from_int_unchecked(self.to_int().resize::<M>(if value {
664+
Mask::<T, M>::from_simd_unchecked(self.to_simd().resize::<M>(if value {
663665
T::TRUE
664666
} else {
665667
T::FALSE
@@ -684,6 +686,6 @@ where
684686
LaneCount<LEN>: SupportedLaneCount,
685687
{
686688
// Safety: swizzles are safe for masks
687-
unsafe { Mask::<T, LEN>::from_int_unchecked(self.to_int().extract::<START, LEN>()) }
689+
unsafe { Mask::<T, LEN>::from_simd_unchecked(self.to_simd().extract::<START, LEN>()) }
688690
}
689691
}

0 commit comments

Comments
 (0)