about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Zulawski <caleb.zulawski@gmail.com>2021-02-13 02:14:47 -0500
committerCaleb Zulawski <caleb.zulawski@gmail.com>2021-02-15 18:22:56 -0500
commit8d5702e437e051333dcf1005fcce140c5c96f759 (patch)
tree91a86c2c81e8c419a825146b5d28e5d2eac7e412
parent38b18904d0399d8dcfee5dfc94e38d78a8fbba66 (diff)
downloadrust-8d5702e437e051333dcf1005fcce140c5c96f759.tar.gz
rust-8d5702e437e051333dcf1005fcce140c5c96f759.zip
Fix performance issues
-rw-r--r--crates/core_simd/tests/float.rs60
-rw-r--r--crates/core_simd/tests/integer.rs76
-rw-r--r--crates/test_helpers/src/lib.rs40
3 files changed, 90 insertions, 86 deletions
diff --git a/crates/core_simd/tests/float.rs b/crates/core_simd/tests/float.rs
index 56d66239e80..03d132ae046 100644
--- a/crates/core_simd/tests/float.rs
+++ b/crates/core_simd/tests/float.rs
@@ -6,9 +6,9 @@ macro_rules! impl_op_test {
         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,
+                    &<$vector as core::ops::$trait>::$fn,
+                    &<$scalar as core::ops::$trait>::$fn,
+                    &|_| true,
                 );
             }
         }
@@ -20,41 +20,41 @@ macro_rules! impl_op_test {
             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,
+                        &<$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,
+                        &<$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,
+                        &<$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,
+                        &|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,
+                        &|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,
                     )
                 }
             }
@@ -79,33 +79,33 @@ macro_rules! impl_tests {
             test_helpers::test_lanes! {
                 fn abs<const LANES: usize>() {
                     test_helpers::test_unary_elementwise(
-                        Vector::<LANES>::abs,
-                        Scalar::abs,
-                        |_| true,
+                        &Vector::<LANES>::abs,
+                        &Scalar::abs,
+                        &|_| true,
                     )
                 }
 
                 fn ceil<const LANES: usize>() {
                     test_helpers::test_unary_elementwise(
-                        Vector::<LANES>::ceil,
-                        Scalar::ceil,
-                        |_| true,
+                        &Vector::<LANES>::ceil,
+                        &Scalar::ceil,
+                        &|_| true,
                     )
                 }
 
                 fn floor<const LANES: usize>() {
                     test_helpers::test_unary_elementwise(
-                        Vector::<LANES>::floor,
-                        Scalar::floor,
-                        |_| true,
+                        &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,
+                        &Vector::<LANES>::round_from_int,
+                        &|x| x as Scalar,
+                        &|_| true,
                     )
                 }
 
diff --git a/crates/core_simd/tests/integer.rs b/crates/core_simd/tests/integer.rs
index 4f38cdb1ed6..878b3f0329a 100644
--- a/crates/core_simd/tests/integer.rs
+++ b/crates/core_simd/tests/integer.rs
@@ -6,9 +6,9 @@ macro_rules! impl_unary_op_test {
         test_helpers::test_lanes! {
             fn $fn<const LANES: usize>() {
                 test_helpers::test_unary_elementwise(
-                    <$vector as core::ops::$trait>::$fn,
-                    $scalar_fn,
-                    |_| true,
+                    &<$vector as core::ops::$trait>::$fn,
+                    &$scalar_fn,
+                    &|_| true,
                 );
             }
         }
@@ -26,42 +26,42 @@ macro_rules! impl_binary_op_test {
             test_helpers::test_lanes! {
                 fn normal<const LANES: usize>() {
                     test_helpers::test_binary_elementwise(
-                        <$vector as core::ops::$trait>::$fn,
-                        $scalar_fn,
-                        |_, _| true,
+                        &<$vector as core::ops::$trait>::$fn,
+                        &$scalar_fn,
+                        &|_, _| true,
                     );
                 }
 
                 fn scalar_rhs<const LANES: usize>() {
                     test_helpers::test_binary_scalar_rhs_elementwise(
-                        <$vector as core::ops::$trait<$scalar>>::$fn,
-                        $scalar_fn,
-                        |_, _| true,
+                        &<$vector as core::ops::$trait<$scalar>>::$fn,
+                        &$scalar_fn,
+                        &|_, _| true,
                     );
                 }
 
                 fn scalar_lhs<const LANES: usize>() {
                     test_helpers::test_binary_scalar_lhs_elementwise(
-                        <$scalar as core::ops::$trait<$vector>>::$fn,
-                        $scalar_fn,
-                        |_, _| true,
+                        &<$scalar as core::ops::$trait<$vector>>::$fn,
+                        &$scalar_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 },
-                        $scalar_fn,
-                        |_, _| true,
-                    )
+                        &|mut a, b| { <$vector as core::ops::$trait_assign>::$fn_assign(&mut a, b); a },
+                        &$scalar_fn,
+                        &|_, _| 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 },
-                        $scalar_fn,
-                        |_, _| true,
-                    )
+                        &|mut a, b| { <$vector as core::ops::$trait_assign<$scalar>>::$fn_assign(&mut a, b); a },
+                        &$scalar_fn,
+                        &|_, _| true,
+                    );
                 }
             }
         }
