Skip to content

Commit 7c059d0

Browse files
authored
Rollup merge of rust-lang#92028 - petrochenkov:psimd, r=Mark-Simulacrum
Sync portable-simd to fix libcore build for AVX-512 enabled targets Fixes rust-lang#91484 (comment) cc `@workingjubilee`
2 parents 91d3b73 + 23c172f commit 7c059d0

File tree

4 files changed

+25
-62
lines changed

4 files changed

+25
-62
lines changed

library/portable-simd/crates/core_simd/src/masks/bitmask.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,14 @@ where
105105
#[must_use = "method returns a new vector and does not mutate the original value"]
106106
pub fn to_int(self) -> Simd<T, LANES> {
107107
unsafe {
108-
crate::intrinsics::simd_select_bitmask(
109-
self.0,
110-
Simd::splat(T::TRUE),
111-
Simd::splat(T::FALSE),
112-
)
108+
intrinsics::simd_select_bitmask(self.0, Simd::splat(T::TRUE), Simd::splat(T::FALSE))
113109
}
114110
}
115111

116112
#[inline]
117113
#[must_use = "method returns a new mask and does not mutate the original value"]
118114
pub unsafe fn from_int_unchecked(value: Simd<T, LANES>) -> Self {
119-
unsafe { Self(crate::intrinsics::simd_bitmask(value), PhantomData) }
115+
unsafe { Self(intrinsics::simd_bitmask(value), PhantomData) }
120116
}
121117

122118
#[cfg(feature = "generic_const_exprs")]

library/portable-simd/crates/core_simd/src/masks/full_masks.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ where
115115
pub fn to_bitmask(self) -> [u8; LaneCount::<LANES>::BITMASK_LEN] {
116116
unsafe {
117117
let mut bitmask: [u8; LaneCount::<LANES>::BITMASK_LEN] =
118-
crate::intrinsics::simd_bitmask(self.0);
118+
intrinsics::simd_bitmask(self.0);
119119

120120
// There is a bug where LLVM appears to implement this operation with the wrong
121121
// bit order.
@@ -144,7 +144,7 @@ where
144144
}
145145
}
146146

147-
Self::from_int_unchecked(crate::intrinsics::simd_select_bitmask(
147+
Self::from_int_unchecked(intrinsics::simd_select_bitmask(
148148
bitmask,
149149
Self::splat(true).to_int(),
150150
Self::splat(false).to_int(),

library/portable-simd/crates/core_simd/src/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub mod simd {
2727

2828
pub use crate::core_simd::lane_count::{LaneCount, SupportedLaneCount};
2929
pub use crate::core_simd::masks::*;
30-
pub use crate::core_simd::select::Select;
3130
pub use crate::core_simd::swizzle::*;
3231
pub use crate::core_simd::vector::*;
3332
}
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,6 @@
11
use crate::simd::intrinsics;
22
use crate::simd::{LaneCount, Mask, MaskElement, Simd, SimdElement, SupportedLaneCount};
33

4-
mod sealed {
5-
pub trait Sealed<Mask> {
6-
fn select(mask: Mask, true_values: Self, false_values: Self) -> Self;
7-
}
8-
}
9-
use sealed::Sealed;
10-
11-
/// Supporting trait for vector `select` function
12-
pub trait Select<Mask>: Sealed<Mask> {}
13-
14-
impl<T, const LANES: usize> Sealed<Mask<T::Mask, LANES>> for Simd<T, LANES>
15-
where
16-
T: SimdElement,
17-
LaneCount<LANES>: SupportedLaneCount,
18-
{
19-
#[inline]
20-
#[must_use = "method returns a new vector and does not mutate the original inputs"]
21-
fn select(mask: Mask<T::Mask, LANES>, true_values: Self, false_values: Self) -> Self {
22-
unsafe { intrinsics::simd_select(mask.to_int(), true_values, false_values) }
23-
}
24-
}
25-
26-
impl<T, const LANES: usize> Select<Mask<T::Mask, LANES>> for Simd<T, LANES>
27-
where
28-
T: SimdElement,
29-
LaneCount<LANES>: SupportedLaneCount,
30-
{
31-
}
32-
33-
impl<T, const LANES: usize> Sealed<Self> for Mask<T, LANES>
34-
where
35-
T: MaskElement,
36-
LaneCount<LANES>: SupportedLaneCount,
37-
{
38-
#[inline]
39-
#[must_use = "method returns a new vector and does not mutate the original inputs"]
40-
fn select(mask: Self, true_values: Self, false_values: Self) -> Self {
41-
mask & true_values | !mask & false_values
42-
}
43-
}
44-
45-
impl<T, const LANES: usize> Select<Self> for Mask<T, LANES>
46-
where
47-
T: MaskElement,
48-
LaneCount<LANES>: SupportedLaneCount,
49-
{
50-
}
51-
524
impl<T, const LANES: usize> Mask<T, LANES>
535
where
546
T: MaskElement,
@@ -69,21 +21,37 @@ where
6921
/// let c = mask.select(a, b);
7022
/// assert_eq!(c.to_array(), [0, 5, 6, 3]);
7123
/// ```
24+
#[inline]
25+
#[must_use = "method returns a new vector and does not mutate the original inputs"]
26+
pub fn select<U>(
27+
self,
28+
true_values: Simd<U, LANES>,
29+
false_values: Simd<U, LANES>,
30+
) -> Simd<U, LANES>
31+
where
32+
U: SimdElement<Mask = T>,
33+
{
34+
unsafe { intrinsics::simd_select(self.to_int(), true_values, false_values) }
35+
}
36+
37+
/// Choose lanes from two masks.
38+
///
39+
/// For each lane in the mask, choose the corresponding lane from `true_values` if
40+
/// that lane mask is true, and `false_values` if that lane mask is false.
7241
///
73-
/// `select` can also be used on masks:
7442
/// ```
7543
/// # #![feature(portable_simd)]
7644
/// # #[cfg(feature = "std")] use core_simd::Mask;
7745
/// # #[cfg(not(feature = "std"))] use core::simd::Mask;
7846
/// let a = Mask::<i32, 4>::from_array([true, true, false, false]);
7947
/// let b = Mask::<i32, 4>::from_array([false, false, true, true]);
8048
/// let mask = Mask::<i32, 4>::from_array([true, false, false, true]);
81-
/// let c = mask.select(a, b);
49+
/// let c = mask.select_mask(a, b);
8250
/// assert_eq!(c.to_array(), [true, false, true, false]);
8351
/// ```
8452
#[inline]
85-
#[must_use = "method returns a new vector and does not mutate the original inputs"]
86-
pub fn select<S: Select<Self>>(self, true_values: S, false_values: S) -> S {
87-
S::select(self, true_values, false_values)
53+
#[must_use = "method returns a new mask and does not mutate the original inputs"]
54+
pub fn select_mask(self, true_values: Self, false_values: Self) -> Self {
55+
self & true_values | !self & false_values
8856
}
8957
}

0 commit comments

Comments
 (0)