Skip to content

Commit 7a05a96

Browse files
folkertdevAmanieu
authored andcommitted
add vec_rl_mask
1 parent 8d4a7cf commit 7a05a96

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

crates/core_arch/src/s390x/macros.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,41 @@ macro_rules! s_t_l {
213213
};
214214
}
215215

216+
macro_rules! l_t_t {
217+
(vector_signed_long_long) => {
218+
i64
219+
};
220+
(vector_signed_int) => {
221+
i32
222+
};
223+
(vector_signed_short) => {
224+
i16
225+
};
226+
(vector_signed_char) => {
227+
i8
228+
};
229+
230+
(vector_unsigned_long_long ) => {
231+
u64
232+
};
233+
(vector_unsigned_int ) => {
234+
u32
235+
};
236+
(vector_unsigned_short ) => {
237+
u16
238+
};
239+
(vector_unsigned_char ) => {
240+
u8
241+
};
242+
243+
(vector_float) => {
244+
f32
245+
};
246+
(vector_double) => {
247+
f64
248+
};
249+
}
250+
216251
macro_rules! t_t_l {
217252
(i64) => {
218253
vector_signed_long_long
@@ -401,6 +436,7 @@ macro_rules! impl_neg {
401436
pub(crate) use impl_from;
402437
pub(crate) use impl_neg;
403438
pub(crate) use impl_vec_trait;
439+
pub(crate) use l_t_t;
404440
pub(crate) use s_t_l;
405441
pub(crate) use t_b;
406442
pub(crate) use t_t_l;

crates/core_arch/src/s390x/vector.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ unsafe extern "unadjusted" {
9595
#[link_name = "llvm.fshl.v8i16"] fn fshlh(a: vector_unsigned_short, b: vector_unsigned_short, c: vector_unsigned_short) -> vector_unsigned_short;
9696
#[link_name = "llvm.fshl.v4i32"] fn fshlf(a: vector_unsigned_int, b: vector_unsigned_int, c: vector_unsigned_int) -> vector_unsigned_int;
9797
#[link_name = "llvm.fshl.v2i64"] fn fshlg(a: vector_unsigned_long_long, b: vector_unsigned_long_long, c: vector_unsigned_long_long) -> vector_unsigned_long_long;
98+
99+
#[link_name = "llvm.s390.verimb"] fn verimb(a: vector_signed_char, b: vector_signed_char, c: vector_signed_char, d: i32) -> vector_signed_char;
100+
#[link_name = "llvm.s390.verimh"] fn verimh(a: vector_signed_short, b: vector_signed_short, c: vector_signed_short, d: i32) -> vector_signed_short;
101+
#[link_name = "llvm.s390.verimf"] fn verimf(a: vector_signed_int, b: vector_signed_int, c: vector_signed_int, d: i32) -> vector_signed_int;
102+
#[link_name = "llvm.s390.verimg"] fn verimg(a: vector_signed_long_long, b: vector_signed_long_long, c: vector_signed_long_long, d: i32) -> vector_signed_long_long;
98103
}
99104

100105
impl_from! { i8x16, u8x16, i16x8, u16x8, i32x4, u32x4, i64x2, u64x2, f32x4, f64x2 }
@@ -948,6 +953,50 @@ mod sealed {
948953
vector_signed_int, verllvf_imm,
949954
vector_signed_long_long, verllvg_imm
950955
}
956+
957+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
958+
pub trait VectorRlMask<Other> {
959+
unsafe fn vec_rl_mask<const IMM8: u8>(self, other: Other) -> Self;
960+
}
961+
962+
macro_rules! impl_rl_mask {
963+
($($ty:ident, $intr:ident, $fun:ident),*) => {
964+
$(
965+
#[inline]
966+
#[target_feature(enable = "vector")]
967+
#[cfg_attr(test, assert_instr($intr, IMM8 = 6))]
968+
unsafe fn $fun<const IMM8: u8>(a: $ty, b: t_u!($ty)) -> $ty {
969+
// mod by the number of bits in a's element type to prevent UB
970+
$intr(a, a, transmute(b), const { (IMM8 % <l_t_t!($ty)>::BITS as u8) as i32 })
971+
}
972+
973+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
974+
impl VectorRlMask<t_u!($ty)> for $ty {
975+
#[inline]
976+
#[target_feature(enable = "vector")]
977+
unsafe fn vec_rl_mask<const IMM8: u8>(self, other: t_u!($ty)) -> Self {
978+
$fun::<IMM8>(self, other)
979+
}
980+
}
981+
982+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
983+
impl VectorRlMask<t_u!($ty)> for t_u!($ty) {
984+
#[inline]
985+
#[target_feature(enable = "vector")]
986+
unsafe fn vec_rl_mask<const IMM8: u8>(self, other: t_u!($ty)) -> Self {
987+
transmute($fun::<IMM8>(transmute(self), transmute(other)))
988+
}
989+
}
990+
)*
991+
}
992+
}
993+
994+
impl_rl_mask! {
995+
vector_signed_char, verimb, test_verimb,
996+
vector_signed_short, verimh, test_verimh,
997+
vector_signed_int, verimf, test_verimf,
998+
vector_signed_long_long, verimg, test_verimg
999+
}
9511000
}
9521001

9531002
/// Vector element-wise addition.

0 commit comments

Comments
 (0)