Skip to content

Commit 889136d

Browse files
committed
add vec_sum2, vec_sum4 and vec_sum_u128
1 parent 6f940af commit 889136d

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

crates/core_arch/src/s390x/vector.rs

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ unsafe extern "unadjusted" {
102102
#[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;
103103

104104
#[link_name = "llvm.s390.vperm"] fn vperm(a: vector_signed_char, b: vector_signed_char, c: vector_unsigned_char) -> vector_signed_char;
105+
106+
#[link_name = "llvm.s390.vsumb"] fn vsumb(a: vector_unsigned_char, b: vector_unsigned_char) -> vector_unsigned_int;
107+
#[link_name = "llvm.s390.vsumh"] fn vsumh(a: vector_unsigned_short, b: vector_unsigned_short) -> vector_unsigned_int;
108+
109+
#[link_name = "llvm.s390.vsumgh"] fn vsumgh(a: vector_unsigned_short, b: vector_unsigned_short) -> vector_unsigned_long_long;
110+
#[link_name = "llvm.s390.vsumgf"] fn vsumgf(a: vector_unsigned_int, b: vector_unsigned_int) -> vector_unsigned_long_long;
111+
112+
#[link_name = "llvm.s390.vsumqf"] fn vsumqf(a: vector_unsigned_int, b: vector_unsigned_int) -> u128;
113+
#[link_name = "llvm.s390.vsumqg"] fn vsumqg(a: vector_unsigned_long_long, b: vector_unsigned_long_long) -> u128;
114+
105115
}
106116

107117
impl_from! { i8x16, u8x16, i16x8, u16x8, i32x4, u32x4, i64x2, u64x2, f32x4, f64x2 }
@@ -1299,6 +1309,95 @@ mod sealed {
12991309
vector_float,
13001310
vector_double
13011311
}
1312+
1313+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1314+
pub trait VectorSumU128 {
1315+
unsafe fn vec_sum_u128(self, other: Self) -> vector_unsigned_char;
1316+
}
1317+
1318+
#[inline]
1319+
#[target_feature(enable = "vector")]
1320+
#[cfg_attr(test, assert_instr(vsumqf))]
1321+
pub unsafe fn vec_vsumqf(a: vector_unsigned_int, b: vector_unsigned_int) -> u128 {
1322+
transmute(vsumqf(a, b))
1323+
}
1324+
1325+
#[inline]
1326+
#[target_feature(enable = "vector")]
1327+
#[cfg_attr(test, assert_instr(vsumqg))]
1328+
pub unsafe fn vec_vsumqg(a: vector_unsigned_long_long, b: vector_unsigned_long_long) -> u128 {
1329+
transmute(vsumqg(a, b))
1330+
}
1331+
1332+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1333+
impl VectorSumU128 for vector_unsigned_int {
1334+
#[inline]
1335+
#[target_feature(enable = "vector")]
1336+
unsafe fn vec_sum_u128(self, other: Self) -> vector_unsigned_char {
1337+
transmute(vec_vsumqf(self, other))
1338+
}
1339+
}
1340+
1341+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1342+
impl VectorSumU128 for vector_unsigned_long_long {
1343+
#[inline]
1344+
#[target_feature(enable = "vector")]
1345+
unsafe fn vec_sum_u128(self, other: Self) -> vector_unsigned_char {
1346+
transmute(vec_vsumqg(self, other))
1347+
}
1348+
}
1349+
1350+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1351+
pub trait VectorSum2 {
1352+
unsafe fn vec_sum2(self, other: Self) -> vector_unsigned_long_long;
1353+
}
1354+
1355+
test_impl! { vec_vsumgh (a: vector_unsigned_short, b: vector_unsigned_short) -> vector_unsigned_long_long [vsumgh, vsumgh] }
1356+
test_impl! { vec_vsumgf (a: vector_unsigned_int, b: vector_unsigned_int) -> vector_unsigned_long_long [vsumgf, vsumgf] }
1357+
1358+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1359+
impl VectorSum2 for vector_unsigned_short {
1360+
#[inline]
1361+
#[target_feature(enable = "vector")]
1362+
unsafe fn vec_sum2(self, other: Self) -> vector_unsigned_long_long {
1363+
vec_vsumgh(self, other)
1364+
}
1365+
}
1366+
1367+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1368+
impl VectorSum2 for vector_unsigned_int {
1369+
#[inline]
1370+
#[target_feature(enable = "vector")]
1371+
unsafe fn vec_sum2(self, other: Self) -> vector_unsigned_long_long {
1372+
vec_vsumgf(self, other)
1373+
}
1374+
}
1375+
1376+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1377+
pub trait VectorSum4 {
1378+
unsafe fn vec_sum4(self, other: Self) -> vector_unsigned_int;
1379+
}
1380+
1381+
test_impl! { vec_vsumb (a: vector_unsigned_char, b: vector_unsigned_char) -> vector_unsigned_int [vsumb, vsumb] }
1382+
test_impl! { vec_vsumh (a: vector_unsigned_short, b: vector_unsigned_short) -> vector_unsigned_int [vsumh, vsumh] }
1383+
1384+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1385+
impl VectorSum4 for vector_unsigned_char {
1386+
#[inline]
1387+
#[target_feature(enable = "vector")]
1388+
unsafe fn vec_sum4(self, other: Self) -> vector_unsigned_int {
1389+
vec_vsumb(self, other)
1390+
}
1391+
}
1392+
1393+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1394+
impl VectorSum4 for vector_unsigned_short {
1395+
#[inline]
1396+
#[target_feature(enable = "vector")]
1397+
unsafe fn vec_sum4(self, other: Self) -> vector_unsigned_int {
1398+
vec_vsumh(self, other)
1399+
}
1400+
}
13021401
}
13031402

