Merge commit 'cc032ad5ed5b69d606c4eabbc9c9ae1f412ef2fb' into sync-from-portable-simd-2026-04-28

This commit is contained in:
Folkert de Vries
2026-04-28 17:17:28 +02:00
6 changed files with 55 additions and 39 deletions
@@ -400,7 +400,15 @@ where
if min_index.eq(T::TRUE) {
None
} else {
Some(min_index.to_usize())
let min_index = min_index.to_usize();
// Allow eliminating bounds checks when using the index
// Safety: the index can't exceed the number of elements in the vector
unsafe {
core::hint::assert_unchecked(min_index < N);
}
Some(min_index)
}
}
}
@@ -430,14 +430,14 @@ macro_rules! impl_trait {
#[inline]
fn reduce_max(self) -> Self::Scalar {
// Safety: `self` is a float vector
unsafe { core::intrinsics::simd::simd_reduce_max(self) }
// LLVM has no intrinsic we can use here
// (https://github.com/llvm/llvm-project/issues/185827).
self.as_array().iter().copied().fold(Self::Scalar::NAN, Self::Scalar::max)
}
#[inline]
fn reduce_min(self) -> Self::Scalar {
// Safety: `self` is a float vector
unsafe { core::intrinsics::simd::simd_reduce_min(self) }
self.as_array().iter().copied().fold(Self::Scalar::NAN, Self::Scalar::min)
}
}
)*
@@ -14,6 +14,10 @@ pub use super::{
simd_swizzle,
};
#[rustfmt::skip]
#[doc(no_inline)]
pub use super::{f16x1, f16x2, f16x4, f16x8, f16x16, f16x32, f16x64};
#[rustfmt::skip]
#[doc(no_inline)]
pub use super::{f32x1, f32x2, f32x4, f32x8, f32x16, f32x32, f32x64};
@@ -33,23 +33,6 @@ macro_rules! unary_approx_test {
}
}
macro_rules! binary_approx_test {
{ $scalar:tt, $($func:tt),+ } => {
test_helpers::test_lanes! {
$(
fn $func<const LANES: usize>() {
test_helpers::test_binary_elementwise_approx(
&core_simd::simd::Simd::<$scalar, LANES>::$func,
&$scalar::$func,
&|_, _| true,
16,
)
}
)*
}
}
}
macro_rules! ternary_test {
{ $scalar:tt, $($func:tt),+ } => {
test_helpers::test_lanes! {
@@ -76,7 +59,19 @@ macro_rules! impl_tests {
// https://github.com/rust-lang/miri/issues/3555
unary_approx_test! { $scalar, sin, cos, exp, exp2, ln, log2, log10 }
binary_approx_test! { $scalar, log }
// The implementation of log is a.ln() / b.ln(), so there are 2 inexact operations,
// hence a larger ulps is needed.
test_helpers::test_lanes! {
fn log<const LANES: usize>() {
test_helpers::test_binary_elementwise_approx(
&core_simd::simd::Simd::<$scalar, LANES>::log,
&$scalar::log,
&|_, _| true,
32,
)
}
}
test_helpers::test_lanes! {
fn fract<const LANES: usize>() {
@@ -122,12 +122,23 @@ pub fn make_runner() -> proptest::test_runner::TestRunner {
proptest::test_runner::TestRunner::new(proptest::test_runner::Config::with_cases(4))
}
#[track_caller]
fn unwrap_test_error<T, U: std::fmt::Debug>(
x: Result<T, proptest::test_runner::TestError<U>>,
) -> T {
// Using the `Display` instance of the error is much more readable.
match x {
Ok(v) => v,
Err(e) => panic!("{e}"),
}
}
/// Test a function that takes a single value.
pub fn test_1<A: core::fmt::Debug + DefaultStrategy>(
f: &dyn Fn(A) -> proptest::test_runner::TestCaseResult,
) {
let mut runner = make_runner();
runner.run(&A::default_strategy(), f).unwrap();
unwrap_test_error(runner.run(&A::default_strategy(), f))
}
/// Test a function that takes two values.
@@ -135,11 +146,11 @@ pub fn test_2<A: core::fmt::Debug + DefaultStrategy, B: core::fmt::Debug + Defau
f: &dyn Fn(A, B) -> proptest::test_runner::TestCaseResult,
) {
let mut runner = make_runner();
runner
.run(&(A::default_strategy(), B::default_strategy()), |(a, b)| {
unwrap_test_error(
runner.run(&(A::default_strategy(), B::default_strategy()), |(a, b)| {
f(a, b)
})
.unwrap();
}),
)
}
/// Test a function that takes two values.
@@ -151,16 +162,14 @@ pub fn test_3<
f: &dyn Fn(A, B, C) -> proptest::test_runner::TestCaseResult,
) {
let mut runner = make_runner();
runner
.run(
&(
A::default_strategy(),
B::default_strategy(),
C::default_strategy(),
),
|(a, b, c)| f(a, b, c),
)
.unwrap();
unwrap_test_error(runner.run(
&(
A::default_strategy(),
B::default_strategy(),
C::default_strategy(),
),
|(a, b, c)| f(a, b, c),
));
}
/// Test a unary vector function against a unary scalar function, applied elementwise.
+1 -1
View File
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2026-03-18"
channel = "nightly-2026-04-28"
components = ["rustfmt", "clippy", "miri", "rust-src"]