@@ -79,41 +79,41 @@ macro_rules! impl_binary_checked_op_test {
             test_helpers::test_lanes! {
                 fn normal<const LANES: usize>() {
                     test_helpers::test_binary_elementwise(
-                        <$vector as core::ops::$trait>::$fn,
-                        $scalar_fn,
-                        |x, y| x.iter().zip(y.iter()).all(|(x, y)| $check_fn(*x, *y)),
+                        &<$vector as core::ops::$trait>::$fn,
+                        &$scalar_fn,
+                        &|x, y| x.iter().zip(y.iter()).all(|(x, y)| $check_fn(*x, *y)),
                     );
                 }
 
                 fn scalar_rhs<const LANES: usize>() {
                     test_helpers::test_binary_scalar_rhs_elementwise(
-                        <$vector as core::ops::$trait<$scalar>>::$fn,
-                        $scalar_fn,
-                        |x, y| x.iter().all(|x| $check_fn(*x, y)),
+                        &<$vector as core::ops::$trait<$scalar>>::$fn,
+                        &$scalar_fn,
+                        &|x, y| x.iter().all(|x| $check_fn(*x, y)),
                     );
                 }
 
                 fn scalar_lhs<const LANES: usize>() {
                     test_helpers::test_binary_scalar_lhs_elementwise(
-                        <$scalar as core::ops::$trait<$vector>>::$fn,
-                        $scalar_fn,
-                        |x, y| y.iter().all(|y| $check_fn(x, *y)),
+                        &<$scalar as core::ops::$trait<$vector>>::$fn,
+                        &$scalar_fn,
+                        &|x, y| y.iter().all(|y| $check_fn(x, *y)),
                     );
                 }
 
                 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 },
-                        $scalar_fn,
-                        |x, y| x.iter().zip(y.iter()).all(|(x, y)| $check_fn(*x, *y)),
+                        &|mut a, b| { <$vector as core::ops::$trait_assign>::$fn_assign(&mut a, b); a },
+                        &$scalar_fn,
+                        &|x, y| x.iter().zip(y.iter()).all(|(x, y)| $check_fn(*x, *y)),
                     )
                 }
 
                 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 },
-                        $scalar_fn,
-                        |x, y| x.iter().all(|x| $check_fn(*x, y)),
+                        &|mut a, b| { <$vector as core::ops::$trait_assign<$scalar>>::$fn_assign(&mut a, b); a },
+                        &$scalar_fn,
+                        &|x, y| x.iter().all(|x| $check_fn(*x, y)),
                     )
                 }
             }
