Skip to content

Commit 5f631eb

Browse files
folkertdevAmanieu
authored andcommitted
add vec_cmprg
1 parent d3f2dac commit 5f631eb

File tree

1 file changed

+97
-8
lines changed

1 file changed

+97
-8
lines changed

crates/core_arch/src/s390x/vector.rs

Lines changed: 97 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ unsafe extern "unadjusted" {
235235
#[link_name = "llvm.s390.vistrfs"] fn vistrfs(a: vector_unsigned_int) -> PackedTuple<vector_unsigned_int, i32>;
236236

237237
#[link_name = "llvm.s390.vmslg"] fn vmslg(a: vector_unsigned_long_long, b: vector_unsigned_long_long, c: u128, d: u32) -> u128;
238+
239+
#[link_name = "llvm.s390.vstrcb"] fn vstrcb(a: vector_unsigned_char, b: vector_unsigned_char, c: vector_unsigned_char, d: u32) -> vector_bool_char;
240+
#[link_name = "llvm.s390.vstrch"] fn vstrch(a: vector_unsigned_short, b: vector_unsigned_short, c: vector_unsigned_short, d: u32) -> vector_bool_short;
241+
#[link_name = "llvm.s390.vstrcf"] fn vstrcf(a: vector_unsigned_int, b: vector_unsigned_int, c: vector_unsigned_int, d: u32) -> vector_bool_int;
242+
243+
#[link_name = "llvm.s390.vstrcbs"] fn vstrcbs(a: vector_unsigned_char, b: vector_unsigned_char, c: vector_unsigned_char, d: u32) -> PackedTuple<vector_bool_char, i32>;
244+
#[link_name = "llvm.s390.vstrchs"] fn vstrchs(a: vector_unsigned_short, b: vector_unsigned_short, c: vector_unsigned_short, d: u32) -> PackedTuple<vector_bool_short, i32>;
245+
#[link_name = "llvm.s390.vstrcfs"] fn vstrcfs(a: vector_unsigned_int, b: vector_unsigned_int, c: vector_unsigned_int, d: u32) -> PackedTuple<vector_bool_int, i32>;
238246
}
239247

240248
impl_from! { i8x16, u8x16, i16x8, u16x8, i32x4, u32x4, i64x2, u64x2, f32x4, f64x2 }
@@ -365,6 +373,13 @@ const fn validate_block_boundary(block_boundary: u16) -> u32 {
365373
block_boundary as u32 >> 7
366374
}
367375

376+
enum FindImm {
377+
Eq = 4,
378+
Ne = 12,
379+
EqIdx = 0,
380+
NeIdx = 8,
381+
}
382+
368383
#[macro_use]
369384
mod sealed {
370385
use super::*;
@@ -1922,13 +1937,6 @@ mod sealed {
19221937
};
19231938
}
19241939

