Skip to content

Commit e5f2bc3

Browse files
lu-zeroAmanieu
authored andcommitted
Add vec_all_ge and vec_any_ge
1 parent 64bf5a5 commit e5f2bc3

File tree

1 file changed

+317
-0
lines changed

1 file changed

+317
-0
lines changed

crates/core_arch/src/powerpc/altivec.rs

Lines changed: 317 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,22 @@ extern "C" {
254254

255255
#[link_name = "llvm.ppc.altivec.vcmpeqfp.p"]
256256
fn vcmpeqfp_p(cr: i32, a: vector_float, b: vector_float) -> i32;
257+
258+
#[link_name = "llvm.ppc.altivec.vcmpgtub.p"]
259+
fn vcmpgtub_p(cr: i32, a: vector_unsigned_char, b: vector_unsigned_char) -> i32;
260+
#[link_name = "llvm.ppc.altivec.vcmpgtuh.p"]
261+
fn vcmpgtuh_p(cr: i32, a: vector_unsigned_short, b: vector_unsigned_short) -> i32;
262+
#[link_name = "llvm.ppc.altivec.vcmpgtuw.p"]
263+
fn vcmpgtuw_p(cr: i32, a: vector_unsigned_int, b: vector_unsigned_int) -> i32;
264+
#[link_name = "llvm.ppc.altivec.vcmpgtsb.p"]
265+
fn vcmpgtsb_p(cr: i32, a: vector_signed_char, b: vector_signed_char) -> i32;
266+
#[link_name = "llvm.ppc.altivec.vcmpgtsh.p"]
267+
fn vcmpgtsh_p(cr: i32, a: vector_signed_short, b: vector_signed_short) -> i32;
268+
#[link_name = "llvm.ppc.altivec.vcmpgtsw.p"]
269+
fn vcmpgtsw_p(cr: i32, a: vector_signed_int, b: vector_signed_int) -> i32;
270+
271+
#[link_name = "llvm.ppc.altivec.vcmpgefp.p"]
272+
fn vcmpgefp_p(cr: i32, a: vector_float, b: vector_float) -> i32;
257273
}
258274

259275
macro_rules! s_t_l {
@@ -541,6 +557,143 @@ mod sealed {
541557
}
542558
}
543559

