Skip to content

Commit f8e7af9

Browse files
lu-zeroAmanieu
authored andcommitted
Add vec_all_nan, vec_all_ne and vec_any_ne
1 parent 01352d2 commit f8e7af9

File tree

1 file changed

+262
-0
lines changed

1 file changed

+262
-0
lines changed

crates/core_arch/src/powerpc/altivec.rs

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,95 @@ mod sealed {
839839
}
840840
}
841841

842+
// All/Any Elements Not Equal
843+
844+
#[inline]
845+
#[target_feature(enable = "altivec")]
846+
#[cfg_attr(test, assert_instr(vcmpequb.))]
847+
unsafe fn vcmpneub_all(a: vector_unsigned_char, b: vector_unsigned_char) -> bool {
848+
vcmpequb_p(0, a, b) != 0
849+
}
850+
851+
#[inline]
852+
#[target_feature(enable = "altivec")]
853+
#[cfg_attr(test, assert_instr(vcmpequb.))]
854+
unsafe fn vcmpneub_any(a: vector_unsigned_char, b: vector_unsigned_char) -> bool {
855+
vcmpequb_p(3, a, b) != 0
856+
}
857+
858+
#[inline]
859+
#[target_feature(enable = "altivec")]
860+
#[cfg_attr(test, assert_instr(vcmpequh.))]
861+
unsafe fn vcmpneuh_all(a: vector_unsigned_short, b: vector_unsigned_short) -> bool {
862+
vcmpequh_p(0, a, b) != 0
863+
}
864+
865+
#[inline]
866+
#[target_feature(enable = "altivec")]
867+
#[cfg_attr(test, assert_instr(vcmpequh.))]
868+
unsafe fn vcmpneuh_any(a: vector_unsigned_short, b: vector_unsigned_short) -> bool {
869+
vcmpequh_p(3, a, b) != 0
870+
}
871+
872+
#[inline]
873+
#[target_feature(enable = "altivec")]
874+
#[cfg_attr(test, assert_instr(vcmpequw.))]
875+
unsafe fn vcmpneuw_all(a: vector_unsigned_int, b: vector_unsigned_int) -> bool {
876+
vcmpequw_p(0, a, b) != 0
877+
}
878+
879+
#[inline]
880+
#[target_feature(enable = "altivec")]
881+
#[cfg_attr(test, assert_instr(vcmpequw.))]
882+
unsafe fn vcmpneuw_any(a: vector_unsigned_int, b: vector_unsigned_int) -> bool {
883+
vcmpequw_p(3, a, b) != 0
884+
}
885+
886+
pub trait VectorAllNe<Other> {
887+
type Result;
888+
unsafe fn vec_all_ne(self, b: Other) -> Self::Result;
889+
}
890+
891+
impl_vec_any_all! { [VectorAllNe vec_all_ne] (vcmpneub_all, vcmpneuh_all, vcmpneuw_all) }
892+
893+
// TODO: vsx encoding
894+
#[inline]
895+
#[target_feature(enable = "altivec")]
896+
#[cfg_attr(test, assert_instr(vcmpeqfp.))]
897+
unsafe fn vcmpnefp_all(a: vector_float, b: vector_float) -> bool {
898+
vcmpeqfp_p(0, a, b) != 0
899+
}
900+
901+
impl VectorAllNe<vector_float> for vector_float {
902+
type Result = bool;
903+
#[inline]
904+
unsafe fn vec_all_ne(self, b: vector_float) -> Self::Result {
905+
vcmpnefp_all(self, b)
906+
}
907+
}
908+
909+
pub trait VectorAnyNe<Other> {
910+
type Result;
911+
unsafe fn vec_any_ne(self, b: Other) -> Self::Result;
912+
}
913+
914+
impl_vec_any_all! { [VectorAnyNe vec_any_ne] (vcmpneub_any, vcmpneuh_any, vcmpneuw_any) }
915+
916+
#[inline]
917+
#[target_feature(enable = "altivec")]
918+
#[cfg_attr(test, assert_instr(vcmpeqfp.))]
919+
unsafe fn vcmpnefp_any(a: vector_float, b: vector_float) -> bool {
920+
vcmpeqfp_p(3, a, b) != 0
921+
}
922+
923+
impl VectorAnyNe<vector_float> for vector_float {
924+
type Result = bool;
925+
#[inline]
926+
unsafe fn vec_any_ne(self, b: vector_float) -> Self::Result {
927+
vcmpnefp_any(self, b)
928+
}
929+
}
930+
842931
test_impl! { vec_vceil(a: vector_float) -> vector_float [vceil, vrfip / xvrspip ] }
843932

