replace horizontal_* with reduce_*
This commit is contained in:
parent
86b9f69622
commit
c196b8abaa
5 changed files with 51 additions and 51 deletions
|
@ -233,7 +233,7 @@ pub fn simd_inv4x4(m: Matrix4x4) -> Option<Matrix4x4> {
|
|||
let det = det.rotate_lanes_right::<2>() + det;
|
||||
let det = det.reverse().rotate_lanes_right::<2>() + det;
|
||||
|
||||
if det.horizontal_sum() == 0. {
|
||||
if det.reduce_sum() == 0. {
|
||||
return None;
|
||||
}
|
||||
// calculate the reciprocal
|
||||
|
|
|
@ -107,10 +107,10 @@ mod nbody {
|
|||
let mut e = 0.;
|
||||
for i in 0..N_BODIES {
|
||||
let bi = &bodies[i];
|
||||
e += bi.mass * (bi.v * bi.v).horizontal_sum() * 0.5;
|
||||
e += bi.mass * (bi.v * bi.v).reduce_sum() * 0.5;
|
||||
for bj in bodies.iter().take(N_BODIES).skip(i + 1) {
|
||||
let dx = bi.x - bj.x;
|
||||
e -= bi.mass * bj.mass / (dx * dx).horizontal_sum().sqrt()
|
||||
e -= bi.mass * bj.mass / (dx * dx).reduce_sum().sqrt()
|
||||
}
|
||||
}
|
||||
e
|
||||
|
@ -134,8 +134,8 @@ mod nbody {
|
|||
let mut mag = [0.0; N];
|
||||
for i in (0..N).step_by(2) {
|
||||
let d2s = f64x2::from_array([
|
||||
(r[i] * r[i]).horizontal_sum(),
|
||||
(r[i + 1] * r[i + 1]).horizontal_sum(),
|
||||
(r[i] * r[i]).reduce_sum(),
|
||||
(r[i + 1] * r[i + 1]).reduce_sum(),
|
||||
]);
|
||||
let dmags = f64x2::splat(dt) / (d2s * d2s.sqrt());
|
||||
mag[i] = dmags[0];
|
||||
|
|
|
@ -20,7 +20,7 @@ fn mult_av(v: &[f64], out: &mut [f64]) {
|
|||
sum += b / a;
|
||||
j += 2
|
||||
}
|
||||
*out = sum.horizontal_sum();
|
||||
*out = sum.reduce_sum();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ fn mult_atv(v: &[f64], out: &mut [f64]) {
|
|||
sum += b / a;
|
||||
j += 2
|
||||
}
|
||||
*out = sum.horizontal_sum();
|
||||
*out = sum.reduce_sum();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,30 +11,30 @@ macro_rules! impl_integer_reductions {
|
|||
where
|
||||
LaneCount<LANES>: SupportedLaneCount,
|
||||
{
|
||||
/// Horizontal wrapping add. Returns the sum of the lanes of the vector, with wrapping addition.
|
||||
/// Reducing wrapping add. Returns the sum of the lanes of the vector, with wrapping addition.
|
||||
#[inline]
|
||||
pub fn horizontal_sum(self) -> $scalar {
|
||||
pub fn reduce_sum(self) -> $scalar {
|
||||
// Safety: `self` is an integer vector
|
||||
unsafe { simd_reduce_add_ordered(self, 0) }
|
||||
}
|
||||
|
||||
/// Horizontal wrapping multiply. Returns the product of the lanes of the vector, with wrapping multiplication.
|
||||
/// Reducing wrapping multiply. Returns the product of the lanes of the vector, with wrapping multiplication.
|
||||
#[inline]
|
||||
pub fn horizontal_product(self) -> $scalar {
|
||||
pub fn reduce_product(self) -> $scalar {
|
||||
// Safety: `self` is an integer vector
|
||||
unsafe { simd_reduce_mul_ordered(self, 1) }
|
||||
}
|
||||
|
||||
/// Horizontal maximum. Returns the maximum lane in the vector.
|
||||
/// Reducing maximum. Returns the maximum lane in the vector.
|
||||
#[inline]
|
||||
pub fn horizontal_max(self) -> $scalar {
|
||||
pub fn reduce_max(self) -> $scalar {
|
||||
// Safety: `self` is an integer vector
|
||||
unsafe { simd_reduce_max(self) }
|
||||
}
|
||||
|
||||
/// Horizontal minimum. Returns the minimum lane in the vector.
|
||||
/// Reducing minimum. Returns the minimum lane in the vector.
|
||||
#[inline]
|
||||
pub fn horizontal_min(self) -> $scalar {
|
||||
pub fn reduce_min(self) -> $scalar {
|
||||
// Safety: `self` is an integer vector
|
||||
unsafe { simd_reduce_min(self) }
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ macro_rules! impl_float_reductions {
|
|||
LaneCount<LANES>: SupportedLaneCount,
|
||||
{
|
||||
|
||||
/// Horizontal add. Returns the sum of the lanes of the vector.
|
||||
/// Reducing add. Returns the sum of the lanes of the vector.
|
||||
#[inline]
|
||||
pub fn horizontal_sum(self) -> $scalar {
|
||||
pub fn reduce_sum(self) -> $scalar {
|
||||
// LLVM sum is inaccurate on i586
|
||||
if cfg!(all(target_arch = "x86", not(target_feature = "sse2"))) {
|
||||
self.as_array().iter().sum()
|
||||
|
@ -72,9 +72,9 @@ macro_rules! impl_float_reductions {
|
|||
}
|
||||
}
|
||||
|
||||
/// Horizontal multiply. Returns the product of the lanes of the vector.
|
||||
/// Reducing multiply. Returns the product of the lanes of the vector.
|
||||
#[inline]
|
||||
pub fn horizontal_product(self) -> $scalar {
|
||||
pub fn reduce_product(self) -> $scalar {
|
||||
// LLVM product is inaccurate on i586
|
||||
if cfg!(all(target_arch = "x86", not(target_feature = "sse2"))) {
|
||||
self.as_array().iter().product()
|
||||
|
@ -84,22 +84,22 @@ macro_rules! impl_float_reductions {
|
|||
}
|
||||
}
|
||||
|
||||
/// Horizontal maximum. Returns the maximum lane in the vector.
|
||||
/// Reducing maximum. Returns 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 horizontal_max(self) -> $scalar {
|
||||
pub fn reduce_max(self) -> $scalar {
|
||||
// Safety: `self` is a float vector
|
||||
unsafe { simd_reduce_max(self) }
|
||||
}
|
||||
|
||||
/// Horizontal minimum. Returns the minimum lane in the vector.
|
||||
/// Reducing minimum. Returns 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 horizontal_min(self) -> $scalar {
|
||||
pub fn reduce_min(self) -> $scalar {
|
||||
// Safety: `self` is a float vector
|
||||
unsafe { simd_reduce_min(self) }
|
||||
}
|
||||
|
@ -116,10 +116,10 @@ where
|
|||
T: SimdElement + BitAnd<T, Output = T>,
|
||||
LaneCount<LANES>: SupportedLaneCount,
|
||||
{
|
||||
/// Horizontal bitwise "and". Returns the cumulative bitwise "and" across the lanes of
|
||||
/// Reducing bitwise "and". Returns the cumulative bitwise "and" across the lanes of
|
||||
/// the vector.
|
||||
#[inline]
|
||||
pub fn horizontal_and(self) -> T {
|
||||
pub fn reduce_and(self) -> T {
|
||||
unsafe { simd_reduce_and(self) }
|
||||
}
|
||||
}
|
||||
|
@ -130,10 +130,10 @@ where
|
|||
T: SimdElement + BitOr<T, Output = T>,
|
||||
LaneCount<LANES>: SupportedLaneCount,
|
||||
{
|
||||
/// Horizontal bitwise "or". Returns the cumulative bitwise "or" across the lanes of
|
||||
/// Reducing bitwise "or". Returns the cumulative bitwise "or" across the lanes of
|
||||
/// the vector.
|
||||
#[inline]
|
||||
pub fn horizontal_or(self) -> T {
|
||||
pub fn reduce_or(self) -> T {
|
||||
unsafe { simd_reduce_or(self) }
|
||||
}
|
||||
}
|
||||
|
@ -144,10 +144,10 @@ where
|
|||
T: SimdElement + BitXor<T, Output = T>,
|
||||
LaneCount<LANES>: SupportedLaneCount,
|
||||
{
|
||||
/// Horizontal bitwise "xor". Returns the cumulative bitwise "xor" across the lanes of
|
||||
/// Reducing bitwise "xor". Returns the cumulative bitwise "xor" across the lanes of
|
||||
/// the vector.
|
||||
#[inline]
|
||||
pub fn horizontal_xor(self) -> T {
|
||||
pub fn reduce_xor(self) -> T {
|
||||
unsafe { simd_reduce_xor(self) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,70 +94,70 @@ macro_rules! impl_binary_checked_op_test {
|
|||
macro_rules! impl_common_integer_tests {
|
||||
{ $vector:ident, $scalar:ident } => {
|
||||
test_helpers::test_lanes! {
|
||||
fn horizontal_sum<const LANES: usize>() {
|
||||
fn reduce_sum<const LANES: usize>() {
|
||||
test_helpers::test_1(&|x| {
|
||||
test_helpers::prop_assert_biteq! (
|
||||
$vector::<LANES>::from_array(x).horizontal_sum(),
|
||||
$vector::<LANES>::from_array(x).reduce_sum(),
|
||||
x.iter().copied().fold(0 as $scalar, $scalar::wrapping_add),
|
||||
);
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
fn horizontal_product<const LANES: usize>() {
|
||||
fn reduce_product<const LANES: usize>() {
|
||||
test_helpers::test_1(&|x| {
|
||||
test_helpers::prop_assert_biteq! (
|
||||
$vector::<LANES>::from_array(x).horizontal_product(),
|
||||
$vector::<LANES>::from_array(x).reduce_product(),
|
||||
x.iter().copied().fold(1 as $scalar, $scalar::wrapping_mul),
|
||||
);
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
fn horizontal_and<const LANES: usize>() {
|
||||
fn reduce_and<const LANES: usize>() {
|
||||
test_helpers::test_1(&|x| {
|
||||
test_helpers::prop_assert_biteq! (
|
||||
$vector::<LANES>::from_array(x).horizontal_and(),
|
||||
$vector::<LANES>::from_array(x).reduce_and(),
|
||||
x.iter().copied().fold(-1i8 as $scalar, <$scalar as core::ops::BitAnd>::bitand),
|
||||
);
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
fn horizontal_or<const LANES: usize>() {
|
||||
fn reduce_or<const LANES: usize>() {
|
||||
test_helpers::test_1(&|x| {
|
||||
test_helpers::prop_assert_biteq! (
|
||||
$vector::<LANES>::from_array(x).horizontal_or(),
|
||||
$vector::<LANES>::from_array(x).reduce_or(),
|
||||
x.iter().copied().fold(0 as $scalar, <$scalar as core::ops::BitOr>::bitor),
|
||||
);
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
fn horizontal_xor<const LANES: usize>() {
|
||||
fn reduce_xor<const LANES: usize>() {
|
||||
test_helpers::test_1(&|x| {
|
||||
test_helpers::prop_assert_biteq! (
|
||||
$vector::<LANES>::from_array(x).horizontal_xor(),
|
||||
$vector::<LANES>::from_array(x).reduce_xor(),
|
||||
x.iter().copied().fold(0 as $scalar, <$scalar as core::ops::BitXor>::bitxor),
|
||||
);
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
fn horizontal_max<const LANES: usize>() {
|
||||
fn reduce_max<const LANES: usize>() {
|
||||
test_helpers::test_1(&|x| {
|
||||
test_helpers::prop_assert_biteq! (
|
||||
$vector::<LANES>::from_array(x).horizontal_max(),
|
||||
$vector::<LANES>::from_array(x).reduce_max(),
|
||||
x.iter().copied().max().unwrap(),
|
||||
);
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
fn horizontal_min<const LANES: usize>() {
|
||||
fn reduce_min<const LANES: usize>() {
|
||||
test_helpers::test_1(&|x| {
|
||||
test_helpers::prop_assert_biteq! (
|
||||
$vector::<LANES>::from_array(x).horizontal_min(),
|
||||
$vector::<LANES>::from_array(x).reduce_min(),
|
||||
x.iter().copied().min().unwrap(),
|
||||
);
|
||||
Ok(())
|
||||
|
@ -516,29 +516,29 @@ macro_rules! impl_float_tests {
|
|||
})
|
||||
}
|
||||
|
||||
fn horizontal_sum<const LANES: usize>() {
|
||||
fn reduce_sum<const LANES: usize>() {
|
||||
test_helpers::test_1(&|x| {
|
||||
test_helpers::prop_assert_biteq! (
|
||||
Vector::<LANES>::from_array(x).horizontal_sum(),
|
||||
Vector::<LANES>::from_array(x).reduce_sum(),
|
||||
x.iter().sum(),
|
||||
);
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
fn horizontal_product<const LANES: usize>() {
|
||||
fn reduce_product<const LANES: usize>() {
|
||||
test_helpers::test_1(&|x| {
|
||||
test_helpers::prop_assert_biteq! (
|
||||
Vector::<LANES>::from_array(x).horizontal_product(),
|
||||
Vector::<LANES>::from_array(x).reduce_product(),
|
||||
x.iter().product(),
|
||||
);
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
fn horizontal_max<const LANES: usize>() {
|
||||
fn reduce_max<const LANES: usize>() {
|
||||
test_helpers::test_1(&|x| {
|
||||
let vmax = Vector::<LANES>::from_array(x).horizontal_max();
|
||||
let vmax = Vector::<LANES>::from_array(x).reduce_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.) {
|
||||
|
@ -548,9 +548,9 @@ macro_rules! impl_float_tests {
|
|||
});
|
||||
}
|
||||
|
||||
fn horizontal_min<const LANES: usize>() {
|
||||
fn reduce_min<const LANES: usize>() {
|
||||
test_helpers::test_1(&|x| {
|
||||
let vmax = Vector::<LANES>::from_array(x).horizontal_min();
|
||||
let vmax = Vector::<LANES>::from_array(x).reduce_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.) {
|
||||
|
|
Loading…
Add table
Reference in a new issue