Skip to content

Commit 9ddd701

Browse files
folkertdevAmanieu
authored andcommitted
add vec_test_mask
1 parent 32d5a80 commit 9ddd701

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

crates/core_arch/src/s390x/vector.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ unsafe extern "unadjusted" {
211211

212212
#[link_name = "llvm.s390.vftcisb"] fn vftcisb(a: vector_float, b: u32) -> PackedTuple<vector_bool_int, i32>;
213213
#[link_name = "llvm.s390.vftcidb"] fn vftcidb(a: vector_double, b: u32) -> PackedTuple<vector_bool_long_long, i32>;
214+
215+
#[link_name = "llvm.s390.vtm"] fn vtm(a: i8x16, b: i8x16) -> i32;
214216
}
215217

216218
impl_from! { i8x16, u8x16, i16x8, u16x8, i32x4, u32x4, i64x2, u64x2, f32x4, f64x2 }
@@ -2818,6 +2820,44 @@ mod sealed {
28182820
x
28192821
}
28202822
}
2823+
2824+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
2825+
pub trait VectorTestMask {
2826+
type Mask;
2827+
unsafe fn vec_test_mask(self, other: Self::Mask) -> i32;
2828+
}
2829+
2830+
macro_rules! impl_vec_test_mask {
2831+
($($instr:ident $ty:ident)*) => {
2832+
$(
2833+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
2834+
impl VectorTestMask for $ty {
2835+
type Mask = t_u!($ty);
2836+
2837+
#[inline]
2838+
#[target_feature(enable = "vector")]
2839+
unsafe fn vec_test_mask(self, other: Self::Mask) -> i32 {
2840+
vtm(transmute(self), transmute(other))
2841+
}
2842+
}
2843+
)*
2844+
}
2845+
}
2846+
2847+
impl_vec_test_mask! {
2848+
vector_signed_char
2849+
vector_signed_short
2850+
vector_signed_int
2851+
vector_signed_long_long
2852+
2853+
vector_unsigned_char
2854+
vector_unsigned_short
2855+
vector_unsigned_int
2856+
vector_unsigned_long_long
2857+
2858+
vector_float
2859+
vector_double
2860+
}
28212861
}
28222862

28232863
/// Load Count to Block Boundary
@@ -4051,6 +4091,16 @@ pub unsafe fn vec_fp_test_data_class<T: sealed::VectorFpTestDataClass, const CLA
40514091
a.vec_fp_test_data_class::<CLASS>(c)
40524092
}
40534093

4094+
/// Vector Test under Mask
4095+
#[inline]
4096+
#[target_feature(enable = "vector")]
4097+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
4098+
pub unsafe fn vec_test_mask<T: sealed::VectorTestMask>(a: T, b: T::Mask) -> i32 {
4099+
// I can't find much information about this, but this might just be a check for whether the
4100+
// bitwise and of a and b is non-zero?
4101+
a.vec_test_mask(b)
4102+
}
4103+
40544104
#[cfg(test)]
40554105
mod tests {
40564106
use super::*;
@@ -5071,4 +5121,25 @@ mod tests {
50715121
assert_eq!(d.as_array(), &[!0, !0]);
50725122
}
50735123
}
5124+
5125+
#[simd_test(enable = "vector")]
5126+
fn test_vec_test_mask() {
5127+
unsafe {
5128+
let v = vector_unsigned_long_long([0xFF00FF00FF00FF00; 2]);
5129+
let m = vector_unsigned_long_long([0x0000FF000000FF00; 2]);
5130+
assert_eq!(vec_test_mask(v, m), 3);
5131+
5132+
let v = vector_unsigned_long_long([u64::MAX; 2]);
5133+
let m = vector_unsigned_long_long([0; 2]);
5134+
assert_eq!(vec_test_mask(v, m), 0);
5135+
5136+
let v = vector_unsigned_long_long([0; 2]);
5137+
let m = vector_unsigned_long_long([u64::MAX; 2]);
5138+
assert_eq!(vec_test_mask(v, m), 0);
5139+
5140+
let v = vector_unsigned_long_long([0xAAAAAAAAAAAAAAAA; 2]);
5141+
let m = vector_unsigned_long_long([0xAAAAAAAAAAAAAAAA; 2]);
5142+
assert_eq!(vec_test_mask(v, m), 3);
5143+
}
5144+
}
50745145
}

0 commit comments

Comments
 (0)