Skip to content

Commit 83c6d2c

Browse files
folkertdevAmanieu
authored andcommitted
add vec_sel
1 parent a855cb0 commit 83c6d2c

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

crates/core_arch/src/s390x/macros.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ macro_rules! t_b {
396396
(vector_bool_int) => {
397397
vector_bool_int
398398
};
399+
(vector_bool_long_long) => {
400+
vector_bool_long_long
401+
};
399402
(vector_signed_char) => {
400403
vector_bool_char
401404
};

crates/core_arch/src/s390x/vector.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,6 +2667,58 @@ mod sealed {
26672667
vgef vector_float
26682668
vgeg vector_double
26692669
}
2670+
2671+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
2672+
pub trait VectorSel<Mask>: Sized {
2673+
unsafe fn vec_sel(self, b: Self, c: Mask) -> Self;
2674+
}
2675+
2676+
macro_rules! impl_vec_sel {
2677+
($($ty:ident)*) => {
2678+
$(
2679+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
2680+
impl VectorSel<t_u!($ty)> for $ty {
2681+
#[inline]
2682+
#[target_feature(enable = "vector")]
2683+
unsafe fn vec_sel(self, b: Self, c: t_u!($ty)) -> Self {
2684+
let b = simd_and(b, transmute(c));
2685+
let a = simd_and(self, simd_xor(transmute(c), transmute(vector_signed_char([!0; 16]))));
2686+
simd_or(a, b)
2687+
}
2688+
}
2689+
2690+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
2691+
impl VectorSel<t_b!($ty)> for $ty {
2692+
#[inline]
2693+
#[target_feature(enable = "vector")]
2694+
unsafe fn vec_sel(self, b: Self, c: t_b!($ty)) -> Self {
2695+
// defer to the implementation with an unsigned mask
2696+
self.vec_sel(b, transmute::<_, t_u!($ty)>(c))
2697+
}
2698+
}
2699+
)*
2700+
}
2701+
}
2702+
2703+
impl_vec_sel! {
2704+
vector_signed_char
2705+
vector_signed_short
2706+
vector_signed_int
2707+
vector_signed_long_long
2708+
2709+
vector_unsigned_char
2710+
vector_unsigned_short
2711+
vector_unsigned_int
2712+
vector_unsigned_long_long
2713+
2714+
vector_bool_char
2715+
vector_bool_short
2716+
vector_bool_int
2717+
vector_bool_long_long
2718+
2719+
vector_float
2720+
vector_double
2721+
}
26702722
}
26712723

26722724
/// Load Count to Block Boundary
@@ -3837,6 +3889,14 @@ pub unsafe fn vec_gather_element<T: sealed::VectorGatherElement, const D: u32>(
38373889
a.vec_gather_element::<D>(b, c)
38383890
}
38393891

3892+
/// Vector Select
3893+
#[inline]
3894+
#[target_feature(enable = "vector")]
3895+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
3896+
pub unsafe fn vec_sel<T: sealed::VectorSel<U>, U>(a: T, b: T, c: U) -> T {
3897+
a.vec_sel(b, c)
3898+
}
3899+
38403900
#[cfg(test)]
38413901
mod tests {
38423902
use super::*;
@@ -4785,6 +4845,20 @@ mod tests {
47854845
assert_eq!(d.as_array(), &[0xF00, 0]);
47864846
}
47874847

4848+
#[simd_test(enable = "vector")]
4849+
fn test_vec_sel() {
4850+
let a = vector_signed_int([1, 2, 3, 4]);
4851+
let b = vector_signed_int([5, 6, 7, 8]);
4852+
4853+
let e = vector_unsigned_int([9, 10, 11, 12]);
4854+
let f = vector_unsigned_int([9, 9, 11, 11]);
4855+
4856+
let c: vector_bool_int = unsafe { simd_eq(e, f) };
4857+
assert_eq!(c.as_array(), &[!0, 0, !0, 0]);
4858+
let d: vector_signed_int = unsafe { vec_sel(a, b, c) };
4859+
assert_eq!(d.as_array(), &[5, 2, 7, 4]);
4860+
}
4861+
47884862
#[simd_test(enable = "vector")]
47894863
fn test_vec_gather_element() {
47904864
let a1: [u32; 10] = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19];

0 commit comments

Comments
 (0)