1925-
enum FindImm {
1926-
Eq = 4,
1927-
Ne = 12,
1928-
EqIdx = 0,
1929-
NeIdx = 8,
1930-
}
1931-
19321940
#[unstable(feature = "stdarch_s390x", issue = "135681")]
19331941
pub trait VectorFindAnyEq<Other> {
19341942
type Result;
@@ -3254,6 +3262,56 @@ mod sealed {
32543262
vector_float
32553263
vector_double
32563264
}
3265+
3266+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
3267+
pub trait VectorCompareRange: Sized {
3268+
type Result;
3269+
3270+
unsafe fn vstrc<const IMM: u32>(self, b: Self, c: Self) -> Self::Result;
3271+
unsafe fn vstrcs<const IMM: u32>(self, b: Self, c: Self) -> (Self::Result, i32);
3272+
}
3273+
3274+
macro_rules! impl_compare_range {
3275+
($($ty:ident $vstrc:ident $vstrcs:ident)*) => {
3276+
$(
3277+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
3278+
impl VectorCompareRange for $ty {
3279+
type Result = t_b!($ty);
3280+
3281+
#[inline]
3282+
#[target_feature(enable = "vector")]
3283+
unsafe fn vstrc<const IMM: u32>(self, b: Self, c: Self) -> Self::Result {
3284+
const {
3285+
if !matches!(IMM, 0 | 4 | 8 | 12) {
3286+
panic!("IMM needs to be one of 0, 4, 8, 12");
3287+
}
3288+
};
3289+
3290+
$vstrc(self, b, c, IMM)
3291+
}
3292+
3293+
#[inline]
3294+
#[target_feature(enable = "vector")]
3295+
unsafe fn vstrcs<const IMM: u32>(self, b: Self, c: Self) -> (Self::Result, i32) {
3296+
const {
3297+
if !matches!(IMM, 0 | 4 | 8 | 12) {
3298+
panic!("IMM needs to be one of 0, 4, 8, 12");
3299+
}
3300+
};
3301+
3302+
let PackedTuple { x, y } = $vstrcs(self, b, c, IMM);
3303+
(x,y)
3304+
}
3305+
}
3306+
)*
3307+
}
3308+
}
3309+
3310+
impl_compare_range! {
3311+
vector_unsigned_char vstrcb vstrcbs
3312+
vector_unsigned_short vstrch vstrchs
3313+
vector_unsigned_int vstrcf vstrcfs
3314+
}
32573315
}
32583316

32593317
/// Load Count to Block Boundary
@@ -4662,6 +4720,13 @@ pub unsafe fn vec_srdb<T: sealed::VectorSrdb, const C: u32>(a: T, b: T) -> T {
46624720
a.vec_srdb::<C>(b)
46634721
}
46644722

4723+
#[inline]
4724+
#[target_feature(enable = "vector")]
4725+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
4726+
pub unsafe fn vec_cmprg<T: sealed::VectorCompareRange>(a: T, b: T, c: T) -> T::Result {
4727+
a.vstrc::<{ FindImm::Eq as u32 }>(b, c)
4728+
}
4729+
46654730
#[cfg(test)]
46664731
mod tests {
46674732
use super::*;
@@ -5936,8 +6001,32 @@ mod tests {
59366001

59376002
unsafe {
59386003
let d = vec_srdb::<_, 4>(a, b);
5939-
println!("{:x?}", &d);
59406004
assert_eq!(d.as_array(), &[0xABBBBBBBBBBBBBBB, 0xBBBBBBBBBBBBBBBB]);
59416005
}
59426006
}
6007+
6008+
#[simd_test(enable = "vector")]
6009+
fn test_vec_cmprg() {
6010+
const GT: u32 = 0x20000000;
6011+
const LT: u32 = 0x40000000;
6012+
const EQ: u32 = 0x80000000;
6013+
6014+
let a = vector_unsigned_int([11, 22, 33, 44]);
6015+
let b = vector_unsigned_int([10, 20, 30, 40]);
6016+
6017+
let c = vector_unsigned_int([GT, LT, GT, LT]);
6018+
let d = unsafe { vec_cmprg(a, b, c) };
6019+
assert_eq!(d.as_array(), &[!0, 0, !0, 0]);
6020+
6021+
let c = vector_unsigned_int([GT, LT, 0, 0]);
6022+
let d = unsafe { vec_cmprg(a, b, c) };
6023+
assert_eq!(d.as_array(), &[!0, 0, 0, 0]);
6024+
6025+
let a = vector_unsigned_int([11, 22, 33, 30]);
6026+
let b = vector_unsigned_int([10, 20, 30, 30]);
6027+
6028+
let c = vector_unsigned_int([GT, LT, EQ, EQ]);
6029+
let d = unsafe { vec_cmprg(a, b, c) };
6030+
assert_eq!(d.as_array(), &[!0, 0, 0, !0]);
6031+
}
59436032
}

0 commit comments

Comments
 (0)