about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2021-02-13 14:19:16 -0500
committerCaleb Zulawski <caleb.zulawski@gmail.com>2021-02-15 18:22:56 -0500
commit0ec3ecfab15fe5baf45cfd452c2317a7f18f69bd (patch)
treeb18db1ef1670a0f22079d2f610b7b2ff65a9f58f
parent976fafcf4fb8008255ce57bc62738a46f8a9152f (diff)
downloadrust-0ec3ecfab15fe5baf45cfd452c2317a7f18f69bd.tar.gz
rust-0ec3ecfab15fe5baf45cfd452c2317a7f18f69bd.zip
Split ops tests
-rw-r--r--crates/core_simd/tests/f32_ops.rs4
-rw-r--r--crates/core_simd/tests/f64_ops.rs4
-rw-r--r--crates/core_simd/tests/float.rs139
-rw-r--r--crates/core_simd/tests/i128_ops.rs4
-rw-r--r--crates/core_simd/tests/i16_ops.rs4
-rw-r--r--crates/core_simd/tests/i32_ops.rs4
-rw-r--r--crates/core_simd/tests/i64_ops.rs4
-rw-r--r--crates/core_simd/tests/i8_ops.rs4
-rw-r--r--crates/core_simd/tests/isize_ops.rs4
-rw-r--r--crates/core_simd/tests/ops_macros.rs (renamed from crates/core_simd/tests/integer.rs)94
-rw-r--r--crates/core_simd/tests/u128_ops.rs4
-rw-r--r--crates/core_simd/tests/u16_ops.rs4
-rw-r--r--crates/core_simd/tests/u32_ops.rs4
-rw-r--r--crates/core_simd/tests/u64_ops.rs4
-rw-r--r--crates/core_simd/tests/u8_ops.rs4
-rw-r--r--crates/core_simd/tests/usize_ops.rs4
16 files changed, 137 insertions, 152 deletions
diff --git a/crates/core_simd/tests/f32_ops.rs b/crates/core_simd/tests/f32_ops.rs
new file mode 100644
index 00000000000..6e3802aae6a
--- /dev/null
+++ b/crates/core_simd/tests/f32_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_float_tests! { SimdF32, f32, i32 }
diff --git a/crates/core_simd/tests/f64_ops.rs b/crates/core_simd/tests/f64_ops.rs
new file mode 100644
index 00000000000..da31cc3161b
--- /dev/null
+++ b/crates/core_simd/tests/f64_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_float_tests! { SimdF64, f64, i64 }
diff --git a/crates/core_simd/tests/float.rs b/crates/core_simd/tests/float.rs
deleted file mode 100644
index 618a75250bd..00000000000
--- a/crates/core_simd/tests/float.rs
+++ /dev/null
@@ -1,139 +0,0 @@
-macro_rules! impl_op_test {
-    { unary, $vector:ty, $scalar:ty, $trait:ident :: $fn:ident } => {
-        test_helpers::test_lanes! {
-            fn $fn<const LANES: usize>() {
-                test_helpers::test_unary_elementwise(
-                    &<$vector as core::ops::$trait>::$fn,
-                    &<$scalar as core::ops::$trait>::$fn,
-                    &|_| true,
-                );
-            }
-        }
-    };
-    { binary, $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident } => {
-        mod $fn {
-            use super::*;
-
-            test_helpers::test_lanes! {
-                fn normal<const LANES: usize>() {
-                    test_helpers::test_binary_elementwise(
-                        &<$vector as core::ops::$trait>::$fn,
-                        &<$scalar as core::ops::$trait>::$fn,
-                        &|_, _| true,
-                    );
-                }
-
-                fn scalar_rhs<const LANES: usize>() {
-                    test_helpers::test_binary_scalar_rhs_elementwise(
-                        &<$vector as core::ops::$trait<$scalar>>::$fn,
-                        &<$scalar as core::ops::$trait>::$fn,
-                        &|_, _| true,
-                    );
-                }
-
-                fn scalar_lhs<const LANES: usize>() {
-                    test_helpers::test_binary_scalar_lhs_elementwise(
-                        &<$scalar as core::ops::$trait<$vector>>::$fn,
-                        &<$scalar as core::ops::$trait>::$fn,
-                        &|_, _| true,
-                    );
-                }
-
-                fn assign<const LANES: usize>() {
-                    test_helpers::test_binary_elementwise(
-                        &|mut a, b| { <$vector as core::ops::$trait_assign>::$fn_assign(&mut a, b); a },
-                        &|mut a, b| { <$scalar as core::ops::$trait_assign>::$fn_assign(&mut a, b); a },
-                        &|_, _| true,
-                    )
-                }
-
-                fn assign_scalar_rhs<const LANES: usize>() {
-                    test_helpers::test_binary_scalar_rhs_elementwise(
-                        &|mut a, b| { <$vector as core::ops::$trait_assign<$scalar>>::$fn_assign(&mut a, b); a },
-                        &|mut a, b| { <$scalar as core::ops::$trait_assign>::$fn_assign(&mut a, b); a },
-                        &|_, _| true,
-                    )
-                }
-            }
-        }
-    };
-}
-
-macro_rules! impl_tests {
-    { $vector:ident, $scalar:tt, $int_scalar:tt } => {
-        mod $scalar {
-            type Vector<const LANES: usize> = core_simd::$vector<LANES>;
-            type Scalar = $scalar;
-            type IntScalar = $int_scalar;
-
-            impl_op_test! { unary, Vector<LANES>, Scalar, Neg::neg }
-            impl_op_test! { binary, Vector<LANES>, Scalar, Add::add, AddAssign::add_assign }
-            impl_op_test! { binary, Vector<LANES>, Scalar, Sub::sub, SubAssign::sub_assign }
-            impl_op_test! { binary, Vector<LANES>, Scalar, Mul::mul, SubAssign::sub_assign }
-            impl_op_test! { binary, Vector<LANES>, Scalar, Div::div, DivAssign::div_assign }
-            impl_op_test! { binary, Vector<LANES>, Scalar, Rem::rem, RemAssign::rem_assign }
-
-            test_helpers::test_lanes! {
-                fn abs<const LANES: usize>() {
-                    test_helpers::test_unary_elementwise(
-                        &Vector::<LANES>::abs,
-                        &Scalar::abs,
-                        &|_| true,
-                    )
-                }
-
-                fn ceil<const LANES: usize>() {
-                    test_helpers::test_unary_elementwise(
-                        &Vector::<LANES>::ceil,
-                        &Scalar::ceil,
-                        &|_| true,
-                    )
-                }
-
-                fn floor<const LANES: usize>() {
-                    test_helpers::test_unary_elementwise(
-                        &Vector::<LANES>::floor,
-                        &Scalar::floor,
-                        &|_| true,
-                    )
-                }
-
-                fn round_from_int<const LANES: usize>() {
-                    test_helpers::test_unary_elementwise(
-                        &Vector::<LANES>::round_from_int,
-                        &|x| x as Scalar,
-                        &|_| true,
-                    )
-                }
-
-                fn to_int_unchecked<const LANES: usize>() {
-                    // The maximum integer that can be represented by the equivalently sized float has
-                    // all of the mantissa digits set to 1, pushed up to the MSB.
-                    const ALL_MANTISSA_BITS: IntScalar = ((1 << <Scalar>::MANTISSA_DIGITS) - 1);
-                    const MAX_REPRESENTABLE_VALUE: Scalar =
-                        (ALL_MANTISSA_BITS << (core::mem::size_of::<Scalar>() * 8 - <Scalar>::MANTISSA_DIGITS as usize - 1)) as Scalar;
-
-                    let mut runner = proptest::test_runner::TestRunner::default();
-                    runner.run(
-                        &test_helpers::array::UniformArrayStrategy::new(-MAX_REPRESENTABLE_VALUE..MAX_REPRESENTABLE_VALUE),
-                        |x| {
-                            let result_1 = unsafe { Vector::from_array(x).to_int_unchecked().to_array() };
-                            let result_2 = {
-                                let mut result = [0; LANES];
-                                for (i, o) in x.iter().zip(result.iter_mut()) {
-                                    *o = unsafe { i.to_int_unchecked() };
-                                }
-                                result
-                            };
-                            test_helpers::prop_assert_biteq!(result_1, result_2);
-                            Ok(())
-                        },
-                    ).unwrap();
-                }
-            }
-        }
-    }
-}
-
-impl_tests! { SimdF32, f32, i32 }
-impl_tests! { SimdF64, f64, i64 }
diff --git a/crates/core_simd/tests/i128_ops.rs b/crates/core_simd/tests/i128_ops.rs
new file mode 100644
index 00000000000..874324463cf
--- /dev/null
+++ b/crates/core_simd/tests/i128_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_signed_tests! { SimdI128, i128 }
diff --git a/crates/core_simd/tests/i16_ops.rs b/crates/core_simd/tests/i16_ops.rs
new file mode 100644
index 00000000000..ebdbf60bce4
--- /dev/null
+++ b/crates/core_simd/tests/i16_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_signed_tests! { SimdI16, i16 }
diff --git a/crates/core_simd/tests/i32_ops.rs b/crates/core_simd/tests/i32_ops.rs
new file mode 100644
index 00000000000..5c2c41cdb18
--- /dev/null
+++ b/crates/core_simd/tests/i32_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_signed_tests! { SimdI32, i32 }
diff --git a/crates/core_simd/tests/i64_ops.rs b/crates/core_simd/tests/i64_ops.rs
new file mode 100644
index 00000000000..9321755d671
--- /dev/null
+++ b/crates/core_simd/tests/i64_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_signed_tests! { SimdI64, i64 }
diff --git a/crates/core_simd/tests/i8_ops.rs b/crates/core_simd/tests/i8_ops.rs
new file mode 100644
index 00000000000..bea49c3a646
--- /dev/null
+++ b/crates/core_simd/tests/i8_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_signed_tests! { SimdI8, i8 }
diff --git a/crates/core_simd/tests/isize_ops.rs b/crates/core_simd/tests/isize_ops.rs
new file mode 100644
index 00000000000..5ec29f23273
--- /dev/null
+++ b/crates/core_simd/tests/isize_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_signed_tests! { SimdIsize, isize }
diff --git a/crates/core_simd/tests/integer.rs b/crates/core_simd/tests/ops_macros.rs
index 33612628356..dc920c649d5 100644
--- a/crates/core_simd/tests/integer.rs
+++ b/crates/core_simd/tests/ops_macros.rs
@@ -1,3 +1,4 @@
+#[macro_export]
 macro_rules! impl_unary_op_test {
     { $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $scalar_fn:expr } => {
         test_helpers::test_lanes! {
@@ -15,6 +16,7 @@ macro_rules! impl_unary_op_test {
     };
 }
 
+#[macro_export]
 macro_rules! impl_binary_op_test {
     { $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident, $scalar_fn:expr } => {
         mod $fn {
@@ -68,6 +70,7 @@ macro_rules! impl_binary_op_test {
     };
 }
 
+#[macro_export]
 macro_rules! impl_binary_checked_op_test {
     { $vector:ty, $scalar:ty, $trait:ident :: $fn:ident, $trait_assign:ident :: $fn_assign:ident, $scalar_fn:expr, $check_fn:expr } => {
         mod $fn {
@@ -121,6 +124,7 @@ macro_rules! impl_binary_checked_op_test {
     };
 }
 
+#[macro_export]
 macro_rules! impl_signed_tests {
     { $vector:ident, $scalar:tt } => {
         mod $scalar {
@@ -151,6 +155,7 @@ macro_rules! impl_signed_tests {
     }
 }
 
+#[macro_export]
 macro_rules! impl_unsigned_tests {
     { $vector:ident, $scalar:tt } => {
         mod $scalar {
@@ -171,16 +176,79 @@ macro_rules! impl_unsigned_tests {
     }
 }
 
-impl_signed_tests! { SimdI8, i8 }
-impl_signed_tests! { SimdI16, i16 }
-impl_signed_tests! { SimdI32, i32 }
-impl_signed_tests! { SimdI64, i64 }
-impl_signed_tests! { SimdI128, i128 }
-impl_signed_tests! { SimdIsize, isize }
-
-impl_unsigned_tests! { SimdU8, u8 }
-impl_unsigned_tests! { SimdU16, u16 }
-impl_unsigned_tests! { SimdU32, u32 }
-impl_unsigned_tests! { SimdU64, u64 }
-impl_unsigned_tests! { SimdU128, u128 }
-impl_unsigned_tests! { SimdUsize, usize }
+#[macro_export]
+macro_rules! impl_float_tests {
+    { $vector:ident, $scalar:tt, $int_scalar:tt } => {
+        mod $scalar {
+            type Vector<const LANES: usize> = core_simd::$vector<LANES>;
+            type Scalar = $scalar;
+            type IntScalar = $int_scalar;
+
+            impl_unary_op_test!(Vector<LANES>, Scalar, Neg::neg);
+            impl_binary_op_test!(Vector<LANES>, Scalar, Add::add, AddAssign::add_assign);
+            impl_binary_op_test!(Vector<LANES>, Scalar, Sub::sub, SubAssign::sub_assign);
+            impl_binary_op_test!(Vector<LANES>, Scalar, Mul::mul, SubAssign::sub_assign);
+            impl_binary_op_test!(Vector<LANES>, Scalar, Div::div, DivAssign::div_assign);
+            impl_binary_op_test!(Vector<LANES>, Scalar, Rem::rem, RemAssign::rem_assign);
+
+            test_helpers::test_lanes! {
+                fn abs<const LANES: usize>() {
+                    test_helpers::test_unary_elementwise(
+                        &Vector::<LANES>::abs,
+                        &Scalar::abs,
+                        &|_| true,
+                    )
+                }
+
+                fn ceil<const LANES: usize>() {
+                    test_helpers::test_unary_elementwise(
+                        &Vector::<LANES>::ceil,
+                        &Scalar::ceil,
+                        &|_| true,
+                    )
+                }
+
+                fn floor<const LANES: usize>() {
+                    test_helpers::test_unary_elementwise(
+                        &Vector::<LANES>::floor,
+                        &Scalar::floor,
+                        &|_| true,
+                    )
+                }
+
+                fn round_from_int<const LANES: usize>() {
+                    test_helpers::test_unary_elementwise(
+                        &Vector::<LANES>::round_from_int,
+                        &|x| x as Scalar,
+                        &|_| true,
+                    )
+                }
+
+                fn to_int_unchecked<const LANES: usize>() {
+                    // The maximum integer that can be represented by the equivalently sized float has
+                    // all of the mantissa digits set to 1, pushed up to the MSB.
+                    const ALL_MANTISSA_BITS: IntScalar = ((1 << <Scalar>::MANTISSA_DIGITS) - 1);
+                    const MAX_REPRESENTABLE_VALUE: Scalar =
+                        (ALL_MANTISSA_BITS << (core::mem::size_of::<Scalar>() * 8 - <Scalar>::MANTISSA_DIGITS as usize - 1)) as Scalar;
+
+                    let mut runner = proptest::test_runner::TestRunner::default();
+                    runner.run(
+                        &test_helpers::array::UniformArrayStrategy::new(-MAX_REPRESENTABLE_VALUE..MAX_REPRESENTABLE_VALUE),
+                        |x| {
+                            let result_1 = unsafe { Vector::from_array(x).to_int_unchecked().to_array() };
+                            let result_2 = {
+                                let mut result = [0; LANES];
+                                for (i, o) in x.iter().zip(result.iter_mut()) {
+                                    *o = unsafe { i.to_int_unchecked() };
+                                }
+                                result
+                            };
+                            test_helpers::prop_assert_biteq!(result_1, result_2);
+                            Ok(())
+                        },
+                    ).unwrap();
+                }
+            }
+        }
+    }
+}
diff --git a/crates/core_simd/tests/u128_ops.rs b/crates/core_simd/tests/u128_ops.rs
new file mode 100644
index 00000000000..eea7e3297c6
--- /dev/null
+++ b/crates/core_simd/tests/u128_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_unsigned_tests! { SimdU128, u128 }
diff --git a/crates/core_simd/tests/u16_ops.rs b/crates/core_simd/tests/u16_ops.rs
new file mode 100644
index 00000000000..ce9951a87c0
--- /dev/null
+++ b/crates/core_simd/tests/u16_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_unsigned_tests! { SimdU16, u16 }
diff --git a/crates/core_simd/tests/u32_ops.rs b/crates/core_simd/tests/u32_ops.rs
new file mode 100644
index 00000000000..87bedbd43b7
--- /dev/null
+++ b/crates/core_simd/tests/u32_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_unsigned_tests! { SimdU32, u32 }
diff --git a/crates/core_simd/tests/u64_ops.rs b/crates/core_simd/tests/u64_ops.rs
new file mode 100644
index 00000000000..ec76891da66
--- /dev/null
+++ b/crates/core_simd/tests/u64_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_unsigned_tests! { SimdU64, u64 }
diff --git a/crates/core_simd/tests/u8_ops.rs b/crates/core_simd/tests/u8_ops.rs
new file mode 100644
index 00000000000..00a63d84613
--- /dev/null
+++ b/crates/core_simd/tests/u8_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_unsigned_tests! { SimdU8, u8 }
diff --git a/crates/core_simd/tests/usize_ops.rs b/crates/core_simd/tests/usize_ops.rs
new file mode 100644
index 00000000000..dd49c656cbe
--- /dev/null
+++ b/crates/core_simd/tests/usize_ops.rs
@@ -0,0 +1,4 @@
+#[macro_use]
+#[path = "ops_macros.rs"]
+mod macros;
+impl_unsigned_tests! { SimdUsize, usize }