Skip to content

Commit eac6db9

Browse files
Rollup merge of #155930 - folkertdev:sync-from-portable-simd-2026-04-28, r=folkertdev
Sync from portable simd 2026 04 28 r? calebzulawski (I'll self-approve if CI looks good)
2 parents 1321a67 + 631e935 commit eac6db9

6 files changed

Lines changed: 55 additions & 39 deletions

File tree

library/portable-simd/crates/core_simd/src/masks.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,15 @@ where
400400
if min_index.eq(T::TRUE) {
401401
None
402402
} else {
403-
Some(min_index.to_usize())
403+
let min_index = min_index.to_usize();
404+
405+
// Allow eliminating bounds checks when using the index
406+
// Safety: the index can't exceed the number of elements in the vector
407+
unsafe {
408+
core::hint::assert_unchecked(min_index < N);
409+
}
410+
411+
Some(min_index)
404412
}
405413
}
406414
}

library/portable-simd/crates/core_simd/src/simd/num/float.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,14 +430,14 @@ macro_rules! impl_trait {
430430

431431
#[inline]
432432
fn reduce_max(self) -> Self::Scalar {
433-
// Safety: `self` is a float vector
434-
unsafe { core::intrinsics::simd::simd_reduce_max(self) }
433+
// LLVM has no intrinsic we can use here
434+
// (https://github.com/llvm/llvm-project/issues/185827).
435+
self.as_array().iter().copied().fold(Self::Scalar::NAN, Self::Scalar::max)
435436
}
436437

437438
#[inline]
438439
fn reduce_min(self) -> Self::Scalar {
439-
// Safety: `self` is a float vector
440-
unsafe { core::intrinsics::simd::simd_reduce_min(self) }
440+
self.as_array().iter().copied().fold(Self::Scalar::NAN, Self::Scalar::min)
441441
}
442442
}
443443
)*

library/portable-simd/crates/core_simd/src/simd/prelude.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ pub use super::{
1414
simd_swizzle,
1515
};
1616

17+
#[rustfmt::skip]
18+
#[doc(no_inline)]
19+
pub use super::{f16x1, f16x2, f16x4, f16x8, f16x16, f16x32, f16x64};
20+
1721
#[rustfmt::skip]
1822
#[doc(no_inline)]
1923
pub use super::{f32x1, f32x2, f32x4, f32x8, f32x16, f32x32, f32x64};

library/portable-simd/crates/std_float/tests/float.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,6 @@ macro_rules! unary_approx_test {
3333
}
3434
}
3535

36-
macro_rules! binary_approx_test {
37-
{ $scalar:tt, $($func:tt),+ } => {
38-
test_helpers::test_lanes! {
39-
$(
40-
fn $func<const LANES: usize>() {
41-
test_helpers::test_binary_elementwise_approx(
42-
&core_simd::simd::Simd::<$scalar, LANES>::$func,
43-
&$scalar::$func,
44-
&|_, _| true,
45-
16,
46-
)
47-
}
48-
)*
49-
}
50-
}
51-
}
52-
5336
macro_rules! ternary_test {
5437
{ $scalar:tt, $($func:tt),+ } => {
5538
test_helpers::test_lanes! {
@@ -76,7 +59,19 @@ macro_rules! impl_tests {
7659

7760
// https://github.com/rust-lang/miri/issues/3555
7861
unary_approx_test! { $scalar, sin, cos, exp, exp2, ln, log2, log10 }
79-
binary_approx_test! { $scalar, log }
62+
63+
// The implementation of log is a.ln() / b.ln(), so there are 2 inexact operations,
64+
// hence a larger ulps is needed.
65+
test_helpers::test_lanes! {
66+
fn log<const LANES: usize>() {
67+
test_helpers::test_binary_elementwise_approx(
68+
&core_simd::simd::Simd::<$scalar, LANES>::log,
69+
&$scalar::log,
70+
&|_, _| true,
71+
32,
72+
)
73+
}
74+
}
8075

8176
test_helpers::test_lanes! {
8277
fn fract<const LANES: usize>() {

library/portable-simd/crates/test_helpers/src/lib.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,35 @@ pub fn make_runner() -> proptest::test_runner::TestRunner {
122122
proptest::test_runner::TestRunner::new(proptest::test_runner::Config::with_cases(4))
123123
}
124124

125+
#[track_caller]
126+
fn unwrap_test_error<T, U: std::fmt::Debug>(
127+
x: Result<T, proptest::test_runner::TestError<U>>,
128+
) -> T {
129+
// Using the `Display` instance of the error is much more readable.
130+
match x {
131+
Ok(v) => v,
132+
Err(e) => panic!("{e}"),
133+
}
134+
}
135+
125136
/// Test a function that takes a single value.
126137
pub fn test_1<A: core::fmt::Debug + DefaultStrategy>(
127138
f: &dyn Fn(A) -> proptest::test_runner::TestCaseResult,
128139
) {
129140
let mut runner = make_runner();
130-
runner.run(&A::default_strategy(), f).unwrap();
141+
unwrap_test_error(runner.run(&A::default_strategy(), f))
131142
}
132143

133144
/// Test a function that takes two values.
134145
pub fn test_2<A: core::fmt::Debug + DefaultStrategy, B: core::fmt::Debug + DefaultStrategy>(
135146
f: &dyn Fn(A, B) -> proptest::test_runner::TestCaseResult,
136147
) {
137148
let mut runner = make_runner();
138-
runner
139-
.run(&(A::default_strategy(), B::default_strategy()), |(a, b)| {
149+
unwrap_test_error(
150+
runner.run(&(A::default_strategy(), B::default_strategy()), |(a, b)| {
140151
f(a, b)
141-
})
142-
.unwrap();
152+
}),
153+
)
143154
}
144155

145156
/// Test a function that takes two values.
@@ -151,16 +162,14 @@ pub fn test_3<
151162
f: &dyn Fn(A, B, C) -> proptest::test_runner::TestCaseResult,
152163
) {
153164
let mut runner = make_runner();
154-
runner
155-
.run(
156-
&(
157-
A::default_strategy(),
158-
B::default_strategy(),
159-
C::default_strategy(),
160-
),
161-
|(a, b, c)| f(a, b, c),
162-
)
163-
.unwrap();
165+
unwrap_test_error(runner.run(
166+
&(
167+
A::default_strategy(),
168+
B::default_strategy(),
169+
C::default_strategy(),
170+
),
171+
|(a, b, c)| f(a, b, c),
172+
));
164173
}
165174

166175
/// Test a unary vector function against a unary scalar function, applied elementwise.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2026-03-18"
2+
channel = "nightly-2026-04-28"
33
components = ["rustfmt", "clippy", "miri", "rust-src"]

0 commit comments

Comments
 (0)