Skip to content

Commit b477f18

Browse files
folkertdevAmanieu
authored andcommitted
add vec_cp_until_zero and vec_cp_until_zero_cc
1 parent 2a834e7 commit b477f18

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

crates/core_arch/src/s390x/vector.rs

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ unsafe extern "unadjusted" {
221221
#[link_name = "llvm.s390.vstrszb"] fn vstrszb(a: vector_unsigned_char, b: vector_unsigned_char, c: vector_unsigned_char) -> PackedTuple<vector_unsigned_char, i32>;
222222
#[link_name = "llvm.s390.vstrszh"] fn vstrszh(a: vector_unsigned_short, b: vector_unsigned_short, c: vector_unsigned_char) -> PackedTuple<vector_unsigned_char, i32>;
223223
#[link_name = "llvm.s390.vstrszf"] fn vstrszf(a: vector_unsigned_int, b: vector_unsigned_int, c: vector_unsigned_char) -> PackedTuple<vector_unsigned_char, i32>;
224+
225+
#[link_name = "llvm.s390.vistrb"] fn vistrb(a: vector_unsigned_char) -> vector_unsigned_char;
226+
#[link_name = "llvm.s390.vistrh"] fn vistrh(a: vector_unsigned_short) -> vector_unsigned_short;
227+
#[link_name = "llvm.s390.vistrf"] fn vistrf(a: vector_unsigned_int) -> vector_unsigned_int;
228+
229+
#[link_name = "llvm.s390.vistrbs"] fn vistrbs(a: vector_unsigned_char) -> PackedTuple<vector_unsigned_char, i32>;
230+
#[link_name = "llvm.s390.vistrhs"] fn vistrhs(a: vector_unsigned_short) -> PackedTuple<vector_unsigned_short, i32>;
231+
#[link_name = "llvm.s390.vistrfs"] fn vistrfs(a: vector_unsigned_int) -> PackedTuple<vector_unsigned_int, i32>;
224232
}
225233

226234
impl_from! { i8x16, u8x16, i16x8, u16x8, i32x4, u32x4, i64x2, u64x2, f32x4, f64x2 }
@@ -3098,6 +3106,68 @@ mod sealed {
30983106

30993107
impl_vec_trait! { [VectorUnsigned vec_unsigned] vclgsb (vector_float) -> vector_unsigned_int }
31003108
impl_vec_trait! { [VectorUnsigned vec_unsigned] vclgdb (vector_double) -> vector_unsigned_long_long }
3109+
3110+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
3111+
pub trait VectorCopyUntilZero {
3112+
unsafe fn vec_cp_until_zero(self) -> Self;
3113+
}
3114+
3115+
test_impl! { vec_vistrb (a: vector_unsigned_char) -> vector_unsigned_char [vistrb, vistrb] }
3116+
test_impl! { vec_vistrh (a: vector_unsigned_short) -> vector_unsigned_short [vistrh, vistrh] }
3117+
test_impl! { vec_vistrf (a: vector_unsigned_int) -> vector_unsigned_int [vistrf, vistrf] }
3118+
3119+
impl_vec_trait! { [VectorCopyUntilZero vec_cp_until_zero]+ vec_vistrb (vector_signed_char) }
3120+
impl_vec_trait! { [VectorCopyUntilZero vec_cp_until_zero]+ vec_vistrb (vector_bool_char) }
3121+
impl_vec_trait! { [VectorCopyUntilZero vec_cp_until_zero]+ vec_vistrb (vector_unsigned_char) }
3122+
3123+
impl_vec_trait! { [VectorCopyUntilZero vec_cp_until_zero]+ vec_vistrh (vector_signed_short) }
3124+
impl_vec_trait! { [VectorCopyUntilZero vec_cp_until_zero]+ vec_vistrh (vector_bool_short) }
3125+
impl_vec_trait! { [VectorCopyUntilZero vec_cp_until_zero]+ vec_vistrh (vector_unsigned_short) }
3126+
3127+
impl_vec_trait! { [VectorCopyUntilZero vec_cp_until_zero]+ vec_vistrf (vector_signed_int) }
3128+
impl_vec_trait! { [VectorCopyUntilZero vec_cp_until_zero]+ vec_vistrf (vector_bool_int) }
3129+
impl_vec_trait! { [VectorCopyUntilZero vec_cp_until_zero]+ vec_vistrf (vector_unsigned_int) }
3130+
3131+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
3132+
pub trait VectorCopyUntilZeroCC {
3133+
unsafe fn vec_cp_until_zero_cc(self, cc: *mut i32) -> Self;
3134+
}
3135+
3136+
test_impl! { vec_vistrbs (a: vector_unsigned_char) -> PackedTuple<vector_unsigned_char, i32> [vistrbs, vistrbs] }
3137+
test_impl! { vec_vistrhs (a: vector_unsigned_short) -> PackedTuple<vector_unsigned_short, i32> [vistrhs, vistrhs] }
3138+
test_impl! { vec_vistrfs (a: vector_unsigned_int) -> PackedTuple<vector_unsigned_int, i32> [vistrfs, vistrfs] }
3139+
3140+
macro_rules! impl_vec_copy_until_zero_cc {
3141+
($($intr:ident $ty:ident)*) => {
3142+
$(
3143+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
3144+
impl VectorCopyUntilZeroCC for $ty {
3145+
#[inline]
3146+
#[target_feature(enable = "vector")]
3147+
unsafe fn vec_cp_until_zero_cc(self, cc: *mut i32) -> Self {
3148+
let PackedTuple { x,y } = $intr(transmute(self));
3149+
cc.write(y);
3150+
transmute(x)
3151+
}
3152+
}
3153+
3154+
)*
3155+
}
3156+
}
3157+
3158+
impl_vec_copy_until_zero_cc! {
3159+
vec_vistrbs vector_signed_char
3160+
vec_vistrbs vector_bool_char
3161+
vec_vistrbs vector_unsigned_char
3162+
3163+
vec_vistrhs vector_signed_short
3164+
vec_vistrhs vector_bool_short
3165+
vec_vistrhs vector_unsigned_short
3166+
3167+
vec_vistrfs vector_signed_int
3168+
vec_vistrfs vector_bool_int
3169+
vec_vistrfs vector_unsigned_int
3170+
}
31013171
}
31023172

