Merge pull request #393 from rust-lang/assume-masks-are-correct
Assume masks are correct
This commit is contained in:
commit
7348d2da1b
@ -12,7 +12,7 @@
|
|||||||
)]
|
)]
|
||||||
mod mask_impl;
|
mod mask_impl;
|
||||||
|
|
||||||
use crate::simd::{cmp::SimdPartialEq, LaneCount, Simd, SimdCast, SimdElement, SupportedLaneCount};
|
use crate::simd::{LaneCount, Simd, SimdCast, SimdElement, SupportedLaneCount};
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
use core::{fmt, mem};
|
use core::{fmt, mem};
|
||||||
|
|
||||||
@ -58,7 +58,16 @@ macro_rules! impl_element {
|
|||||||
where
|
where
|
||||||
LaneCount<N>: SupportedLaneCount,
|
LaneCount<N>: SupportedLaneCount,
|
||||||
{
|
{
|
||||||
(value.simd_eq(Simd::splat(0 as _)) | value.simd_eq(Simd::splat(-1 as _))).all()
|
// We can't use `Simd` directly, because `Simd`'s functions call this function and
|
||||||
|
// we will end up with an infinite loop.
|
||||||
|
// Safety: `value` is an integer vector
|
||||||
|
unsafe {
|
||||||
|
use core::intrinsics::simd;
|
||||||
|
let falses: Simd<Self, N> = simd::simd_eq(value, Simd::splat(0 as _));
|
||||||
|
let trues: Simd<Self, N> = simd::simd_eq(value, Simd::splat(-1 as _));
|
||||||
|
let valid: Simd<Self, N> = simd::simd_or(falses, trues);
|
||||||
|
simd::simd_reduce_all(valid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -174,7 +183,10 @@ where
|
|||||||
#[must_use = "method returns a new mask and does not mutate the original value"]
|
#[must_use = "method returns a new mask and does not mutate the original value"]
|
||||||
pub unsafe fn from_int_unchecked(value: Simd<T, N>) -> Self {
|
pub unsafe fn from_int_unchecked(value: Simd<T, N>) -> Self {
|
||||||
// Safety: the caller must confirm this invariant
|
// Safety: the caller must confirm this invariant
|
||||||
unsafe { Self(mask_impl::Mask::from_int_unchecked(value)) }
|
unsafe {
|
||||||
|
core::intrinsics::assume(<T as Sealed>::valid(value));
|
||||||
|
Self(mask_impl::Mask::from_int_unchecked(value))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a vector of integers to a mask, where 0 represents `false` and -1
|
/// Converts a vector of integers to a mask, where 0 represents `false` and -1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user