Skip to content

Commit f57e862

Browse files
folkertdevAmanieu
authored andcommitted
implement standard bitshifts
1 parent 83ce767 commit f57e862

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

crates/core_arch/src/s390x/vector.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,73 @@ mod sealed {
706706
impl_vec_trait! { [VectorFloor vec_floor] simd_floor (vector_float) }
707707
impl_vec_trait! { [VectorFloor vec_floor] simd_floor (vector_double) }
708708

709+
macro_rules! impl_vec_shift {
710+
([$Trait:ident $m:ident] ($b:ident, $h:ident, $w:ident, $g:ident)) => {
711+
impl_vec_trait!{ [$Trait $m]+ $b (vector_unsigned_char, vector_unsigned_char) -> vector_unsigned_char }
712+
impl_vec_trait!{ [$Trait $m]+ $b (vector_signed_char, vector_unsigned_char) -> vector_signed_char }
713+
impl_vec_trait!{ [$Trait $m]+ $h (vector_unsigned_short, vector_unsigned_short) -> vector_unsigned_short }
714+
impl_vec_trait!{ [$Trait $m]+ $h (vector_signed_short, vector_unsigned_short) -> vector_signed_short }
715+
impl_vec_trait!{ [$Trait $m]+ $w (vector_unsigned_int, vector_unsigned_int) -> vector_unsigned_int }
716+
impl_vec_trait!{ [$Trait $m]+ $w (vector_signed_int, vector_unsigned_int) -> vector_signed_int }
717+
impl_vec_trait!{ [$Trait $m]+ $g (vector_unsigned_long_long, vector_unsigned_long_long) -> vector_unsigned_long_long }
718+
impl_vec_trait!{ [$Trait $m]+ $g (vector_signed_long_long, vector_unsigned_long_long) -> vector_signed_long_long }
719+
};
720+
}
721+
722+
macro_rules! impl_shift {
723+
($fun:ident $intr:ident $ty:ident) => {
724+
#[inline]
725+
#[target_feature(enable = "vector")]
726+
#[cfg_attr(test, assert_instr($fun))]
727+
unsafe fn $fun(a: t_t_l!($ty), b: t_t_l!($ty)) -> t_t_l!($ty) {
728+
let a = transmute(a);
729+
// use the remainder of b by the width of a's elements to prevent UB
730+
let b = simd_rem(transmute(b), <t_t_s!($ty)>::splat($ty::BITS as $ty));
731+
732+
transmute($intr(a, b))
733+
}
734+
};
735+
}
736+
737+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
738+
pub trait VectorSl<Other> {
739+
type Result;
740+
unsafe fn vec_sl(self, b: Other) -> Self::Result;
741+
}
742+
743+
impl_shift! { veslvb simd_shl u8 }
744+
impl_shift! { veslvh simd_shl u16 }
745+
impl_shift! { veslvf simd_shl u32 }
746+
impl_shift! { veslvg simd_shl u64 }
747+
748+
impl_vec_shift! { [VectorSl vec_sl] (veslvb, veslvh, veslvf, veslvg) }
749+
750+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
751+
pub trait VectorSr<Other> {
752+
type Result;
753+
unsafe fn vec_sr(self, b: Other) -> Self::Result;
754+
}
755+
756+
impl_shift! { vesrlvb simd_shr u8 }
757+
impl_shift! { vesrlvh simd_shr u16 }
758+
impl_shift! { vesrlvf simd_shr u32 }
759+
impl_shift! { vesrlvg simd_shr u64 }
760+
761+
impl_vec_shift! { [VectorSr vec_sr] (vesrlvb, vesrlvh, vesrlvf, vesrlvg) }
762+
763+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
764+
pub trait VectorSra<Other> {
765+
type Result;
766+
unsafe fn vec_sra(self, b: Other) -> Self::Result;
767+
}
768+
769+
impl_shift! { vesravb simd_shr i8 }
770+
impl_shift! { vesravh simd_shr i16 }
771+
impl_shift! { vesravf simd_shr i32 }
772+
impl_shift! { vesravg simd_shr i64 }
773+
774+
impl_vec_shift! { [VectorSra vec_sra] (vesravb, vesravh, vesravf, vesravg) }
775+
709776
macro_rules! impl_vec_shift_long {
710777
([$trait:ident $m:ident] ($f:ident)) => {
711778
impl_vec_trait!{ [$trait $m]+ $f (vector_unsigned_char, vector_unsigned_char) -> vector_unsigned_char }
@@ -1076,6 +1143,39 @@ where
10761143
a.vec_rint()
10771144
}
10781145

1146+
/// Vector Shift Left
1147+
#[inline]
1148+
#[target_feature(enable = "vector")]
1149+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1150+
pub unsafe fn vec_sl<T, U>(a: T, b: U) -> <T as sealed::VectorSl<U>>::Result
1151+
where
1152+
T: sealed::VectorSl<U>,
1153+
{
1154+
a.vec_sl(b)
1155+
}
1156+
1157+
/// Vector Shift Right
1158+
#[inline]
1159+
#[target_feature(enable = "vector")]
1160+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1161+
pub unsafe fn vec_sr<T, U>(a: T, b: U) -> <T as sealed::VectorSr<U>>::Result
1162+
where
1163+
T: sealed::VectorSr<U>,
1164+
{
1165+
a.vec_sr(b)
1166+
}
1167+
1168+
/// Vector Shift Right Algebraic
1169+
#[inline]
1170+
#[target_feature(enable = "vector")]
1171+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1172+
pub unsafe fn vec_sra<T, U>(a: T, b: U) -> <T as sealed::VectorSra<U>>::Result
1173+
where
1174+
T: sealed::VectorSra<U>,
1175+
{
1176+
a.vec_sra(b)
1177+
}
1178+
10791179
/// Performs a left shift for a vector by a given number of bits. Each element of the result is obtained by shifting the corresponding
10801180
/// element of a left by the number of bits specified by the last 3 bits of every byte of b. The bits that are shifted out are replaced by zeros.
10811181
#[inline]

0 commit comments

Comments
 (0)