Skip to content

Commit 31f15d5

Browse files
folkertdevAmanieu
authored andcommitted
add vec_revb
1 parent 1ee451f commit 31f15d5

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
@@ -1083,6 +1083,43 @@ mod sealed {
10831083
transmute(transmute::<_, vector_signed_long_long>(self).vec_reve())
10841084
}
10851085
}
1086+
1087+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1088+
pub trait VectorRevb {
1089+
unsafe fn vec_revb(self) -> Self;
1090+
}
1091+
1092+
test_impl! { bswapb (a: vector_signed_char) -> vector_signed_char [simd_bswap, _] }
1093+
test_impl! { bswaph (a: vector_signed_short) -> vector_signed_short [simd_bswap, vperm] }
1094+
test_impl! { bswapf (a: vector_signed_int) -> vector_signed_int [simd_bswap, vperm] }
1095+
test_impl! { bswapg (a: vector_signed_long_long) -> vector_signed_long_long [simd_bswap, vperm] }
1096+
1097+
impl_vec_trait! { [VectorRevb vec_revb]+ bswapb (vector_unsigned_char) }
1098+
impl_vec_trait! { [VectorRevb vec_revb]+ bswapb (vector_signed_char) }
1099+
impl_vec_trait! { [VectorRevb vec_revb]+ bswaph (vector_unsigned_short) }
1100+
impl_vec_trait! { [VectorRevb vec_revb]+ bswaph (vector_signed_short) }
1101+
impl_vec_trait! { [VectorRevb vec_revb]+ bswapf (vector_unsigned_int) }
1102+
impl_vec_trait! { [VectorRevb vec_revb]+ bswapf (vector_signed_int) }
1103+
impl_vec_trait! { [VectorRevb vec_revb]+ bswapg (vector_unsigned_long_long) }
1104+
impl_vec_trait! { [VectorRevb vec_revb]+ bswapg (vector_signed_long_long) }
1105+
1106+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1107+
impl VectorRevb for vector_float {
1108+
#[inline]
1109+
#[target_feature(enable = "vector")]
1110+
unsafe fn vec_revb(self) -> Self {
1111+
transmute(transmute::<_, vector_signed_int>(self).vec_revb())
1112+
}
1113+
}
1114+
1115+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1116+
impl VectorRevb for vector_double {
1117+
#[inline]
1118+
#[target_feature(enable = "vector")]
1119+
unsafe fn vec_revb(self) -> Self {
1120+
transmute(transmute::<_, vector_signed_long_long>(self).vec_revb())
1121+
}
1122+
}
10861123
}
10871124

10881125
/// Vector element-wise addition.
@@ -1554,6 +1591,17 @@ where
15541591
a.vec_reve()
15551592
}
15561593

1594+
/// Returns a vector where each vector element contains the corresponding byte-reversed vector element of the input vector.
1595+
#[inline]
1596+
#[target_feature(enable = "vector")]
1597+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1598+
pub unsafe fn vec_revb<T>(a: T) -> T
1599+
where
1600+
T: sealed::VectorRevb,
1601+
{
1602+
a.vec_revb()
1603+
}
1604+
15571605
#[cfg(test)]
15581606
mod tests {
15591607
use super::*;
@@ -1914,4 +1962,9 @@ mod tests {
19141962
[0.1, 0.5, 0.6, 0.9],
19151963
[0.9, 0.6, 0.5, 0.1]
19161964
}
1965+
1966+
test_vec_1! { test_vec_revb_u32, vec_revb, u32x4,
1967+
[0xAABBCCDD, 0xEEFF0011, 0x22334455, 0x66778899],
1968+
[0xDDCCBBAA, 0x1100FFEE, 0x55443322, 0x99887766]
1969+
}
19171970
}

0 commit comments

Comments
 (0)