Skip to content

Commit 474b389

Browse files
committed
powerpc/vsx: implement vec_sld for vector_double
1 parent 6332f19 commit 474b389

3 files changed

Lines changed: 48 additions & 22 deletions

File tree

crates/core_arch/src/powerpc/altivec.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ unsafe extern "unadjusted" {
411411
}
412412

413413
#[macro_use]
414-
mod sealed {
414+
pub(crate) mod sealed {
415415
use super::*;
416416

417417
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
@@ -3030,7 +3030,7 @@ mod sealed {
30303030
#[inline]
30313031
#[target_feature(enable = "altivec")]
30323032
#[cfg_attr(test, assert_instr(vsldoi, UIMM4 = 1))]
3033-
unsafe fn vsldoi<const UIMM4: i32>(
3033+
pub(crate) unsafe fn vsldoi<const UIMM4: i32>(
30343034
a: vector_unsigned_char,
30353035
b: vector_unsigned_char,
30363036
) -> vector_unsigned_char {
@@ -3082,9 +3082,9 @@ mod sealed {
30823082

30833083
// TODO: collapse the two once generic_const_exprs are usable.
30843084
#[inline]
3085-
#[target_feature(enable = "altivec")]
3085+
#[target_feature(enable = "vsx")]
30863086
#[cfg_attr(test, assert_instr(xxsldwi, UIMM2 = 1))]
3087-
unsafe fn xxsldwi<const UIMM2: i32>(
3087+
pub(crate) unsafe fn xxsldwi<const UIMM2: i32>(
30883088
a: vector_unsigned_char,
30893089
b: vector_unsigned_char,
30903090
) -> vector_unsigned_char {
@@ -3134,24 +3134,6 @@ mod sealed {
31343134
}
31353135
}
31363136

3137-
macro_rules! impl_vec_sld {
3138-
($($ty:ident),+) => { $(
3139-
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
3140-
impl VectorSld for $ty {
3141-
#[inline]
3142-
#[target_feature(enable = "altivec")]
3143-
unsafe fn vec_sld<const UIMM4: i32>(self, b: Self) -> Self {
3144-
transmute(vsldoi::<UIMM4>(transmute(self), transmute(b)))
3145-
}
3146-
#[inline]
3147-
#[target_feature(enable = "altivec")]
3148-
unsafe fn vec_sldw<const UIMM2: i32>(self, b: Self) -> Self {
3149-
transmute(xxsldwi::<UIMM2>(transmute(self), transmute(b)))
3150-
}
3151-
}
3152-
)+ };
3153-
}
3154-
31553137
impl_vec_sld! { vector_bool_char, vector_signed_char, vector_unsigned_char }
31563138
impl_vec_sld! { vector_bool_short, vector_signed_short, vector_unsigned_short }
31573139
impl_vec_sld! { vector_bool_int, vector_signed_int, vector_unsigned_int }

crates/core_arch/src/powerpc/macros.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,25 @@ macro_rules! t_b {
274274
};
275275
}
276276

277+
macro_rules! impl_vec_sld {
278+
($($ty:ident),+) => { $(
279+
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
280+
impl VectorSld for $ty {
281+
#[inline]
282+
#[target_feature(enable = "altivec")]
283+
unsafe fn vec_sld<const UIMM4: i32>(self, b: Self) -> Self {
284+
transmute(vsldoi::<UIMM4>(transmute(self), transmute(b)))
285+
}
286+
#[inline]
287+
#[target_feature(enable = "vsx")]
288+
unsafe fn vec_sldw<const UIMM2: i32>(self, b: Self) -> Self {
289+
transmute(xxsldwi::<UIMM2>(transmute(self), transmute(b)))
290+
}
291+
}
292+
)+ };
293+
}
294+
295+
pub(crate) use impl_vec_sld;
277296
pub(crate) use impl_vec_trait;
278297
pub(crate) use s_t_l;
279298
pub(crate) use t_b;

crates/core_arch/src/powerpc/vsx.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use crate::core_arch::powerpc::*;
1212
use crate::core_arch::simd::*;
13+
use super::macros::*;
1314

1415
#[cfg(test)]
1516
use stdarch_test::assert_instr;
@@ -173,6 +174,10 @@ mod sealed {
173174
vec_mergeeo! { vector_float, mergee, mergeo }
174175
}
175176

177+
// Implement AltiVec's VectorSld trait for vector_double to enable vec_sld support
178+
use crate::core_arch::powerpc::altivec::sealed::{VectorSld, vsldoi, xxsldwi};
179+
impl_vec_sld! { vector_double }
180+
176181
/// Vector permute.
177182
#[inline]
178183
#[target_feature(enable = "vsx")]
@@ -255,4 +260,24 @@ mod tests {
255260
test_vec_xxpermdi! {test_vec_xxpermdi_i64x2, i64x2, vector_signed_long, [0], [-1], [2], [-3]}
256261
test_vec_xxpermdi! {test_vec_xxpermdi_m64x2, m64x2, vector_bool_long, [false], [true], [false], [true]}
257262
test_vec_xxpermdi! {test_vec_xxpermdi_f64x2, f64x2, vector_double, [0.0], [1.0], [2.0], [3.0]}
263+
264+
#[simd_test(enable = "altivec")]
265+
fn test_vec_sld_f64x2() {
266+
use crate::core_arch::powerpc::altivec::sealed::VectorSld;
267+
268+
let a = vector_double::from(f64x2::from_array([1.0, 2.0]));
269+
let b = vector_double::from(f64x2::from_array([3.0, 4.0]));
270+
271+
// Shift left by 8 bytes (1 f64 element)
272+
// On little-endian: shifts right in memory, result is [b[1], a[0]] = [4.0, 1.0]
273+
// On big-endian: shifts left in memory, result is [a[1], b[0]] = [2.0, 3.0]
274+
unsafe {
275+
let result: f64x2 = transmute(a.vec_sld::<8>(b));
276+
#[cfg(target_endian = "little")]
277+
let expected = f64x2::from_array([4.0, 1.0]);
278+
#[cfg(target_endian = "big")]
279+
let expected = f64x2::from_array([2.0, 3.0]);
280+
assert_eq!(result, expected);
281+
}
282+
}
258283
}

0 commit comments

Comments
 (0)