Skip to content

Commit 2f38f70

Browse files
Merge pull request #309 from rust-lang/mask-inline
Mark more mask functions inline
2 parents 2c5ebfb + 4491309 commit 2f38f70

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

crates/core_simd/src/masks.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ pub unsafe trait MaskElement: SimdElement + Sealed {}
5555
macro_rules! impl_element {
5656
{ $ty:ty } => {
5757
impl Sealed for $ty {
58+
#[inline]
5859
fn valid<const LANES: usize>(value: Simd<Self, LANES>) -> bool
5960
where
6061
LaneCount<LANES>: SupportedLaneCount,
6162
{
6263
(value.simd_eq(Simd::splat(0 as _)) | value.simd_eq(Simd::splat(-1 as _))).all()
6364
}
6465

66+
#[inline]
6567
fn eq(self, other: Self) -> bool { self == other }
6668

6769
const TRUE: Self = -1;
@@ -104,6 +106,7 @@ where
104106
T: MaskElement,
105107
LaneCount<LANES>: SupportedLaneCount,
106108
{
109+
#[inline]
107110
fn clone(&self) -> Self {
108111
*self
109112
}
@@ -115,11 +118,13 @@ where
115118
LaneCount<LANES>: SupportedLaneCount,
116119
{
117120
/// Construct a mask by setting all lanes to the given value.
121+
#[inline]
118122
pub fn splat(value: bool) -> Self {
119123
Self(mask_impl::Mask::splat(value))
120124
}
121125

122126
/// Converts an array of bools to a SIMD mask.
127+
#[inline]
123128
pub fn from_array(array: [bool; LANES]) -> Self {
124129
// SAFETY: Rust's bool has a layout of 1 byte (u8) with a value of
125130
// true: 0b_0000_0001
@@ -136,6 +141,7 @@ where
136141
}
137142

138143
/// Converts a SIMD mask to an array of bools.
144+
#[inline]
139145
pub fn to_array(self) -> [bool; LANES] {
140146
// This follows mostly the same logic as from_array.
141147
// SAFETY: Rust's bool has a layout of 1 byte (u8) with a value of
@@ -263,6 +269,7 @@ where
263269
T: MaskElement,
264270
LaneCount<LANES>: SupportedLaneCount,
265271
{
272+
#[inline]
266273
fn from(array: [bool; LANES]) -> Self {
267274
Self::from_array(array)
268275
}
@@ -273,6 +280,7 @@ where
273280
T: MaskElement,
274281
LaneCount<LANES>: SupportedLaneCount,
275282
{
283+
#[inline]
276284
fn from(vector: Mask<T, LANES>) -> Self {
277285
vector.to_array()
278286
}
@@ -655,6 +663,7 @@ macro_rules! impl_from {
655663
where
656664
LaneCount<LANES>: SupportedLaneCount,
657665
{
666+
#[inline]
658667
fn from(value: Mask<$from, LANES>) -> Self {
659668
value.cast()
660669
}

crates/core_simd/src/masks/bitmask.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ where
2626
T: MaskElement,
2727
LaneCount<LANES>: SupportedLaneCount,
2828
{
29+
#[inline]
2930
fn clone(&self) -> Self {
3031
*self
3132
}
@@ -36,6 +37,7 @@ where
3637
T: MaskElement,
3738
LaneCount<LANES>: SupportedLaneCount,
3839
{
40+
#[inline]
3941
fn eq(&self, other: &Self) -> bool {
4042
self.0.as_ref() == other.0.as_ref()
4143
}
@@ -46,6 +48,7 @@ where
4648
T: MaskElement,
4749
LaneCount<LANES>: SupportedLaneCount,
4850
{
51+
#[inline]
4952
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
5053
self.0.as_ref().partial_cmp(other.0.as_ref())
5154
}
@@ -63,6 +66,7 @@ where
6366
T: MaskElement,
6467
LaneCount<LANES>: SupportedLaneCount,
6568
{
69+
#[inline]
6670
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
6771
self.0.as_ref().cmp(other.0.as_ref())
6872
}

crates/core_simd/src/masks/full_masks.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ where
3737
T: MaskElement + PartialEq,
3838
LaneCount<LANES>: SupportedLaneCount,
3939
{
40+
#[inline]
4041
fn eq(&self, other: &Self) -> bool {
4142
self.0.eq(&other.0)
4243
}
@@ -47,6 +48,7 @@ where
4748
T: MaskElement + PartialOrd,
4849
LaneCount<LANES>: SupportedLaneCount,
4950
{
51+
#[inline]
5052
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
5153
self.0.partial_cmp(&other.0)
5254
}
@@ -64,6 +66,7 @@ where
6466
T: MaskElement + Ord,
6567
LaneCount<LANES>: SupportedLaneCount,
6668
{
69+
#[inline]
6770
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
6871
self.0.cmp(&other.0)
6972
}
@@ -262,6 +265,7 @@ where
262265
T: MaskElement,
263266
LaneCount<LANES>: SupportedLaneCount,
264267
{
268+
#[inline]
265269
fn from(value: Mask<T, LANES>) -> Self {
266270
value.0
267271
}

crates/core_simd/src/masks/to_bitmask.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ macro_rules! impl_integer_intrinsic {
4848
impl<T: MaskElement> ToBitMask for Mask<T, $lanes> {
4949
type BitMask = $int;
5050

51+
#[inline]
5152
fn to_bitmask(self) -> $int {
5253
self.0.to_bitmask_integer()
5354
}
5455

56+
#[inline]
5557
fn from_bitmask(bitmask: $int) -> Self {
5658
Self(mask_impl::Mask::from_bitmask_integer(bitmask))
5759
}
@@ -83,10 +85,12 @@ where
8385
{
8486
const BYTES: usize = bitmask_len(LANES);
8587

88+
#[inline]
8689
fn to_bitmask_array(self) -> [u8; Self::BYTES] {
8790
self.0.to_bitmask_array()
8891
}
8992

93+
#[inline]
9094
fn from_bitmask_array(bitmask: [u8; Self::BYTES]) -> Self {
9195
Mask(mask_impl::Mask::from_bitmask_array(bitmask))
9296
}

0 commit comments

Comments
 (0)