|
12 | 12 | )] |
13 | 13 | mod mask_impl; |
14 | 14 |
|
15 | | -use crate::simd::{cmp::SimdPartialEq, LaneCount, Simd, SimdCast, SimdElement, SupportedLaneCount}; |
| 15 | +use crate::simd::{LaneCount, Simd, SimdCast, SimdElement, SupportedLaneCount}; |
16 | 16 | use core::cmp::Ordering; |
17 | 17 | use core::{fmt, mem}; |
18 | 18 |
|
@@ -58,7 +58,16 @@ macro_rules! impl_element { |
58 | 58 | where |
59 | 59 | LaneCount<N>: SupportedLaneCount, |
60 | 60 | { |
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 | + } |
62 | 71 | } |
63 | 72 |
|
64 | 73 | #[inline] |
@@ -174,7 +183,10 @@ where |
174 | 183 | #[must_use = "method returns a new mask and does not mutate the original value"] |
175 | 184 | pub unsafe fn from_int_unchecked(value: Simd<T, N>) -> Self { |
176 | 185 | // Safety: the caller must confirm this invariant |
177 | | - unsafe { Self(mask_impl::Mask::from_int_unchecked(value)) } |
| 186 | + unsafe { |
| 187 | + core::intrinsics::assume(<T as Sealed>::valid(value)); |
| 188 | + Self(mask_impl::Mask::from_int_unchecked(value)) |
| 189 | + } |
178 | 190 | } |
179 | 191 |
|
180 | 192 | /// Converts a vector of integers to a mask, where 0 represents `false` and -1 |
|
0 commit comments