Update documentation and fix i586 inaccuracy

This commit is contained in:
Caleb Zulawski 2021-03-11 00:27:47 -05:00
parent 02608d44f7
commit 64f564866b

View File

@ -58,22 +58,38 @@ impl<const LANES: usize> crate::$name<LANES>
/// Produces the sum of the lanes of the vector.
#[inline]
pub fn sum(self) -> $scalar {
unsafe { crate::intrinsics::simd_reduce_add_ordered(self, 0.) }
// f32 SIMD sum is inaccurate on i586
if cfg!(target_arch = "i586") && core::mem::size_of::<$scalar>() == 4 {
self.as_slice().iter().sum()
} else {
unsafe { crate::intrinsics::simd_reduce_add_ordered(self, 0.) }
}
}
/// Produces the sum of the lanes of the vector.
#[inline]
pub fn product(self) -> $scalar {
unsafe { crate::intrinsics::simd_reduce_mul_ordered(self, 1.) }
// f32 SIMD product is inaccurate on i586
if cfg!(target_arch = "i586") && core::mem::size_of::<$scalar>() == 4 {
self.as_slice().iter().product()
} else {
unsafe { crate::intrinsics::simd_reduce_mul_ordered(self, 1.) }
}
}
/// 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 max_lane(self) -> $scalar {
unsafe { crate::intrinsics::simd_reduce_max(self) }
}
/// 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 min_lane(self) -> $scalar {
unsafe { crate::intrinsics::simd_reduce_min(self) }