Skip to content

Commit aebf6f1

Browse files
committed
Use intrinsics directly to avoid recursion
1 parent 44b4d26 commit aebf6f1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

crates/core_simd/src/masks.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
)]
1313
mod mask_impl;
1414

15-
use crate::simd::{cmp::SimdPartialEq, LaneCount, Simd, SimdCast, SimdElement, SupportedLaneCount};
15+
use crate::simd::{LaneCount, Simd, SimdCast, SimdElement, SupportedLaneCount};
1616
use core::cmp::Ordering;
1717
use core::{fmt, mem};
1818

@@ -58,7 +58,16 @@ macro_rules! impl_element {
5858
where
5959
LaneCount<N>: SupportedLaneCount,
6060
{
61-
(value.simd_eq(Simd::splat(0 as _)) | value.simd_eq(Simd::splat(-1 as _))).all()
61+
// We can't use `Simd` directly, because `Simd`'s functions call this function and
62+
// we will end up with an infinite loop.
63+
// Safety: `value` is an integer vector
64+
unsafe {
65+
use core::intrinsics::simd;
66+
let falses: Simd<Self, N> = simd::simd_eq(value, Simd::splat(0 as _));
67+
let trues: Simd<Self, N> = simd::simd_eq(value, Simd::splat(-1 as _));
68+
let valid: Simd<Self, N> = simd::simd_or(falses, trues);
69+
simd::simd_reduce_all(valid)
70+
}
6271
}
6372

6473
#[inline]

0 commit comments

Comments
 (0)