Skip to content

Commit c383877

Browse files
folkertdevAmanieu
authored andcommitted
add vec_search_string_cc and vec_search_string_until_zero_cc
1 parent 9ddd701 commit c383877

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

crates/core_arch/src/s390x/vector.rs

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ unsafe extern "unadjusted" {
213213
#[link_name = "llvm.s390.vftcidb"] fn vftcidb(a: vector_double, b: u32) -> PackedTuple<vector_bool_long_long, i32>;
214214

215215
#[link_name = "llvm.s390.vtm"] fn vtm(a: i8x16, b: i8x16) -> i32;
216+
217+
#[link_name = "llvm.s390.vstrsb"] fn vstrsb(a: vector_unsigned_char, b: vector_unsigned_char, c: vector_unsigned_char) -> PackedTuple<vector_unsigned_char, i32>;
218+
#[link_name = "llvm.s390.vstrsh"] fn vstrsh(a: vector_unsigned_short, b: vector_unsigned_short, c: vector_unsigned_char) -> PackedTuple<vector_unsigned_char, i32>;
219+
#[link_name = "llvm.s390.vstrsf"] fn vstrsf(a: vector_unsigned_int, b: vector_unsigned_int, c: vector_unsigned_char) -> PackedTuple<vector_unsigned_char, i32>;
220+
221+
#[link_name = "llvm.s390.vstrszb"] fn vstrszb(a: vector_unsigned_char, b: vector_unsigned_char, c: vector_unsigned_char) -> PackedTuple<vector_unsigned_char, i32>;
222+
#[link_name = "llvm.s390.vstrszh"] fn vstrszh(a: vector_unsigned_short, b: vector_unsigned_short, c: vector_unsigned_char) -> PackedTuple<vector_unsigned_char, i32>;
223+
#[link_name = "llvm.s390.vstrszf"] fn vstrszf(a: vector_unsigned_int, b: vector_unsigned_int, c: vector_unsigned_char) -> PackedTuple<vector_unsigned_char, i32>;
216224
}
217225

218226
impl_from! { i8x16, u8x16, i16x8, u16x8, i32x4, u32x4, i64x2, u64x2, f32x4, f64x2 }
@@ -2858,6 +2866,63 @@ mod sealed {
28582866
vector_float
28592867
vector_double
28602868
}
2869+
2870+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
2871+
pub trait VectorSearchString {
2872+
unsafe fn vec_search_string_cc(
2873+
self,
2874+
b: Self,
2875+
c: vector_unsigned_char,
2876+
d: &mut i32,
2877+
) -> vector_unsigned_char;
2878+
2879+
unsafe fn vec_search_string_until_zero_cc(
2880+
self,
2881+
b: Self,
2882+
c: vector_unsigned_char,
2883+
d: &mut i32,
2884+
) -> vector_unsigned_char;
2885+
}
2886+
2887+
macro_rules! impl_vec_search_string{
2888+
($($intr_s:ident $intr_sz:ident $ty:ident)*) => {
2889+
$(
2890+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
2891+
impl VectorSearchString for $ty {
2892+
#[inline]
2893+
#[target_feature(enable = "vector")]
2894+
unsafe fn vec_search_string_cc(self, b: Self, c: vector_unsigned_char, d: &mut i32) -> vector_unsigned_char {
2895+
let PackedTuple { x,y } = $intr_s(transmute(self), transmute(b), c);
2896+
*d = y;
2897+
x
2898+
}
2899+
2900+
#[inline]
2901+
#[target_feature(enable = "vector")]
2902+
unsafe fn vec_search_string_until_zero_cc(self, b: Self, c: vector_unsigned_char, d: &mut i32) -> vector_unsigned_char {
2903+
let PackedTuple { x,y } = $intr_sz(transmute(self), transmute(b), c);
2904+
*d = y;
2905+
x
2906+
}
2907+
}
2908+
2909+
)*
2910+
}
2911+
}
2912+
2913+
impl_vec_search_string! {
2914+
vstrsb vstrszb vector_signed_char
2915+
vstrsb vstrszb vector_bool_char
2916+
vstrsb vstrszb vector_unsigned_char
2917+
2918+
vstrsh vstrszh vector_signed_short
2919+
vstrsh vstrszh vector_bool_short
2920+
vstrsh vstrszh vector_unsigned_short
2921+
2922+
vstrsf vstrszf vector_signed_int
2923+
vstrsf vstrszf vector_bool_int
2924+
vstrsf vstrszf vector_unsigned_int
2925+
}
28612926
}
28622927

28632928
/// Load Count to Block Boundary
@@ -4101,6 +4166,32 @@ pub unsafe fn vec_test_mask<T: sealed::VectorTestMask>(a: T, b: T::Mask) -> i32
41014166
a.vec_test_mask(b)
41024167
}
41034168