560+
#[inline]
561+
#[target_feature(enable = "altivec")]
562+
#[cfg_attr(test, assert_instr(vcmpgtsb.))]
563+
unsafe fn vcmpgesb_all(a: vector_signed_char, b: vector_signed_char) -> bool {
564+
vcmpgtsb_p(0, b, a) != 0
565+
}
566+
567+
#[inline]
568+
#[target_feature(enable = "altivec")]
569+
#[cfg_attr(test, assert_instr(vcmpgtsb.))]
570+
unsafe fn vcmpgesb_any(a: vector_signed_char, b: vector_signed_char) -> bool {
571+
vcmpgtsb_p(3, b, a) != 0
572+
}
573+
574+
#[inline]
575+
#[target_feature(enable = "altivec")]
576+
#[cfg_attr(test, assert_instr(vcmpgtsh.))]
577+
unsafe fn vcmpgesh_all(a: vector_signed_short, b: vector_signed_short) -> bool {
578+
vcmpgtsh_p(0, b, a) != 0
579+
}
580+
581+
#[inline]
582+
#[target_feature(enable = "altivec")]
583+
#[cfg_attr(test, assert_instr(vcmpgtsh.))]
584+
unsafe fn vcmpgesh_any(a: vector_signed_short, b: vector_signed_short) -> bool {
585+
vcmpgtsh_p(3, b, a) != 0
586+
}
587+
588+
#[inline]
589+
#[target_feature(enable = "altivec")]
590+
#[cfg_attr(test, assert_instr(vcmpgtsw.))]
591+
unsafe fn vcmpgesw_all(a: vector_signed_int, b: vector_signed_int) -> bool {
592+
vcmpgtsw_p(0, b, a) != 0
593+
}
594+
595+
#[inline]
596+
#[target_feature(enable = "altivec")]
597+
#[cfg_attr(test, assert_instr(vcmpgtsw.))]
598+
unsafe fn vcmpgesw_any(a: vector_signed_int, b: vector_signed_int) -> bool {
599+
vcmpgtsw_p(3, b, a) != 0
600+
}
601+
602+
#[inline]
603+
#[target_feature(enable = "altivec")]
604+
#[cfg_attr(test, assert_instr(vcmpgtub.))]
605+
unsafe fn vcmpgeub_all(a: vector_unsigned_char, b: vector_unsigned_char) -> bool {
606+
vcmpgtub_p(0, b, a) != 0
607+
}
608+
609+
#[inline]
610+
#[target_feature(enable = "altivec")]
611+
#[cfg_attr(test, assert_instr(vcmpgtub.))]
612+
unsafe fn vcmpgeub_any(a: vector_unsigned_char, b: vector_unsigned_char) -> bool {
613+
vcmpgtub_p(3, b, a) != 0
614+
}
615+
616+
#[inline]
617+
#[target_feature(enable = "altivec")]
618+
#[cfg_attr(test, assert_instr(vcmpgtuh.))]
619+
unsafe fn vcmpgeuh_all(a: vector_unsigned_short, b: vector_unsigned_short) -> bool {
620+
vcmpgtuh_p(0, b, a) != 0
621+
}
622+
623+
#[inline]
624+
#[target_feature(enable = "altivec")]
625+
#[cfg_attr(test, assert_instr(vcmpgtuh.))]
626+
unsafe fn vcmpgeuh_any(a: vector_unsigned_short, b: vector_unsigned_short) -> bool {
627+
vcmpgtuh_p(3, b, a) != 0
628+
}
629+
630+
#[inline]
631+
#[target_feature(enable = "altivec")]
632+
#[cfg_attr(test, assert_instr(vcmpgtuw.))]
633+
unsafe fn vcmpgeuw_all(a: vector_unsigned_int, b: vector_unsigned_int) -> bool {
634+
vcmpgtuw_p(0, b, a) != 0
635+
}
636+
637+
#[inline]
638+
#[target_feature(enable = "altivec")]
639+
#[cfg_attr(test, assert_instr(vcmpgtuw.))]
640+
unsafe fn vcmpgeuw_any(a: vector_unsigned_int, b: vector_unsigned_int) -> bool {
641+
vcmpgtuw_p(3, b, a) != 0
642+
}
643+
644+
pub trait VectorAllGe<Other> {
645+
type Result;
646+
unsafe fn vec_all_ge(self, b: Other) -> Self::Result;
647+
}
648+
649+
impl_vec_any_all! { [VectorAllGe vec_all_ge] (
650+
vcmpgeub_all, vcmpgesb_all,
651+
vcmpgeuh_all, vcmpgesh_all,
652+
vcmpgeuw_all, vcmpgesw_all
653+
) }
654+
655+
// TODO: vsx encoding
656+
#[inline]
657+
#[target_feature(enable = "altivec")]
658+
#[cfg_attr(test, assert_instr(vcmpgefp.))]
659+
unsafe fn vcmpgefp_all(a: vector_float, b: vector_float) -> bool {
660+
vcmpgefp_p(2, a, b) != 0
661+
}
662+
663+
impl VectorAllGe<vector_float> for vector_float {
664+
type Result = bool;
665+
#[inline]
666+
unsafe fn vec_all_ge(self, b: vector_float) -> Self::Result {
667+
vcmpgefp_all(self, b)
668+
}
669+
}
670+
671+
pub trait VectorAnyGe<Other> {
672+
type Result;
673+
unsafe fn vec_any_ge(self, b: Other) -> Self::Result;
674+
}
675+
676+
impl_vec_any_all! { [VectorAnyGe vec_any_ge] (
677+
vcmpgeub_any, vcmpgesb_any,
678+
vcmpgeuh_any, vcmpgesh_any,
679+
vcmpgeuw_any, vcmpgesw_any
680+
) }
681+
682+
#[inline]
683+
#[target_feature(enable = "altivec")]
684+
#[cfg_attr(test, assert_instr(vcmpgefp.))]
685+
unsafe fn vcmpgefp_any(a: vector_float, b: vector_float) -> bool {
686+
vcmpgefp_p(1, a, b) != 0
687+
}
688+
689+
impl VectorAnyGe<vector_float> for vector_float {
690+
type Result = bool;
691+
#[inline]
692+
unsafe fn vec_any_ge(self, b: vector_float) -> Self::Result {
693+
vcmpgefp_any(self, b)
694+
}
695+
}
696+
544697
test_impl! { vec_vceil(a: vector_float) -> vector_float [vceil, vrfip / xvrspip ] }
545698