@@ -133,9 +133,9 @@ macro_rules! impl_signed_tests {
             test_helpers::test_lanes! {
                 fn neg<const LANES: usize>() {
                     test_helpers::test_unary_elementwise(
-                        <Vector<LANES> as core::ops::Neg>::neg,
-                        <Scalar as core::ops::Neg>::neg,
-                        |x| !x.contains(&Scalar::MIN),
+                        &<Vector<LANES> as core::ops::Neg>::neg,
+                        &<Scalar as core::ops::Neg>::neg,
+                        &|x| !x.contains(&Scalar::MIN),
                     );
                 }
             }
diff --git a/crates/test_helpers/src/lib.rs b/crates/test_helpers/src/lib.rs
index 77dafe38a10..134b4073a4e 100644
--- a/crates/test_helpers/src/lib.rs
+++ b/crates/test_helpers/src/lib.rs
@@ -42,14 +42,14 @@ impl<T: core::fmt::Debug + DefaultStrategy, const LANES: usize> DefaultStrategy
 }
 
 pub fn test_1<A: core::fmt::Debug + DefaultStrategy>(
-    f: impl Fn(A) -> proptest::test_runner::TestCaseResult,
+    f: &dyn Fn(A) -> proptest::test_runner::TestCaseResult,
 ) {
     let mut runner = proptest::test_runner::TestRunner::default();
     runner.run(&A::default_strategy(), f).unwrap();
 }
 
 pub fn test_2<A: core::fmt::Debug + DefaultStrategy, B: core::fmt::Debug + DefaultStrategy>(
-    f: impl Fn(A, B) -> proptest::test_runner::TestCaseResult,
+    f: &dyn Fn(A, B) -> proptest::test_runner::TestCaseResult,
 ) {
     let mut runner = proptest::test_runner::TestRunner::default();
     runner
@@ -59,17 +59,18 @@ pub fn test_2<A: core::fmt::Debug + DefaultStrategy, B: core::fmt::Debug + Defau
         .unwrap();
 }
 
