Skip to content

Commit f99fee7

Browse files
lu-zerognzlbg
authored andcommitted
Add Altivec vec_cmpeq
1 parent 6df722d commit f99fee7

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

crates/core_arch/src/powerpc/altivec.rs

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ extern "C" {
212212

213213
#[link_name = "llvm.ppc.altivec.vcmpbfp"]
214214
fn vcmpbfp(a: vector_float, b: vector_float) -> vector_signed_int;
215+
216+
#[link_name = "llvm.ppc.altivec.vcmpequb"]
217+
fn vcmpequb(a: vector_unsigned_char, b: vector_unsigned_char) -> vector_bool_char;
218+
#[link_name = "llvm.ppc.altivec.vcmpequh"]
219+
fn vcmpequh(a: vector_unsigned_short, b: vector_unsigned_short) -> vector_bool_short;
220+
#[link_name = "llvm.ppc.altivec.vcmpequw"]
221+
fn vcmpequw(a: vector_unsigned_int, b: vector_unsigned_int) -> vector_bool_int;
215222
}
216223

217224
macro_rules! s_t_l {
@@ -368,6 +375,28 @@ mod sealed {
368375
}
369376
}
370377

378+
test_impl! { vec_vcmpequb(a: vector_unsigned_char, b: vector_unsigned_char) -> vector_bool_char [ vcmpequb, vcmpequb ] }
379+
test_impl! { vec_vcmpequh(a: vector_unsigned_short, b: vector_unsigned_short) -> vector_bool_short [ vcmpequh, vcmpequh ] }
380+
test_impl! { vec_vcmpequw(a: vector_unsigned_int, b: vector_unsigned_int) -> vector_bool_int [ vcmpequw, vcmpequw ] }
381+
382+
pub trait VectorCmpEq<Other> {
383+
type Result;
384+
unsafe fn vec_cmpeq(self, b: Other) -> Self::Result;
385+
}
386+
387+
macro_rules! impl_vec_cmp {
388+
([$Trait:ident $m:ident] ($b:ident, $h:ident, $w:ident)) => {
389+
impl_vec_trait!{ [$Trait $m] $b (vector_unsigned_char, vector_unsigned_char) -> vector_bool_char }
390+
impl_vec_trait!{ [$Trait $m] $b (vector_signed_char, vector_signed_char) -> vector_bool_char }
391+
impl_vec_trait!{ [$Trait $m] $h (vector_unsigned_short, vector_unsigned_short) -> vector_bool_short }
392+
impl_vec_trait!{ [$Trait $m] $h (vector_signed_short, vector_signed_short) -> vector_bool_short }
393+
impl_vec_trait!{ [$Trait $m] $w (vector_unsigned_int, vector_unsigned_int) -> vector_bool_int }
394+
impl_vec_trait!{ [$Trait $m] $w (vector_signed_int, vector_signed_int) -> vector_bool_int }
395+
}
396+
}
397+
398+
impl_vec_cmp! { [VectorCmpEq vec_cmpeq] (vec_vcmpequb, vec_vcmpequh, vec_vcmpequw) }
399+
371400
test_impl! { vec_vcmpbfp(a: vector_float, b: vector_float) -> vector_signed_int [vcmpbfp, vcmpbfp] }
372401

373402
test_impl! { vec_vceil(a: vector_float) -> vector_float [vceil, vrfip / xvrspip ] }
@@ -1289,6 +1318,16 @@ mod sealed {
12891318
vector_mladd! { vector_signed_short, vector_signed_short, vector_signed_short }
12901319
}
12911320

1321+
/// Vector cmpeq.
1322+
#[inline]
1323+
#[target_feature(enable = "altivec")]
1324+
pub unsafe fn vec_cmpeq<T, U>(a: T, b: U) -> <T as sealed::VectorCmpEq<U>>::Result
1325+
where
1326+
T: sealed::VectorCmpEq<U>,
1327+
{
1328+
a.vec_cmpeq(b)
1329+
}
1330+
12921331
/// Vector cmpb.
12931332
#[inline]
12941333
#[target_feature(enable = "altivec")]
@@ -1625,18 +1664,57 @@ mod tests {
16251664

16261665
macro_rules! test_vec_2 {
16271666
{ $name: ident, $fn:ident, $ty: ident, [$($a:expr),+], [$($b:expr),+], [$($d:expr),+] } => {
1667+
test_vec_2! { $name, $fn, $ty -> $ty, [$($a),+], [$($b),+], [$($d),+] }
1668+
};
1669+
{ $name: ident, $fn:ident, $ty: ident -> $ty_out: ident, [$($a:expr),+], [$($b:expr),+], [$($d:expr),+] } => {
16281670
#[simd_test(enable = "altivec")]
16291671
unsafe fn $name() {
16301672
let a: s_t_l!($ty) = transmute($ty::new($($a),+));
16311673
let b: s_t_l!($ty) = transmute($ty::new($($b),+));
16321674

1633-
let d = $ty::new($($d),+);
1634-
let r : $ty = transmute($fn(a, b));
1675+
let d = $ty_out::new($($d),+);
1676+
let r : $ty_out = transmute($fn(a, b));
16351677
assert_eq!(d, r);
16361678
}
16371679
}
16381680
}
16391681

1682+
test_vec_2! { test_vec_cmpeq_i8, vec_cmpeq, i8x16 -> m8x16,
1683+
[1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
1684+
[0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
1685+
[false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true]
1686+
}
1687+
1688+
test_vec_2! { test_vec_cmpeq_u8, vec_cmpeq, u8x16 -> m8x16,
1689+
[1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
1690+
[0, 0, 255, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
1691+
[false, false, false, false, true, true, true, true, true, true, true, true, true, true, true, true]
1692+
}
1693+
1694+
test_vec_2! { test_vec_cmpeq_i16, vec_cmpeq, i16x8 -> m16x8,
1695+
[1, -1, 0, 0, 0, 0, 0, 0],
1696+
[0, 0, -1, 1, 0, 0, 0, 0],
1697+
[false, false, false, false, true, true, true, true]
1698+
}
1699+
1700+
test_vec_2! { test_vec_cmpeq_u16, vec_cmpeq, u16x8 -> m16x8,
1701+
[1, 255, 0, 0, 0, 0, 0, 0],
1702+
[0, 0, 255, 1, 0, 0, 0, 0],
1703+
[false, false, false, false, true, true, true, true]
1704+
}
1705+
1706+
test_vec_2! { test_vec_cmpeq_i32, vec_cmpeq, i32x4 -> m32x4,
1707+
[1, -1, 0, 0],
1708+
[0, -1, 0, 1],
1709+
[false, true, true, false]
1710+
}
1711+
1712+
test_vec_2! { test_vec_cmpeq_u32, vec_cmpeq, u32x4 -> m32x4,
1713+
[1, 255, 0, 0],
1714+
[0, 255, 0, 1],
1715+
[false, true, true, false]
1716+
}
1717+
16401718
#[simd_test(enable = "altivec")]
16411719
unsafe fn test_vec_cmpb() {
16421720
let a: vector_float = transmute(f32x4::new(0.1, 0.5, 0.6, 0.9));

0 commit comments

Comments
 (0)