546699
test_impl! { vec_vavgsb(a: vector_signed_char, b: vector_signed_char) -> vector_signed_char [ vavgsb, vavgsb ] }
@@ -1846,6 +1999,26 @@ where
18461999
a.vec_any_eq(b)
18472000
}
18482001

2002+
/// Vector All Elements Greater or Equal
2003+
#[inline]
2004+
#[target_feature(enable = "altivec")]
2005+
pub unsafe fn vec_all_ge<T, U>(a: T, b: U) -> <T as sealed::VectorAllGe<U>>::Result
2006+
where
2007+
T: sealed::VectorAllGe<U>,
2008+
{
2009+
a.vec_all_ge(b)
2010+
}
2011+
2012+
/// Vector Any Element Greater or Equal
2013+
#[inline]
2014+
#[target_feature(enable = "altivec")]
2015+
pub unsafe fn vec_any_ge<T, U>(a: T, b: U) -> <T as sealed::VectorAnyGe<U>>::Result
2016+
where
2017+
T: sealed::VectorAnyGe<U>,
2018+
{
2019+
a.vec_any_ge(b)
2020+
}
2021+
18492022
#[cfg(target_endian = "big")]
18502023
mod endian {
18512024
use super::*;
@@ -2212,6 +2385,150 @@ mod tests {
22122385
true
22132386
}
22142387

2388+
test_vec_2! { test_vec_all_ge_i8_false, vec_all_ge, i8x16 -> bool,
2389+
[1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2390+
[0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2391+
false
2392+
}
2393+
2394+
test_vec_2! { test_vec_all_ge_u8_false, vec_all_ge, u8x16 -> bool,
2395+
[1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2396+
[0, 0, 255, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2397+
false
2398+
}
2399+
2400+
test_vec_2! { test_vec_all_ge_i16_false, vec_all_ge, i16x8 -> bool,
2401+
[1, -1, 0, 0, 0, 0, 0, 0],
2402+
[0, 0, -1, 1, 0, 0, 0, 0],
2403+
false
2404+
}
2405+
2406+
test_vec_2! { test_vec_all_ge_u16_false, vec_all_ge, u16x8 -> bool,
2407+
[1, 255, 0, 0, 0, 0, 0, 0],
2408+
[0, 0, 255, 1, 0, 0, 0, 0],
2409+
false
2410+
}
2411+
2412+
test_vec_2! { test_vec_all_ge_i32_false, vec_all_ge, i32x4 -> bool,
2413+
[1, -1, 0, 0],
2414+
[0, -1, 0, 1],
2415+
false
2416+
}
2417+
2418+
test_vec_2! { test_vec_all_ge_u32_false, vec_all_ge, u32x4 -> bool,
2419+
[1, 255, 0, 0],
2420+
[0, 255, 1, 1],
2421+
false
2422+
}
2423+
2424+
test_vec_2! { test_vec_all_ge_i8_true, vec_all_ge, i8x16 -> bool,
2425+
[0, 0, -1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
2426+
[0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2427+
true
2428+
}
2429+
2430+
test_vec_2! { test_vec_all_ge_u8_true, vec_all_ge, u8x16 -> bool,
2431+
[1, 255, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2432+
[1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2433+
true
2434+
}
2435+
2436+
test_vec_2! { test_vec_all_ge_i16_true, vec_all_ge, i16x8 -> bool,
2437+
[1, -1, 42, 0, 0, 0, 0, 0],
2438+
[1, -5, 2, 0, 0, 0, 0, 0],
2439+
true
2440+
}
2441+
2442+
test_vec_2! { test_vec_all_ge_u16_true, vec_all_ge, u16x8 -> bool,
2443+
[42, 255, 1, 0, 0, 0, 0, 0],
2444+
[2, 255, 1, 0, 0, 0, 0, 0],
2445+
true
2446+
}
2447+
2448+
test_vec_2! { test_vec_all_ge_i32_true, vec_all_ge, i32x4 -> bool,
2449+
[1, -1, 0, 1],
2450+
[0, -1, 0, 1],
2451+
true
2452+
}
2453+
2454+
test_vec_2! { test_vec_all_ge_u32_true, vec_all_ge, u32x4 -> bool,
2455+
[1, 255, 0, 1],
2456+
[1, 254, 0, 0],
2457+
true
2458+
}
2459+
2460+
test_vec_2! { test_vec_any_ge_i8_false, vec_any_ge, i8x16 -> bool,
2461+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2462+
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
2463+
false
2464+
}
2465+
2466+
test_vec_2! { test_vec_any_ge_u8_false, vec_any_ge, u8x16 -> bool,
2467+
[1, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2468+
[42, 255, 255, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
2469+
false
2470+
}
2471+
2472+
test_vec_2! { test_vec_any_ge_i16_false, vec_any_ge, i16x8 -> bool,
2473+
[1, -1, -2, 0, 0, 0, 0, 0],
2474+
[2, 0, -1, 1, 1, 1, 1, 1],
2475+
false
2476+
}
2477+
2478+
test_vec_2! { test_vec_any_ge_u16_false, vec_any_ge, u16x8 -> bool,
2479+
[1, 2, 0, 0, 0, 0, 0, 0],
2480+
[2, 42, 255, 1, 1, 1, 1, 1],
2481+
false
2482+
}
2483+
2484+
test_vec_2! { test_vec_any_ge_i32_false, vec_any_ge, i32x4 -> bool,
2485+
[1, -1, 0, 0],
2486+
[2, 0, 1, 1],
2487+
false
2488+
}
2489+
2490+
test_vec_2! { test_vec_any_ge_u32_false, vec_any_ge, u32x4 -> bool,
2491+
[1, 2, 1, 0],
2492+
[4, 255, 4, 1],
2493+
false
2494+
}
2495+
2496+
test_vec_2! { test_vec_any_ge_i8_true, vec_any_ge, i8x16 -> bool,
2497+
[1, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2498+
[0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2499+
true
2500+
}
2501+
2502+
test_vec_2! { test_vec_any_ge_u8_true, vec_any_ge, u8x16 -> bool,
2503+
[0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2504+
[1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
2505+
true
2506+
}
2507+
2508+
test_vec_2! { test_vec_any_ge_i16_true, vec_any_ge, i16x8 -> bool,
2509+
[0, -1, 1, 0, 0, 0, 0, 0],
2510+
[1, -1, 1, 0, 0, 0, 0, 0],
2511+
true
2512+
}
2513+
2514+
test_vec_2! { test_vec_any_ge_u16_true, vec_any_ge, u16x8 -> bool,
2515+
[0, 255, 1, 0, 0, 0, 0, 0],
2516+
[1, 255, 1, 0, 0, 0, 0, 0],
2517+
true
2518+
}
2519+
2520+
test_vec_2! { test_vec_any_ge_i32_true, vec_any_ge, i32x4 -> bool,
2521+
[0, -1, 0, 1],
2522+
[1, -1, 0, 1],
2523+
true
2524+
}
2525+
2526+
test_vec_2! { test_vec_any_ge_u32_true, vec_any_ge, u32x4 -> bool,
2527+
[0, 255, 0, 1],
2528+
[1, 255, 0, 1],
2529+
true
2530+
}
2531+
22152532
#[simd_test(enable = "altivec")]
22162533
unsafe fn test_vec_cmpb() {
22172534
let a: vector_float = transmute(f32x4::new(0.1, 0.5, 0.6, 0.9));

0 commit comments

Comments
 (0)