Skip to content

Commit bffd44f

Browse files
lu-zeroAmanieu
authored andcommitted
Add vec_insert and vec_extract
1 parent 8ce6875 commit bffd44f

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

Diff for: crates/core_arch/src/powerpc/altivec.rs

+98
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,66 @@ impl_neg! { f32x4 : 0f32 }
408408
mod sealed {
409409
use super::*;
410410

411+
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
412+
pub trait VectorInsert {
413+
type S;
414+
unsafe fn vec_insert<const IDX: u32>(self, s: Self::S) -> Self;
415+
}
416+
417+
const fn idx_in_vec<T, const IDX: u32>() -> u32 {
418+
IDX & (16 / crate::mem::size_of::<T>() as u32)
419+
}
420+
421+
macro_rules! impl_vec_insert {
422+
($ty:ident) => {
423+
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
424+
impl VectorInsert for t_t_l!($ty) {
425+
type S = $ty;
426+
#[inline]
427+
#[target_feature(enable = "altivec")]
428+
unsafe fn vec_insert<const IDX: u32>(self, s: Self::S) -> Self {
429+
simd_insert(self, const { idx_in_vec::<Self::S, IDX>() }, s)
430+
}
431+
}
432+
};
433+
}
434+
435+
impl_vec_insert! { i8 }
436+
impl_vec_insert! { u8 }
437+
impl_vec_insert! { i16 }
438+
impl_vec_insert! { u16 }
439+
impl_vec_insert! { i32 }
440+
impl_vec_insert! { u32 }
441+
impl_vec_insert! { f32 }
442+
443+
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
444+
pub trait VectorExtract {
445+
type S;
446+
unsafe fn vec_extract<const IDX: u32>(self) -> Self::S;
447+
}
448+
449+
macro_rules! impl_vec_extract {
450+
($ty:ident) => {
451+
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
452+
impl VectorExtract for t_t_l!($ty) {
453+
type S = $ty;
454+
#[inline]
455+
#[target_feature(enable = "altivec")]
456+
unsafe fn vec_extract<const IDX: u32>(self) -> Self::S {
457+
simd_extract(self, const { idx_in_vec::<Self::S, IDX>() })
458+
}
459+
}
460+
};
461+
}
462+
463+
impl_vec_extract! { i8 }
464+
impl_vec_extract! { u8 }
465+
impl_vec_extract! { i16 }
466+
impl_vec_extract! { u16 }
467+
impl_vec_extract! { i32 }
468+
impl_vec_extract! { u32 }
469+
impl_vec_extract! { f32 }
470+
411471
macro_rules! impl_vec_cmp {
412472
([$Trait:ident $m:ident] ($b:ident, $h:ident, $w:ident)) => {
413473
impl_vec_cmp! { [$Trait $m] ($b, $b, $h, $h, $w, $w) }
@@ -3219,6 +3279,44 @@ mod sealed {
32193279
}
32203280
}
32213281

3282+
/// Vector Insert
3283+
///
3284+
/// ## Purpose
3285+
/// Returns a copy of vector b with element c replaced by the value of a.
3286+
///
3287+
/// ## Result value
3288+
/// r contains a copy of vector b with element c replaced by the value of a.
3289+
/// This function uses modular arithmetic on c to determine the element number.
3290+
/// For example, if c is out of range, the compiler uses c modulo the number of
3291+
/// elements in the vector to determine the element position.
3292+
#[inline]
3293+
#[target_feature(enable = "altivec")]
3294+
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
3295+
pub unsafe fn vec_insert<T, const IDX: u32>(a: T, b: <T as sealed::VectorInsert>::S) -> T
3296+
where
3297+
T: sealed::VectorInsert,
3298+
{
3299+
a.vec_insert::<IDX>(b)
3300+
}
3301+
3302+
/// Vector Extract
3303+
///
3304+
/// ## Purpose
3305+
/// Returns the value of the bth element of vector a.
3306+
///
3307+
/// ## Result value
3308+
/// The value of each element of r is the element of a at position b modulo the number of
3309+
/// elements of a.
3310+
#[inline]
3311+
#[target_feature(enable = "altivec")]
3312+
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
3313+
pub unsafe fn vec_extract<T, const IDX: u32>(a: T) -> <T as sealed::VectorExtract>::S
3314+
where
3315+
T: sealed::VectorExtract,
3316+
{
3317+
a.vec_extract::<IDX>()
3318+
}
3319+
32223320
/// Vector Merge Low
32233321
#[inline]
32243322
#[target_feature(enable = "altivec")]

0 commit comments

Comments
 (0)