31033173
/// Load Count to Block Boundary
@@ -4433,6 +4503,22 @@ pub unsafe fn vec_unsigned<T: sealed::VectorUnsigned>(a: T) -> T::Result {
44334503
a.vec_unsigned()
44344504
}
44354505

4506+
/// Vector Copy Until Zero
4507+
#[inline]
4508+
#[target_feature(enable = "vector")]
4509+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
4510+
pub unsafe fn vec_cp_until_zero<T: sealed::VectorCopyUntilZero>(a: T) -> T {
4511+
a.vec_cp_until_zero()
4512+
}
4513+
4514+
/// Vector Copy Until Zero
4515+
#[inline]
4516+
#[target_feature(enable = "vector")]
4517+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
4518+
pub unsafe fn vec_cp_until_zero_cc<T: sealed::VectorCopyUntilZeroCC>(a: T, cc: *mut i32) -> T {
4519+
a.vec_cp_until_zero_cc(cc)
4520+
}
4521+
44364522
#[cfg(test)]
44374523
mod tests {
44384524
use super::*;
@@ -5615,4 +5701,33 @@ mod tests {
56155701
assert_eq!(vec_unsigned(v).as_array(), &[2, 3]);
56165702
}
56175703
}
5704+
5705+
#[simd_test(enable = "vector")]
5706+
fn test_vec_cp_until_zero() {
5707+
unsafe {
5708+
let v = vector_signed_int([1, 2, 3, 4]);
5709+
let d = vec_cp_until_zero(v);
5710+
assert_eq!(d.as_array(), &[1, 2, 3, 4]);
5711+
5712+
let v = vector_signed_int([1, 2, 0, 4]);
5713+
let d = vec_cp_until_zero(v);
5714+
assert_eq!(d.as_array(), &[1, 2, 0, 0]);
5715+
}
5716+
}
5717+
5718+
#[simd_test(enable = "vector")]
5719+
fn test_vec_cp_until_zero_cc() {
5720+
let mut cc = 0;
5721+
unsafe {
5722+
let v = vector_signed_int([1, 2, 3, 4]);
5723+
let d = vec_cp_until_zero_cc(v, &mut cc);
5724+
assert_eq!(d.as_array(), &[1, 2, 3, 4]);
5725+
assert_eq!(cc, 3);
5726+
5727+
let v = vector_signed_int([1, 2, 0, 4]);
5728+
let d = vec_cp_until_zero_cc(v, &mut cc);
5729+
assert_eq!(d.as_array(), &[1, 2, 0, 0]);
5730+
assert_eq!(cc, 0);
5731+
}
5732+
}
56185733
}

0 commit comments

Comments
 (0)