13041403
/// Vector element-wise addition.
@@ -1859,6 +1958,39 @@ pub unsafe fn vec_perm<T: sealed::VectorPerm>(a: T, b: T, c: vector_unsigned_cha
18591958
a.vec_perm(b, c)
18601959
}
18611960

1961+
/// Vector Sum Across Quadword
1962+
///
1963+
/// Returns a vector containing the results of performing a sum across all the elements in each of the quadword of vector a,
1964+
/// and the rightmost word or doubleword element of the b. The result is an unsigned 128-bit integer.
1965+
#[inline]
1966+
#[target_feature(enable = "vector")]
1967+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1968+
pub unsafe fn vec_sum_u128<T: sealed::VectorSumU128>(a: T, b: T) -> vector_unsigned_char {
1969+
a.vec_sum_u128(b)
1970+
}
1971+
1972+
/// Vector Sum Across Doubleword
1973+
///
1974+
/// Returns a vector containing the results of performing a sum across all the elements in each of the doubleword of vector a,
1975+
/// and the rightmost sub-element of the corresponding doubleword of b.
1976+
#[inline]
1977+
#[target_feature(enable = "vector")]
1978+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1979+
pub unsafe fn vec_sum2<T: sealed::VectorSum2>(a: T, b: T) -> vector_unsigned_long_long {
1980+
a.vec_sum2(b)
1981+
}
1982+
1983+
/// Vector Sum Across Word
1984+
///
1985+
/// Returns a vector containing the results of performing a sum across all the elements in each of the word of vector a,
1986+
/// and the rightmost sub-element of the corresponding word of b.
1987+
#[inline]
1988+
#[target_feature(enable = "vector")]
1989+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1990+
pub unsafe fn vec_sum4<T: sealed::VectorSum4>(a: T, b: T) -> vector_unsigned_int {
1991+
a.vec_sum4(b)
1992+
}
1993+
18621994
#[cfg(test)]
18631995
mod tests {
18641996
use super::*;

0 commit comments

Comments
 (0)