844933
test_impl! { vec_vavgsb(a: vector_signed_char, b: vector_signed_char) -> vector_signed_char [ vavgsb, vavgsb ] }
@@ -2231,6 +2320,35 @@ where
22312320
{
22322321
b.vec_any_gt(a)
22332322
}
2323+
2324+
/// All Elements Not a Number
2325+
#[inline]
2326+
#[target_feature(enable = "altivec")]
2327+
#[cfg_attr(test, assert_instr("vcmpeqfp."))]
2328+
pub unsafe fn vec_all_nan(a: vector_float) -> bool {
2329+
vcmpeqfp_p(0, a, a) != 0
2330+
}
2331+
2332+
/// Vector All Elements Not Equal
2333+
#[inline]
2334+
#[target_feature(enable = "altivec")]
2335+
pub unsafe fn vec_all_ne<T, U>(a: T, b: U) -> <T as sealed::VectorAllNe<U>>::Result
2336+
where
2337+
T: sealed::VectorAllNe<U>,
2338+
{
2339+
a.vec_all_ne(b)
2340+
}
2341+
2342+
/// Vector Any Elements Not Equal
2343+
#[inline]
2344+
#[target_feature(enable = "altivec")]
2345+
pub unsafe fn vec_any_ne<T, U>(a: T, b: U) -> <T as sealed::VectorAnyNe<U>>::Result
2346+
where
2347+
T: sealed::VectorAnyNe<U>,
2348+
{
2349+
a.vec_any_ne(b)
2350+
}
2351+
22342352
#[cfg(target_endian = "big")]
22352353
mod endian {
22362354
use super::*;
@@ -3185,6 +3303,150 @@ mod tests {
31853303
true
31863304
}
31873305

3306+
test_vec_2! { test_vec_all_ne_i8_false, vec_all_ne, i8x16 -> bool,
3307+
[1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3308+
[0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3309+
false
3310+
}
3311+
3312+
test_vec_2! { test_vec_all_ne_u8_false, vec_all_ne, u8x16 -> bool,
3313+
[1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3314+
[0, 0, 255, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3315+
false
3316+
}
3317+
3318+
test_vec_2! { test_vec_all_ne_i16_false, vec_all_ne, i16x8 -> bool,
3319+
[1, -1, 0, 0, 0, 0, 0, 0],
3320+
[0, -1, 1, 0, 0, 0, 0, 0],
3321+
false
3322+
}
3323+
3324+
test_vec_2! { test_vec_all_ne_u16_false, vec_all_ne, u16x8 -> bool,
3325+
[1, 255, 0, 0, 0, 0, 0, 0],
3326+
[0, 255, 0, 1, 0, 0, 0, 0],
3327+
false
3328+
}
3329+
3330+
test_vec_2! { test_vec_all_ne_i32_false, vec_all_ne, i32x4 -> bool,
3331+
[1, -1, 0, 0],
3332+
[0, -1, 0, 1],
3333+
false
3334+
}
3335+
3336+
test_vec_2! { test_vec_all_ne_u32_false, vec_all_ne, u32x4 -> bool,
3337+
[1, 255, 0, 0],
3338+
[0, 255, 0, 1],
3339+
false
3340+
}
3341+
3342+
test_vec_2! { test_vec_all_ne_i8_true, vec_all_ne, i8x16 -> bool,
3343+
[0, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
3344+
[1, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3345+
true
3346+
}
3347+
3348+
test_vec_2! { test_vec_all_ne_u8_true, vec_all_ne, u8x16 -> bool,
3349+
[0, 254, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
3350+
[1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3351+
true
3352+
}
3353+
3354+
test_vec_2! { test_vec_all_ne_i16_true, vec_all_ne, i16x8 -> bool,
3355+
[2, -2, 0, 1, 1, 1, 1, 1],
3356+
[1, -1, 1, 0, 0, 0, 0, 0],
3357+
true
3358+
}
3359+
3360+
test_vec_2! { test_vec_all_ne_u16_true, vec_all_ne, u16x8 -> bool,
3361+
[0, 254, 1, 1, 0, 0, 1, 0],
3362+
[1, 255, 0, 0, 1, 1, 0, 1],
3363+
true
3364+
}
3365+
3366+
test_vec_2! { test_vec_all_ne_i32_true, vec_all_ne, i32x4 -> bool,
3367+
[0, -2, 0, 0],
3368+
[1, -1, 1, 1],
3369+
true
3370+
}
3371+
3372+
test_vec_2! { test_vec_all_ne_u32_true, vec_all_ne, u32x4 -> bool,
3373+
[1, 255, 0, 0],
3374+
[0, 254, 1, 1],
3375+
true
3376+
}
3377+
3378+
test_vec_2! { test_vec_any_ne_i8_false, vec_any_ne, i8x16 -> bool,
3379+
[1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3380+
[1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3381+
false
3382+
}
3383+
3384+
test_vec_2! { test_vec_any_ne_u8_false, vec_any_ne, u8x16 -> bool,
3385+
[1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3386+
[1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3387+
false
3388+
}
3389+
3390+
test_vec_2! { test_vec_any_ne_i16_false, vec_any_ne, i16x8 -> bool,
3391+
[1, -1, 0, 0, 0, 0, 0, 0],
3392+
[1, -1, 0, 0, 0, 0, 0, 0],
3393+
false
3394+
}
3395+
3396+
test_vec_2! { test_vec_any_ne_u16_false, vec_any_ne, u16x8 -> bool,
3397+
[1, 255, 1, 1, 1, 1, 1, 0],
3398+
[1, 255, 1, 1, 1, 1, 1, 0],
3399+
false
3400+
}
3401+
3402+
test_vec_2! { test_vec_any_ne_i32_false, vec_any_ne, i32x4 -> bool,
3403+
[0, -1, 1, 1],
3404+
[0, -1, 1, 1],
3405+
false
3406+
}
3407+
3408+
test_vec_2! { test_vec_any_ne_u32_false, vec_any_ne, u32x4 -> bool,
3409+
[1, 2, 1, 255],
3410+
[1, 2, 1, 255],
3411+
false
3412+
}
3413+
3414+
test_vec_2! { test_vec_any_ne_i8_true, vec_any_ne, i8x16 -> bool,
3415+
[1, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3416+
[0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3417+
true
3418+
}
3419+
3420+
test_vec_2! { test_vec_any_ne_u8_true, vec_any_ne, u8x16 -> bool,
3421+
[0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3422+
[1, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
3423+
true
3424+
}
3425+
3426+
test_vec_2! { test_vec_any_ne_i16_true, vec_any_ne, i16x8 -> bool,
3427+
[0, -1, 1, 0, 0, 0, 0, 0],
3428+
[1, -1, 1, 0, 0, 0, 0, 0],
3429+
true
3430+
}
3431+
3432+
test_vec_2! { test_vec_any_ne_u16_true, vec_any_ne, u16x8 -> bool,
3433+
[0, 255, 1, 0, 0, 0, 0, 0],
3434+
[1, 255, 1, 0, 0, 0, 0, 0],
3435+
true
3436+
}
3437+
3438+
test_vec_2! { test_vec_any_ne_i32_true, vec_any_ne, i32x4 -> bool,
3439+
[0, -1, 0, 1],
3440+
[1, -1, 0, 1],
3441+
true
3442+
}
3443+
3444+
test_vec_2! { test_vec_any_ne_u32_true, vec_any_ne, u32x4 -> bool,
3445+
[0, 255, 0, 1],
3446+
[1, 255, 0, 1],
3447+
true
3448+
}
3449+
31883450
#[simd_test(enable = "altivec")]
31893451
unsafe fn test_vec_cmpb() {
31903452
let a: vector_float = transmute(f32x4::new(0.1, 0.5, 0.6, 0.9));

0 commit comments

Comments
 (0)