+#[inline(never)]
 pub fn test_unary_elementwise<Scalar, ScalarResult, Vector, VectorResult, const LANES: usize>(
-    fv: impl Fn(Vector) -> VectorResult,
-    fs: impl Fn(Scalar) -> ScalarResult,
-    check: impl Fn([Scalar; LANES]) -> bool,
+    fv: &dyn Fn(Vector) -> VectorResult,
+    fs: &dyn Fn(Scalar) -> ScalarResult,
+    check: &dyn Fn([Scalar; LANES]) -> bool,
 ) where
     Scalar: Copy + Default + core::fmt::Debug + DefaultStrategy,
     ScalarResult: Copy + Default + biteq::BitEq + core::fmt::Debug + DefaultStrategy,
     Vector: Into<[Scalar; LANES]> + From<[Scalar; LANES]> + Copy,
     VectorResult: Into<[ScalarResult; LANES]> + From<[ScalarResult; LANES]> + Copy,
 {
-    test_1(|x: [Scalar; LANES]| {
+    test_1(&|x: [Scalar; LANES]| {
         proptest::prop_assume!(check(x));
         let result_1: [ScalarResult; LANES] = fv(x.into()).into();
         let result_2: [ScalarResult; LANES] = {
@@ -84,6 +85,7 @@ pub fn test_unary_elementwise<Scalar, ScalarResult, Vector, VectorResult, const
     });
 }
 
+#[inline(never)]
 pub fn test_binary_elementwise<
     Scalar1,
     Scalar2,
@@ -93,9 +95,9 @@ pub fn test_binary_elementwise<
     VectorResult,
     const LANES: usize,
 >(
-    fv: impl Fn(Vector1, Vector2) -> VectorResult,
-    fs: impl Fn(Scalar1, Scalar2) -> ScalarResult,
-    check: impl Fn([Scalar1; LANES], [Scalar2; LANES]) -> bool,
+    fv: &dyn Fn(Vector1, Vector2) -> VectorResult,
+    fs: &dyn Fn(Scalar1, Scalar2) -> ScalarResult,
+    check: &dyn Fn([Scalar1; LANES], [Scalar2; LANES]) -> bool,
 ) where
     Scalar1: Copy + Default + core::fmt::Debug + DefaultStrategy,
     Scalar2: Copy + Default + core::fmt::Debug + DefaultStrategy,
@@ -104,7 +106,7 @@ pub fn test_binary_elementwise<
     Vector2: Into<[Scalar2; LANES]> + From<[Scalar2; LANES]> + Copy,
     VectorResult: Into<[ScalarResult; LANES]> + From<[ScalarResult; LANES]> + Copy,
 {
-    test_2(|x: [Scalar1; LANES], y: [Scalar2; LANES]| {
+    test_2(&|x: [Scalar1; LANES], y: [Scalar2; LANES]| {
         proptest::prop_assume!(check(x, y));
         let result_1: [ScalarResult; LANES] = fv(x.into(), y.into()).into();
         let result_2: [ScalarResult; LANES] = {
@@ -119,6 +121,7 @@ pub fn test_binary_elementwise<
     });
 }
 
+#[inline(never)]
 pub fn test_binary_scalar_rhs_elementwise<
     Scalar1,
     Scalar2,
@@ -127,9 +130,9 @@ pub fn test_binary_scalar_rhs_elementwise<
     VectorResult,
     const LANES: usize,
 >(
-    fv: impl Fn(Vector, Scalar2) -> VectorResult,
-    fs: impl Fn(Scalar1, Scalar2) -> ScalarResult,
-    check: impl Fn([Scalar1; LANES], Scalar2) -> bool,
+    fv: &dyn Fn(Vector, Scalar2) -> VectorResult,
+    fs: &dyn Fn(Scalar1, Scalar2) -> ScalarResult,
+    check: &dyn Fn([Scalar1; LANES], Scalar2) -> bool,
 ) where
     Scalar1: Copy + Default + core::fmt::Debug + DefaultStrategy,
     Scalar2: Copy + Default + core::fmt::Debug + DefaultStrategy,
@@ -137,7 +140,7 @@ pub fn test_binary_scalar_rhs_elementwise<
     Vector: Into<[Scalar1; LANES]> + From<[Scalar1; LANES]> + Copy,
     VectorResult: Into<[ScalarResult; LANES]> + From<[ScalarResult; LANES]> + Copy,
 {
-    test_2(|x: [Scalar1; LANES], y: Scalar2| {
+    test_2(&|x: [Scalar1; LANES], y: Scalar2| {
         proptest::prop_assume!(check(x, y));
         let result_1: [ScalarResult; LANES] = fv(x.into(), y).into();
         let result_2: [ScalarResult; LANES] = {
@@ -152,6 +155,7 @@ pub fn test_binary_scalar_rhs_elementwise<
     });
 }
 
+#[inline(never)]
 pub fn test_binary_scalar_lhs_elementwise<
     Scalar1,
     Scalar2,
@@ -160,9 +164,9 @@ pub fn test_binary_scalar_lhs_elementwise<
     VectorResult,
     const LANES: usize,
 >(
-    fv: impl Fn(Scalar1, Vector) -> VectorResult,
-    fs: impl Fn(Scalar1, Scalar2) -> ScalarResult,
-    check: impl Fn(Scalar1, [Scalar2; LANES]) -> bool,
+    fv: &dyn Fn(Scalar1, Vector) -> VectorResult,
+    fs: &dyn Fn(Scalar1, Scalar2) -> ScalarResult,
+    check: &dyn Fn(Scalar1, [Scalar2; LANES]) -> bool,
 ) where
     Scalar1: Copy + Default + core::fmt::Debug + DefaultStrategy,
     Scalar2: Copy + Default + core::fmt::Debug + DefaultStrategy,
@@ -170,7 +174,7 @@ pub fn test_binary_scalar_lhs_elementwise<
     Vector: Into<[Scalar2; LANES]> + From<[Scalar2; LANES]> + Copy,
     VectorResult: Into<[ScalarResult; LANES]> + From<[ScalarResult; LANES]> + Copy,
 {
-    test_2(|x: Scalar1, y: [Scalar2; LANES]| {
+    test_2(&|x: Scalar1, y: [Scalar2; LANES]| {
         proptest::prop_assume!(check(x, y));
         let result_1: [ScalarResult; LANES] = fv(x, y.into()).into();
         let result_2: [ScalarResult; LANES] = {