Skip to content

Commit 9bb996c

Browse files
lu-zeroAmanieu
authored andcommitted
Add vec_unpackh and vec_unpackl
1 parent 947e006 commit 9bb996c

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

crates/core_arch/src/powerpc/altivec.rs

+71
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ extern "C" {
308308
fn vpkswus(a: vector_signed_int, b: vector_signed_int) -> vector_unsigned_short;
309309
#[link_name = "llvm.ppc.altivec.vpkuwus"]
310310
fn vpkuwus(a: vector_unsigned_int, b: vector_unsigned_int) -> vector_unsigned_short;
311+
312+
#[link_name = "llvm.ppc.altivec.vupkhsb"]
313+
fn vupkhsb(a: vector_signed_char) -> vector_signed_short;
314+
#[link_name = "llvm.ppc.altivec.vupklsb"]
315+
fn vupklsb(a: vector_signed_char) -> vector_signed_short;
316+
317+
#[link_name = "llvm.ppc.altivec.vupkhsh"]
318+
fn vupkhsh(a: vector_signed_short) -> vector_signed_int;
319+
#[link_name = "llvm.ppc.altivec.vupklsh"]
320+
fn vupklsh(a: vector_signed_short) -> vector_signed_int;
311321
}
312322

313323
macro_rules! s_t_l {
@@ -2270,6 +2280,47 @@ mod sealed {
22702280
impl_vec_trait! { [VectorPacksu vec_packsu] vec_vpkuhus (vector_unsigned_short, vector_unsigned_short) -> vector_unsigned_char }
22712281
impl_vec_trait! { [VectorPacksu vec_packsu] vec_vpkswus (vector_signed_int, vector_signed_int) -> vector_unsigned_short }
22722282
impl_vec_trait! { [VectorPacksu vec_packsu] vec_vpkuwus (vector_unsigned_int, vector_unsigned_int) -> vector_unsigned_short }
2283+
2284+
macro_rules! impl_vec_unpack {
2285+
($fun:ident ($a:ident) -> $r:ident [$little:ident, $big:ident]) => {
2286+
#[inline]
2287+
#[target_feature(enable = "altivec")]
2288+
#[cfg_attr(all(test, target_endiant = "little"), assert_instr($little))]
2289+
#[cfg_attr(all(test, target_endiant = "big"), assert_instr($big))]
2290+
unsafe fn $fun(a: $a) -> $r {
2291+
if cfg!(target_endian = "little") {
2292+
$little(a)
2293+
} else {
2294+
$big(a)
2295+
}
2296+
}
2297+
};
2298+
}
2299+
2300+
impl_vec_unpack! { vec_vupkhsb (vector_signed_char) -> vector_signed_short [vupklsb, vupkhsb] }
2301+
impl_vec_unpack! { vec_vupklsb (vector_signed_char) -> vector_signed_short [vupkhsb, vupklsb] }
2302+
impl_vec_unpack! { vec_vupkhsh (vector_signed_short) -> vector_signed_int [vupklsh, vupkhsh] }
2303+
impl_vec_unpack! { vec_vupklsh (vector_signed_short) -> vector_signed_int [vupkhsh, vupklsh] }
2304+
2305+
pub trait VectorUnpackh {
2306+
type Result;
2307+
unsafe fn vec_unpackh(self) -> Self::Result;
2308+
}
2309+
2310+
impl_vec_trait! { [VectorUnpackh vec_unpackh] vec_vupkhsb (vector_signed_char) -> vector_signed_short }
2311+
impl_vec_trait! { [VectorUnpackh vec_unpackh]+ vec_vupkhsb (vector_bool_char) -> vector_bool_short }
2312+
impl_vec_trait! { [VectorUnpackh vec_unpackh] vec_vupkhsh (vector_signed_short) -> vector_signed_int }
2313+
impl_vec_trait! { [VectorUnpackh vec_unpackh]+ vec_vupkhsh (vector_bool_short) -> vector_bool_int }
2314+
2315+
pub trait VectorUnpackl {
2316+
type Result;
2317+
unsafe fn vec_unpackl(self) -> Self::Result;
2318+
}
2319+
2320+
impl_vec_trait! { [VectorUnpackl vec_unpackl] vec_vupklsb (vector_signed_char) -> vector_signed_short }
2321+
impl_vec_trait! { [VectorUnpackl vec_unpackl]+ vec_vupklsb (vector_bool_char) -> vector_bool_short }
2322+
impl_vec_trait! { [VectorUnpackl vec_unpackl] vec_vupklsh (vector_signed_short) -> vector_signed_int }
2323+
impl_vec_trait! { [VectorUnpackl vec_unpackl]+ vec_vupklsh (vector_bool_short) -> vector_bool_int }
22732324
}
22742325

22752326
/// Vector Merge Low
@@ -2322,6 +2373,26 @@ where
23222373
a.vec_packsu(b)
23232374
}
23242375

2376+
/// Vector Unpack High
2377+
#[inline]
2378+
#[target_feature(enable = "altivec")]
2379+
pub unsafe fn vec_unpackh<T>(a: T) -> <T as sealed::VectorUnpackh>::Result
2380+
where
2381+
T: sealed::VectorUnpackh,
2382+
{
2383+
a.vec_unpackh()
2384+
}
2385+
2386+
/// Vector Unpack Low
2387+
#[inline]
2388+
#[target_feature(enable = "altivec")]
2389+
pub unsafe fn vec_unpackl<T>(a: T) -> <T as sealed::VectorUnpackl>::Result
2390+
where
2391+
T: sealed::VectorUnpackl,
2392+
{
2393+
a.vec_unpackl()
2394+
}
2395+
23252396
/// Vector Load Indexed.
23262397
#[inline]
23272398
#[target_feature(enable = "altivec")]

crates/core_arch/src/powerpc/macros.rs

+10
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ macro_rules! impl_vec_trait {
3939
}
4040
}
4141
};
42+
([$Trait:ident $m:ident]+ $fun:ident ($a:ty) -> $r:ty) => {
43+
impl $Trait for $a {
44+
type Result = $r;
45+
#[inline]
46+
#[target_feature(enable = "altivec")]
47+
unsafe fn $m(self) -> Self::Result {
48+
transmute($fun(transmute(self)))
49+
}
50+
}
51+
};
4252
([$Trait:ident $m:ident] 1 ($ub:ident, $sb:ident, $uh:ident, $sh:ident, $uw:ident, $sw:ident, $sf: ident)) => {
4353
impl_vec_trait!{ [$Trait $m] $ub (vector_unsigned_char) -> vector_unsigned_char }
4454
impl_vec_trait!{ [$Trait $m] $sb (vector_signed_char) -> vector_signed_char }

0 commit comments

Comments
 (0)