Skip to content

Commit 3fae09b

Browse files
committed
Revert "Revert i586 fix, fix test instead"
This reverts commit 1ea2f12.
1 parent b51febb commit 3fae09b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

crates/core_simd/src/reduction.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,23 @@ macro_rules! impl_float_reductions {
5959
/// Produces the sum of the lanes of the vector.
6060
#[inline]
6161
pub fn sum(self) -> $scalar {
62-
unsafe { crate::intrinsics::simd_reduce_add_ordered(self, 0.) }
62+
// f32 SIMD sum is inaccurate on i586
63+
if cfg!(all(target_arch = "x86", not(target_feature = "sse2"))) && core::mem::size_of::<$scalar>() == 4 {
64+
self.as_slice().iter().sum()
65+
} else {
66+
unsafe { crate::intrinsics::simd_reduce_add_ordered(self, 0.) }
67+
}
6368
}
6469

6570
/// Produces the sum of the lanes of the vector.
6671
#[inline]
6772
pub fn product(self) -> $scalar {
68-
unsafe { crate::intrinsics::simd_reduce_mul_ordered(self, 1.) }
73+
// f32 SIMD product is inaccurate on i586
74+
if cfg!(all(target_arch = "x86", not(target_feature = "sse2"))) && core::mem::size_of::<$scalar>() == 4 {
75+
self.as_slice().iter().product()
76+
} else {
77+
unsafe { crate::intrinsics::simd_reduce_mul_ordered(self, 1.) }
78+
}
6979
}
7080

7181
/// Returns the maximum lane in the vector.

crates/core_simd/tests/ops_macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ macro_rules! impl_float_tests {
483483
test_helpers::test_1(&|x| {
484484
test_helpers::prop_assert_biteq! (
485485
Vector::<LANES>::from_array(x).sum(),
486-
x.iter().sum(),
486+
x.iter().copied().fold(0 as Scalar, <Scalar as core::ops::Add>::add),
487487
);
488488
Ok(())
489489
});
@@ -493,7 +493,7 @@ macro_rules! impl_float_tests {
493493
test_helpers::test_1(&|x| {
494494
test_helpers::prop_assert_biteq! (
495495
Vector::<LANES>::from_array(x).product(),
496-
x.iter().product(),
496+
x.iter().copied().fold(1. as Scalar, <Scalar as core::ops::Mul>::mul),
497497
);
498498
Ok(())
499499
});

0 commit comments

Comments
 (0)