From e12758670900aa079b4151bb262d7e4dc0f375c6 Mon Sep 17 00:00:00 2001 From: Caleb Zulawski Date: Sun, 11 Apr 2021 10:59:05 -0400 Subject: [PATCH] Improve function names and docs --- crates/core_simd/src/reduction.rs | 39 +++++++++++++++------------- crates/core_simd/tests/ops_macros.rs | 28 ++++++++++---------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/crates/core_simd/src/reduction.rs b/crates/core_simd/src/reduction.rs index a2b652189c84..e728f8ad82a9 100644 --- a/crates/core_simd/src/reduction.rs +++ b/crates/core_simd/src/reduction.rs @@ -4,45 +4,48 @@ macro_rules! impl_integer_reductions { where Self: crate::LanesAtMost32 { - /// Produces the sum of the lanes of the vector, with wrapping addition. + /// Horizontal wrapping add. Computes the sum of the lanes of the vector, with wrapping addition. #[inline] pub fn wrapping_sum(self) -> $scalar { unsafe { crate::intrinsics::simd_reduce_add_ordered(self, 0) } } - /// Produces the sum of the lanes of the vector, with wrapping multiplication. + /// Horizontal wrapping multiply. Computes the product of the lanes of the vector, with wrapping multiplication. #[inline] pub fn wrapping_product(self) -> $scalar { unsafe { crate::intrinsics::simd_reduce_mul_ordered(self, 1) } } - /// Sequentially performs bitwise "and" between the lanes of the vector. + /// Horizontal bitwise "and". Computes the cumulative bitwise "and" across the lanes of + /// the vector. #[inline] - pub fn and_lanes(self) -> $scalar { + pub fn horizontal_and(self) -> $scalar { unsafe { crate::intrinsics::simd_reduce_and(self) } } - /// Sequentially performs bitwise "or" between the lanes of the vector. + /// Horizontal bitwise "or". Computes the cumulative bitwise "or" across the lanes of + /// the vector. #[inline] - pub fn or_lanes(self) -> $scalar { + pub fn horizontal_or(self) -> $scalar { unsafe { crate::intrinsics::simd_reduce_or(self) } } - /// Sequentially performs bitwise "xor" between the lanes of the vector. + /// Horizontal bitwise "xor". Computes the cumulative bitwise "xor" across the lanes of + /// the vector. #[inline] - pub fn xor_lanes(self) -> $scalar { + pub fn horizontal_xor(self) -> $scalar { unsafe { crate::intrinsics::simd_reduce_xor(self) } } - /// Returns the maximum lane in the vector. + /// Horizontal maximum. Computes the maximum lane in the vector. #[inline] - pub fn max_lane(self) -> $scalar { + pub fn horizontal_max(self) -> $scalar { unsafe { crate::intrinsics::simd_reduce_max(self) } } - /// Returns the minimum lane in the vector. + /// Horizontal minimum. Computes the minimum lane in the vector. #[inline] - pub fn min_lane(self) -> $scalar { + pub fn horizontal_min(self) -> $scalar { unsafe { crate::intrinsics::simd_reduce_min(self) } } } @@ -56,7 +59,7 @@ macro_rules! impl_float_reductions { Self: crate::LanesAtMost32 { - /// Produces the sum of the lanes of the vector. + /// Horizontal add. Computes the sum of the lanes of the vector. #[inline] pub fn sum(self) -> $scalar { // LLVM sum is inaccurate on i586 @@ -67,7 +70,7 @@ macro_rules! impl_float_reductions { } } - /// Produces the sum of the lanes of the vector. + /// Horizontal multiply. Computes the sum of the lanes of the vector. #[inline] pub fn product(self) -> $scalar { // LLVM product is inaccurate on i586 @@ -78,21 +81,21 @@ macro_rules! impl_float_reductions { } } - /// Returns the maximum lane in the vector. + /// Horizontal maximum. Computes the maximum lane in the vector. /// /// Returns values based on equality, so a vector containing both `0.` and `-0.` may /// return either. This function will not return `NaN` unless all lanes are `NaN`. #[inline] - pub fn max_lane(self) -> $scalar { + pub fn horizontal_max(self) -> $scalar { unsafe { crate::intrinsics::simd_reduce_max(self) } } - /// Returns the minimum lane in the vector. + /// Horizontal minimum. Computes the minimum lane in the vector. /// /// Returns values based on equality, so a vector containing both `0.` and `-0.` may /// return either. This function will not return `NaN` unless all lanes are `NaN`. #[inline] - pub fn min_lane(self) -> $scalar { + pub fn horizontal_min(self) -> $scalar { unsafe { crate::intrinsics::simd_reduce_min(self) } } } diff --git a/crates/core_simd/tests/ops_macros.rs b/crates/core_simd/tests/ops_macros.rs index 59e923ac5c14..7ce85b77254a 100644 --- a/crates/core_simd/tests/ops_macros.rs +++ b/crates/core_simd/tests/ops_macros.rs @@ -160,50 +160,50 @@ macro_rules! impl_common_integer_tests { }); } - fn and_lanes() { + fn horizontal_and() { test_helpers::test_1(&|x| { test_helpers::prop_assert_biteq! ( - $vector::::from_array(x).and_lanes(), + $vector::::from_array(x).horizontal_and(), x.iter().copied().fold(-1i8 as $scalar, <$scalar as core::ops::BitAnd>::bitand), ); Ok(()) }); } - fn or_lanes() { + fn horizontal_or() { test_helpers::test_1(&|x| { test_helpers::prop_assert_biteq! ( - $vector::::from_array(x).or_lanes(), + $vector::::from_array(x).horizontal_or(), x.iter().copied().fold(0 as $scalar, <$scalar as core::ops::BitOr>::bitor), ); Ok(()) }); } - fn xor_lanes() { + fn horizontal_xor() { test_helpers::test_1(&|x| { test_helpers::prop_assert_biteq! ( - $vector::::from_array(x).xor_lanes(), + $vector::::from_array(x).horizontal_xor(), x.iter().copied().fold(0 as $scalar, <$scalar as core::ops::BitXor>::bitxor), ); Ok(()) }); } - fn max_lane() { + fn horizontal_max() { test_helpers::test_1(&|x| { test_helpers::prop_assert_biteq! ( - $vector::::from_array(x).max_lane(), + $vector::::from_array(x).horizontal_max(), x.iter().copied().max().unwrap(), ); Ok(()) }); } - fn min_lane() { + fn horizontal_min() { test_helpers::test_1(&|x| { test_helpers::prop_assert_biteq! ( - $vector::::from_array(x).min_lane(), + $vector::::from_array(x).horizontal_min(), x.iter().copied().min().unwrap(), ); Ok(()) @@ -499,9 +499,9 @@ macro_rules! impl_float_tests { }); } - fn max_lane() { + fn horizontal_max() { test_helpers::test_1(&|x| { - let vmax = Vector::::from_array(x).max_lane(); + let vmax = Vector::::from_array(x).horizontal_max(); let smax = x.iter().copied().fold(Scalar::NAN, Scalar::max); // 0 and -0 are treated the same if !(x.contains(&0.) && x.contains(&-0.) && vmax.abs() == 0. && smax.abs() == 0.) { @@ -511,9 +511,9 @@ macro_rules! impl_float_tests { }); } - fn min_lane() { + fn horizontal_min() { test_helpers::test_1(&|x| { - let vmax = Vector::::from_array(x).min_lane(); + let vmax = Vector::::from_array(x).horizontal_min(); let smax = x.iter().copied().fold(Scalar::NAN, Scalar::min); // 0 and -0 are treated the same if !(x.contains(&0.) && x.contains(&-0.) && vmax.abs() == 0. && smax.abs() == 0.) {