Skip to content

Commit 99b0683

Browse files
lu-zeroAmanieu
authored andcommitted
Add vec_sl
1 parent 2659a32 commit 99b0683

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

crates/core_arch/src/powerpc/altivec.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,32 @@ macro_rules! t_t_l {
389389
};
390390
}
391391

392+
macro_rules! t_t_s {
393+
(i32) => {
394+
i32x4
395+
};
396+
(i16) => {
397+
i16x8
398+
};
399+
(i8) => {
400+
i8x16
401+
};
402+
403+
(u32) => {
404+
u32x4
405+
};
406+
(u16) => {
407+
u16x8
408+
};
409+
(u8) => {
410+
u8x16
411+
};
412+
413+
(f32) => {
414+
f32x4
415+
};
416+
}
417+
392418
macro_rules! impl_from {
393419
($s: ident) => {
394420
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
@@ -2620,6 +2646,46 @@ mod sealed {
26202646
impl_vec_trait! { [VectorUnpackl vec_unpackl]+ vec_vupklsb (vector_bool_char) -> vector_bool_short }
26212647
impl_vec_trait! { [VectorUnpackl vec_unpackl] vec_vupklsh (vector_signed_short) -> vector_signed_int }
26222648
impl_vec_trait! { [VectorUnpackl vec_unpackl]+ vec_vupklsh (vector_bool_short) -> vector_bool_int }
2649+
2650+
macro_rules! impl_vec_shift {
2651+
([$Trait:ident $m:ident] ($b:ident, $h:ident, $w:ident)) => {
2652+
impl_vec_trait!{ [$Trait $m]+ $b (vector_unsigned_char, vector_unsigned_char) -> vector_unsigned_char }
2653+
impl_vec_trait!{ [$Trait $m]+ $b (vector_signed_char, vector_unsigned_char) -> vector_signed_char }
2654+
impl_vec_trait!{ [$Trait $m]+ $h (vector_unsigned_short, vector_unsigned_short) -> vector_unsigned_short }
2655+
impl_vec_trait!{ [$Trait $m]+ $h (vector_signed_short, vector_unsigned_short) -> vector_signed_short }
2656+
impl_vec_trait!{ [$Trait $m]+ $w (vector_unsigned_int, vector_unsigned_int) -> vector_unsigned_int }
2657+
impl_vec_trait!{ [$Trait $m]+ $w (vector_signed_int, vector_unsigned_int) -> vector_signed_int }
2658+
};
2659+
}
2660+
2661+
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
2662+
pub trait VectorSl<Other> {
2663+
type Result;
2664+
unsafe fn vec_sl(self, b: Other) -> Self::Result;
2665+
}
2666+
2667+
macro_rules! impl_sl {
2668+
($fun:ident $ty:ident) => {
2669+
#[inline]
2670+
#[target_feature(enable = "altivec")]
2671+
#[cfg_attr(test, assert_instr($fun))]
2672+
unsafe fn $fun(a: t_t_l!($ty), b: t_t_l!($ty)) -> t_t_l!($ty) {
2673+
let a = transmute(a);
2674+
let b = simd_rem(
2675+
transmute(b),
2676+
<t_t_s!($ty)>::splat(mem::size_of::<$ty>() as $ty * $ty::BITS as $ty),
2677+
);
2678+
2679+
transmute(simd_shl(a, b))
2680+
}
2681+
};
2682+
}
2683+
2684+
impl_sl! { vslb u8 }
2685+
impl_sl! { vslh u16 }
2686+
impl_sl! { vslw u32 }
2687+
2688+
impl_vec_shift! { [VectorSl vec_sl] (vslb, vslh, vslw) }
26232689
}
26242690

26252691
/// Vector Merge Low
@@ -2699,6 +2765,16 @@ where
26992765
a.vec_unpackl()
27002766
}
27012767

2768+
/// Vector Shift Left
2769+
#[inline]
2770+
#[target_feature(enable = "altivec")]
2771+
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
2772+
pub unsafe fn vec_sl<T, U>(a: T, b: U) -> <T as sealed::VectorSl<U>>::Result
2773+
where
2774+
T: sealed::VectorSl<U>,
2775+
{
2776+
a.vec_sl(b)
2777+
}
27022778
/// Vector Load Indexed.
27032779
#[inline]
27042780
#[target_feature(enable = "altivec")]

crates/core_arch/src/simd_llvm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern "platform-intrinsic" {
2424
pub fn simd_sub<T>(x: T, y: T) -> T;
2525
pub fn simd_mul<T>(x: T, y: T) -> T;
2626
pub fn simd_div<T>(x: T, y: T) -> T;
27+
pub fn simd_rem<T>(x: T, y: T) -> T;
2728
pub fn simd_shl<T>(x: T, y: T) -> T;
2829
pub fn simd_shr<T>(x: T, y: T) -> T;
2930
pub fn simd_and<T>(x: T, y: T) -> T;

0 commit comments

Comments
 (0)