Skip to content

Commit 4a12559

Browse files
folkertdevAmanieu
authored andcommitted
add vec_all_nan, vec_any_nan, vec_all_numeric and vec_any_numeric
1 parent 8eb2b52 commit 4a12559

File tree

1 file changed

+88
-8
lines changed

1 file changed

+88
-8
lines changed

crates/core_arch/src/s390x/vector.rs

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,7 +2862,7 @@ mod sealed {
28622862
#[unstable(feature = "stdarch_s390x", issue = "135681")]
28632863
pub trait VectorFpTestDataClass {
28642864
type Result;
2865-
unsafe fn vec_fp_test_data_class<const CLASS: u32>(self, ptr: *mut i32) -> Self::Result;
2865+
unsafe fn vec_fp_test_data_class<const CLASS: u32>(self) -> (Self::Result, i32);
28662866
}
28672867

28682868
#[unstable(feature = "stdarch_s390x", issue = "135681")]
@@ -2871,10 +2871,9 @@ mod sealed {
28712871

28722872
#[inline]
28732873
#[target_feature(enable = "vector")]
2874-
unsafe fn vec_fp_test_data_class<const CLASS: u32>(self, ptr: *mut i32) -> Self::Result {
2874+
unsafe fn vec_fp_test_data_class<const CLASS: u32>(self) -> (Self::Result, i32) {
28752875
let PackedTuple { x, y } = vftcisb(self, CLASS);
2876-
unsafe { ptr.write(y) };
2877-
x
2876+
(x, y)
28782877
}
28792878
}
28802879

@@ -2884,10 +2883,9 @@ mod sealed {
28842883

28852884
#[inline]
28862885
#[target_feature(enable = "vector")]
2887-
unsafe fn vec_fp_test_data_class<const CLASS: u32>(self, ptr: *mut i32) -> Self::Result {
2886+
unsafe fn vec_fp_test_data_class<const CLASS: u32>(self) -> (Self::Result, i32) {
28882887
let PackedTuple { x, y } = vftcidb(self, CLASS);
2889-
unsafe { ptr.write(y) };
2890-
x
2888+
(x, y)
28912889
}
28922890
}
28932891

@@ -4800,7 +4798,37 @@ pub unsafe fn vec_fp_test_data_class<T: sealed::VectorFpTestDataClass, const CLA
48004798
a: T,
48014799
c: *mut i32,
48024800
) -> T::Result {
4803-
a.vec_fp_test_data_class::<CLASS>(c)
4801+
let (x, y) = a.vec_fp_test_data_class::<CLASS>();
4802+
c.write(y);
4803+
x
4804+
}
4805+
4806+
#[inline]
4807+
#[target_feature(enable = "vector")]
4808+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
4809+
pub unsafe fn vec_all_nan<T: sealed::VectorFpTestDataClass>(a: T) -> i32 {
4810+
i32::from(a.vec_fp_test_data_class::<__VEC_CLASS_FP_NAN>().1 == 0)
4811+
}
4812+
4813+
#[inline]
4814+
#[target_feature(enable = "vector")]
4815+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
4816+
pub unsafe fn vec_all_numeric<T: sealed::VectorFpTestDataClass>(a: T) -> i32 {
4817+
i32::from(a.vec_fp_test_data_class::<__VEC_CLASS_FP_NAN>().1 == 3)
4818+
}
4819+
4820+
#[inline]
4821+
#[target_feature(enable = "vector")]
4822+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
4823+
pub unsafe fn vec_any_nan<T: sealed::VectorFpTestDataClass>(a: T) -> i32 {
4824+
i32::from(a.vec_fp_test_data_class::<__VEC_CLASS_FP_NAN>().1 != 3)
4825+
}
4826+
4827+
#[inline]
4828+
#[target_feature(enable = "vector")]
4829+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
4830+
pub unsafe fn vec_any_numeric<T: sealed::VectorFpTestDataClass>(a: T) -> i32 {
4831+
i32::from(a.vec_fp_test_data_class::<__VEC_CLASS_FP_NAN>().1 != 0)
48044832
}
48054833

48064834
/// Vector Test under Mask
@@ -6257,6 +6285,58 @@ mod tests {
62576285
}
62586286
}
62596287

6288+
#[simd_test(enable = "vector")]
6289+
fn test_vec_fp_any_all_nan_numeric() {
6290+
unsafe {
6291+
assert_eq!(
6292+
vec_all_nan(vector_double([f64::NAN, f64::NAN])),
6293+
i32::from(true)
6294+
);
6295+
assert_eq!(
6296+
vec_all_nan(vector_double([f64::NAN, 1.0])),
6297+
i32::from(false)
6298+
);
6299+
assert_eq!(vec_all_nan(vector_double([0.0, 1.0])), i32::from(false));
6300+
6301+
assert_eq!(
6302+
vec_any_nan(vector_double([f64::NAN, f64::NAN])),
6303+
i32::from(true)
6304+
);
6305+
assert_eq!(vec_any_nan(vector_double([f64::NAN, 1.0])), i32::from(true));
6306+
assert_eq!(vec_any_nan(vector_double([0.0, 1.0])), i32::from(false));
6307+
6308+
assert_eq!(
6309+
vec_all_numeric(vector_double([f64::NAN, f64::NAN])),
6310+
i32::from(false)
6311+
);
6312+
assert_eq!(
6313+
vec_all_numeric(vector_double([f64::NAN, 1.0])),
6314+
i32::from(false)
6315+
);
6316+
assert_eq!(vec_all_numeric(vector_double([0.0, 1.0])), i32::from(true));
6317+
6318+
assert_eq!(
6319+
vec_any_numeric(vector_double([f64::NAN, f64::NAN])),
6320+
i32::from(false)
6321+
);
6322+
assert_eq!(
6323+
vec_any_numeric(vector_double([f64::NAN, 1.0])),
6324+
i32::from(true)
6325+
);
6326+
assert_eq!(vec_any_numeric(vector_double([0.0, 1.0])), i32::from(true));
6327+
6328+
// "numeric" means "not NaN". infinities are numeric
6329+
assert_eq!(
6330+
vec_all_numeric(vector_double([f64::INFINITY, f64::NEG_INFINITY])),
6331+
i32::from(true)
6332+
);
6333+
assert_eq!(
6334+
vec_any_numeric(vector_double([f64::INFINITY, f64::NEG_INFINITY])),
6335+
i32::from(true)
6336+
);
6337+
}
6338+
}
6339+
62606340
#[simd_test(enable = "vector")]
62616341
fn test_vec_test_mask() {
62626342
unsafe {

0 commit comments

Comments
 (0)