Skip to content

Commit 2c1c7ad

Browse files
lu-zeroAmanieu
authored andcommitted
Add vec_pack
1 parent 6d5b5c1 commit 2c1c7ad

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

crates/core_arch/src/powerpc/altivec.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,56 @@ mod sealed {
21182118

21192119
impl_vec_trait! { [VectorMergel vec_mergel]+ 2b (vec_vmrglb, vec_vmrglh, vec_vmrglw) }
21202120
impl_vec_trait! { [VectorMergel vec_mergel]+ vec_vmrglw (vector_float, vector_float) -> vector_float }
2121+
2122+
#[inline]
2123+
#[target_feature(enable = "altivec")]
2124+
#[cfg_attr(test, assert_instr(vpkuhum))]
2125+
unsafe fn vec_vpkuhum(a: vector_signed_short, b: vector_signed_short) -> vector_signed_char {
2126+
let pack_perm = if cfg!(target_endian = "little") {
2127+
transmute(u8x16::new(
2128+
0x00, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A,
2129+
0x1C, 0x1E,
2130+
))
2131+
} else {
2132+
transmute(u8x16::new(
2133+
0x01, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0F, 0x11, 0x13, 0x15, 0x17, 0x19, 0x1B,
2134+
0x1D, 0x1F,
2135+
))
2136+
};
2137+
2138+
transmute(vec_perm(a, b, pack_perm))
2139+
}
2140+
2141+
#[inline]
2142+
#[target_feature(enable = "altivec")]
2143+
#[cfg_attr(test, assert_instr(vpkuwum))]
2144+
unsafe fn vec_vpkuwum(a: vector_signed_int, b: vector_signed_int) -> vector_signed_short {
2145+
let pack_perm = if cfg!(target_endian = "little") {
2146+
transmute(u8x16::new(
2147+
0x00, 0x01, 0x04, 0x05, 0x08, 0x09, 0x0C, 0x0D, 0x10, 0x11, 0x14, 0x15, 0x18, 0x19,
2148+
0x1C, 0x1D,
2149+
))
2150+
} else {
2151+
transmute(u8x16::new(
2152+
0x02, 0x03, 0x06, 0x07, 0x0A, 0x0B, 0x0E, 0x0F, 0x12, 0x13, 0x16, 0x17, 0x1A, 0x1B,
2153+
0x1E, 0x1F,
2154+
))
2155+
};
2156+
2157+
transmute(vec_perm(a, b, pack_perm))
2158+
}
2159+
2160+
pub trait VectorPack<Other> {
2161+
type Result;
2162+
unsafe fn vec_pack(self, b: Other) -> Self::Result;
2163+
}
2164+
2165+
impl_vec_trait! { [VectorPack vec_pack]+ vec_vpkuhum (vector_signed_short, vector_signed_short) -> vector_signed_char }
2166+
impl_vec_trait! { [VectorPack vec_pack]+ vec_vpkuhum (vector_unsigned_short, vector_unsigned_short) -> vector_unsigned_char }
2167+
impl_vec_trait! { [VectorPack vec_pack]+ vec_vpkuhum (vector_bool_short, vector_bool_short) -> vector_bool_char }
2168+
impl_vec_trait! { [VectorPack vec_pack]+ vec_vpkuwum (vector_signed_int, vector_signed_int) -> vector_signed_short }
2169+
impl_vec_trait! { [VectorPack vec_pack]+ vec_vpkuwum (vector_unsigned_int, vector_unsigned_int) -> vector_unsigned_short }
2170+
impl_vec_trait! { [VectorPack vec_pack]+ vec_vpkuwum (vector_bool_int, vector_bool_int) -> vector_bool_short }
21212171
}
21222172

21232173
/// Vector Merge Low
@@ -2140,6 +2190,16 @@ where
21402190
a.vec_mergeh(b)
21412191
}
21422192

2193+
/// Vector Pack
2194+
#[inline]
2195+
#[target_feature(enable = "altivec")]
2196+
pub unsafe fn vec_pack<T, U>(a: T, b: U) -> <T as sealed::VectorPack<U>>::Result
2197+
where
2198+
T: sealed::VectorPack<U>,
2199+
{
2200+
a.vec_pack(b)
2201+
}
2202+
21432203
/// Vector Load Indexed.
21442204
#[inline]
21452205
#[target_feature(enable = "altivec")]

0 commit comments

Comments
 (0)