Skip to content

Commit 5f1b287

Browse files
committed
add vec_revb
1 parent 1898379 commit 5f1b287

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

crates/core_arch/src/s390x/macros.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ macro_rules! impl_vec_trait {
5555
}
5656
}
5757
};
58+
([$Trait:ident $m:ident]+ $fun:ident ($a:ty)) => {
59+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
60+
impl $Trait for $a {
61+
#[inline]
62+
#[target_feature(enable = "vector")]
63+
unsafe fn $m(self) -> Self {
64+
transmute($fun(transmute(self)))
65+
}
66+
}
67+
};
5868
([$Trait:ident $m:ident] $fun:ident ($a:ty) -> $r:ty) => {
5969
#[unstable(feature = "stdarch_s390x", issue = "135681")]
6070
impl $Trait for $a {

crates/core_arch/src/s390x/vector.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,43 @@ mod sealed {
10871087
transmute(transmute::<_, vector_signed_long_long>(self).vec_reve())
10881088
}
10891089
}
1090+
1091+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1092+
pub trait VectorRevb {
1093+
unsafe fn vec_revb(self) -> Self;
1094+
}
1095+
1096+
test_impl! { bswapb (a: vector_signed_char) -> vector_signed_char [simd_bswap, _] }
1097+
test_impl! { bswaph (a: vector_signed_short) -> vector_signed_short [simd_bswap, vperm] }
1098+
test_impl! { bswapf (a: vector_signed_int) -> vector_signed_int [simd_bswap, vperm] }
1099+
test_impl! { bswapg (a: vector_signed_long_long) -> vector_signed_long_long [simd_bswap, vperm] }
1100+
1101+
impl_vec_trait! { [VectorRevb vec_revb]+ bswapb (vector_unsigned_char) }
1102+
impl_vec_trait! { [VectorRevb vec_revb]+ bswapb (vector_signed_char) }
1103+
impl_vec_trait! { [VectorRevb vec_revb]+ bswaph (vector_unsigned_short) }
1104+
impl_vec_trait! { [VectorRevb vec_revb]+ bswaph (vector_signed_short) }
1105+
impl_vec_trait! { [VectorRevb vec_revb]+ bswapf (vector_unsigned_int) }
1106+
impl_vec_trait! { [VectorRevb vec_revb]+ bswapf (vector_signed_int) }
1107+
impl_vec_trait! { [VectorRevb vec_revb]+ bswapg (vector_unsigned_long_long) }
1108+
impl_vec_trait! { [VectorRevb vec_revb]+ bswapg (vector_signed_long_long) }
1109+
1110+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1111+
impl VectorRevb for vector_float {
1112+
#[inline]
1113+
#[target_feature(enable = "vector")]
1114+
unsafe fn vec_revb(self) -> Self {
1115+
transmute(transmute::<_, vector_signed_int>(self).vec_revb())
1116+
}
1117+
}
1118+
1119+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1120+
impl VectorRevb for vector_double {
1121+
#[inline]
1122+
#[target_feature(enable = "vector")]
1123+
unsafe fn vec_revb(self) -> Self {
1124+
transmute(transmute::<_, vector_signed_long_long>(self).vec_revb())
1125+
}
1126+
}
10901127
}
10911128

10921129
/// Vector element-wise addition.
@@ -1558,6 +1595,17 @@ where
15581595
a.vec_reve()
15591596
}
15601597

1598+
/// Returns a vector where each vector element contains the corresponding byte-reversed vector element of the input vector.
1599+
#[inline]
1600+
#[target_feature(enable = "vector")]
1601+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1602+
pub unsafe fn vec_revb<T>(a: T) -> T
1603+
where
1604+
T: sealed::VectorRevb,
1605+
{
1606+
a.vec_revb()
1607+
}
1608+
15611609
#[cfg(test)]
15621610
mod tests {
15631611
use super::*;
@@ -1913,4 +1961,9 @@ mod tests {
19131961
[0.1, 0.5, 0.6, 0.9],
19141962
[0.9, 0.6, 0.5, 0.1]
19151963
}
1964+
1965+
test_vec_1! { test_vec_revb_u32, vec_revb, u32x4,
1966+
[0xAABBCCDD, 0xEEFF0011, 0x22334455, 0x66778899],
1967+
[0xDDCCBBAA, 0x1100FFEE, 0x55443322, 0x99887766]
1968+
}
19161969
}

0 commit comments

Comments
 (0)