4169+
/// Vector Search String
4170+
#[inline]
4171+
#[target_feature(enable = "vector")]
4172+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
4173+
pub unsafe fn vec_search_string_cc<T: sealed::VectorSearchString>(
4174+
a: T,
4175+
b: T,
4176+
c: vector_unsigned_char,
4177+
d: &mut i32,
4178+
) -> vector_unsigned_char {
4179+
a.vec_search_string_cc(b, c, d)
4180+
}
4181+
4182+
/// Vector Search String Until Zero
4183+
#[inline]
4184+
#[target_feature(enable = "vector")]
4185+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
4186+
pub unsafe fn vec_search_string_until_zero_cc<T: sealed::VectorSearchString>(
4187+
a: T,
4188+
b: T,
4189+
c: vector_unsigned_char,
4190+
d: &mut i32,
4191+
) -> vector_unsigned_char {
4192+
a.vec_search_string_until_zero_cc(b, c, d)
4193+
}
4194+
41044195
#[cfg(test)]
41054196
mod tests {
41064197
use super::*;
@@ -5142,4 +5233,72 @@ mod tests {
51425233
assert_eq!(vec_test_mask(v, m), 3);
51435234
}
51445235
}
5236+
5237+
#[simd_test(enable = "vector-enhancements-2")]
5238+
fn test_vec_search_string_cc() {
5239+
unsafe {
5240+
let b = vector_unsigned_char(*b"ABCD------------");
5241+
let c = vector_unsigned_char([4; 16]);
5242+
let mut d = 0i32;
5243+
5244+
let haystack = vector_unsigned_char(*b"__ABCD__________");
5245+
let result = vec_search_string_cc(haystack, b, c, &mut d);
5246+
assert_eq!(result.as_array()[7], 2);
5247+
assert_eq!(d, 2);
5248+
5249+
let haystack = vector_unsigned_char(*b"___ABCD_________");
5250+
let result = vec_search_string_cc(haystack, b, c, &mut d);
5251+
assert_eq!(result.as_array()[7], 3);
5252+
assert_eq!(d, 2);
5253+
5254+
let haystack = vector_unsigned_char(*b"________________");
5255+
let result = vec_search_string_cc(haystack, b, c, &mut d);
5256+
assert_eq!(result.as_array()[7], 16);
5257+
assert_eq!(d, 0);
5258+
5259+
let haystack = vector_unsigned_char(*b"______\0_________");
5260+
let result = vec_search_string_cc(haystack, b, c, &mut d);
5261+
assert_eq!(result.as_array()[7], 16);
5262+
assert_eq!(d, 0);
5263+
5264+
let haystack = vector_unsigned_char(*b"______\0__ABCD___");
5265+
let result = vec_search_string_cc(haystack, b, c, &mut d);
5266+
assert_eq!(result.as_array()[7], 9);
5267+
assert_eq!(d, 2);
5268+
}
5269+
}
5270+
5271+
#[simd_test(enable = "vector-enhancements-2")]
5272+
fn test_vec_search_string_until_zero_cc() {
5273+
unsafe {
5274+
let b = vector_unsigned_char(*b"ABCD\0\0\0\0\0\0\0\0\0\0\0\0");
5275+
let c = vector_unsigned_char([16; 16]);
5276+
let mut d = 0i32;
5277+
5278+
let haystack = vector_unsigned_char(*b"__ABCD__________");
5279+
let result = vec_search_string_until_zero_cc(haystack, b, c, &mut d);
5280+
assert_eq!(result.as_array()[7], 2);
5281+
assert_eq!(d, 2);
5282+
5283+
let haystack = vector_unsigned_char(*b"___ABCD_________");
5284+
let result = vec_search_string_until_zero_cc(haystack, b, c, &mut d);
5285+
assert_eq!(result.as_array()[7], 3);
5286+
assert_eq!(d, 2);
5287+
5288+
let haystack = vector_unsigned_char(*b"________________");
5289+
let result = vec_search_string_until_zero_cc(haystack, b, c, &mut d);
5290+
assert_eq!(result.as_array()[7], 16);
5291+
assert_eq!(d, 0);
5292+
5293+
let haystack = vector_unsigned_char(*b"______\0_________");
5294+
let result = vec_search_string_until_zero_cc(haystack, b, c, &mut d);
5295+
assert_eq!(result.as_array()[7], 16);
5296+
assert_eq!(d, 1);
5297+
5298+
let haystack = vector_unsigned_char(*b"______\0__ABCD___");
5299+
let result = vec_search_string_until_zero_cc(haystack, b, c, &mut d);
5300+
assert_eq!(result.as_array()[7], 16);
5301+
assert_eq!(d, 1);
5302+
}
5303+
}
51455304
}

0 commit comments

Comments
 (0)