Skip to content

Commit da42aa5

Browse files
committed
Begin reducing mask API
1 parent 5751179 commit da42aa5

File tree

8 files changed

+59
-341
lines changed

8 files changed

+59
-341
lines changed

crates/core_simd/src/comparisons.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::LanesAtMost32;
22

33
macro_rules! implement_mask_ops {
4-
{ $($vector:ident => $mask:ident ($inner_mask_ty:ident, $inner_ty:ident),)* } => {
4+
{ $($vector:ident => $mask:ident ($inner_ty:ident),)* } => {
55
$(
66
impl<const LANES: usize> crate::$vector<LANES>
77
where
@@ -12,53 +12,47 @@ macro_rules! implement_mask_ops {
1212
#[inline]
1313
pub fn lanes_eq(self, other: Self) -> crate::$mask<LANES> {
1414
unsafe {
15-
crate::$inner_mask_ty::from_int_unchecked(crate::intrinsics::simd_eq(self, other))
16-
.into()
15+
crate::$mask::from_int_unchecked(crate::intrinsics::simd_eq(self, other))
1716
}
1817
}
1918

2019
/// Test if each lane is not equal to the corresponding lane in `other`.
2120
#[inline]
2221
pub fn lanes_ne(self, other: Self) -> crate::$mask<LANES> {
2322
unsafe {
24-
crate::$inner_mask_ty::from_int_unchecked(crate::intrinsics::simd_ne(self, other))
25-
.into()
23+
crate::$mask::from_int_unchecked(crate::intrinsics::simd_ne(self, other))
2624
}
2725
}
2826

2927
/// Test if each lane is less than the corresponding lane in `other`.
3028
#[inline]
3129
pub fn lanes_lt(self, other: Self) -> crate::$mask<LANES> {
3230
unsafe {
33-
crate::$inner_mask_ty::from_int_unchecked(crate::intrinsics::simd_lt(self, other))
34-
.into()
31+
crate::$mask::from_int_unchecked(crate::intrinsics::simd_lt(self, other))
3532
}
3633
}
3734

3835
/// Test if each lane is greater than the corresponding lane in `other`.
3936
#[inline]
4037
pub fn lanes_gt(self, other: Self) -> crate::$mask<LANES> {
4138
unsafe {
42-
crate::$inner_mask_ty::from_int_unchecked(crate::intrinsics::simd_gt(self, other))
43-
.into()
39+
crate::$mask::from_int_unchecked(crate::intrinsics::simd_gt(self, other))
4440
}
4541
}
4642

4743
/// Test if each lane is less than or equal to the corresponding lane in `other`.
4844
#[inline]
4945
pub fn lanes_le(self, other: Self) -> crate::$mask<LANES> {
5046
unsafe {
51-
crate::$inner_mask_ty::from_int_unchecked(crate::intrinsics::simd_le(self, other))
52-
.into()
47+
crate::$mask::from_int_unchecked(crate::intrinsics::simd_le(self, other))
5348
}
5449
}
5550

5651
/// Test if each lane is greater than or equal to the corresponding lane in `other`.
5752
#[inline]
5853
pub fn lanes_ge(self, other: Self) -> crate::$mask<LANES> {
5954
unsafe {
60-
crate::$inner_mask_ty::from_int_unchecked(crate::intrinsics::simd_ge(self, other))
61-
.into()
55+
crate::$mask::from_int_unchecked(crate::intrinsics::simd_ge(self, other))
6256
}
6357
}
6458
}
@@ -67,18 +61,18 @@ macro_rules! implement_mask_ops {
6761
}
6862

6963
implement_mask_ops! {
70-
SimdI8 => Mask8 (SimdMask8, SimdI8),
71-
SimdI16 => Mask16 (SimdMask16, SimdI16),
72-
SimdI32 => Mask32 (SimdMask32, SimdI32),
73-
SimdI64 => Mask64 (SimdMask64, SimdI64),
74-
SimdIsize => MaskSize (SimdMaskSize, SimdIsize),
64+
SimdI8 => Mask8 (SimdI8),
65+
SimdI16 => Mask16 (SimdI16),
66+
SimdI32 => Mask32 (SimdI32),
67+
SimdI64 => Mask64 (SimdI64),
68+
SimdIsize => MaskSize (SimdIsize),
7569

76-
SimdU8 => Mask8 (SimdMask8, SimdI8),
77-
SimdU16 => Mask16 (SimdMask16, SimdI16),
78-
SimdU32 => Mask32 (SimdMask32, SimdI32),
79-
SimdU64 => Mask64 (SimdMask64, SimdI64),
80-
SimdUsize => MaskSize (SimdMaskSize, SimdIsize),
70+
SimdU8 => Mask8 (SimdI8),
71+
SimdU16 => Mask16 (SimdI16),
72+
SimdU32 => Mask32 (SimdI32),
73+
SimdU64 => Mask64 (SimdI64),
74+
SimdUsize => MaskSize (SimdIsize),
8175

82-
SimdF32 => Mask32 (SimdMask32, SimdI32),
83-
SimdF64 => Mask64 (SimdMask64, SimdI64),
76+
SimdF32 => Mask32 (SimdI32),
77+
SimdF64 => Mask64 (SimdI64),
8478
}

crates/core_simd/src/lanes_at_most_32.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Implemented for bitmask sizes that are supported by the implementation.
1+
/// Implemented for vectors that are supported by the implementation.
22
pub trait LanesAtMost32 {}
33

44
macro_rules! impl_for {
@@ -28,5 +28,3 @@ impl_for! { SimdIsize }
2828

2929
impl_for! { SimdF32 }
3030
impl_for! { SimdF64 }
31-
32-
impl_for! { BitMask }

crates/core_simd/src/masks/bitmask.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ use crate::LanesAtMost32;
44
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Ord, Eq, Hash)]
55
#[repr(transparent)]
66
pub struct BitMask<const LANES: usize>(u64)
7-
where
8-
BitMask<LANES>: LanesAtMost32;
97

108
impl<const LANES: usize> BitMask<LANES>
119
where
1210
Self: LanesAtMost32,
1311
{
14-
/// Construct a mask by setting all lanes to the given value.
12+
#[inline]
1513
pub fn splat(value: bool) -> Self {
1614
if value {
1715
Self(u64::MAX >> (64 - LANES))
@@ -20,23 +18,13 @@ where
2018
}
2119
}
2220

23-
/// Tests the value of the specified lane.
24-
///
25-
/// # Panics
26-
/// Panics if `lane` is greater than or equal to the number of lanes in the vector.
2721
#[inline]
28-
pub fn test(&self, lane: usize) -> bool {
29-
assert!(lane < LANES, "lane index out of range");
22+
pub unsafe fn test_unchecked(&self, lane: usize) -> bool {
3023
(self.0 >> lane) & 0x1 > 0
3124
}
3225

33-
/// Sets the value of the specified lane.
34-
///
35-
/// # Panics
36-
/// Panics if `lane` is greater than or equal to the number of lanes in the vector.
3726
#[inline]
38-
pub fn set(&mut self, lane: usize, value: bool) {
39-
assert!(lane < LANES, "lane index out of range");
27+
pub unsafe fn set_unchecked(&mut self, lane: usize, value: bool) {
4028
self.0 ^= ((value ^ self.test(lane)) as u64) << lane
4129
}
4230
}

0 commit comments

Comments
 (0)