commit
939914e39d
@ -181,6 +181,13 @@ where
|
||||
self.0.to_int()
|
||||
}
|
||||
|
||||
/// Converts the mask to a mask of any other lane size.
|
||||
#[inline]
|
||||
#[must_use = "method returns a new mask and does not mutate the original value"]
|
||||
pub fn cast<U: MaskElement>(self) -> Mask<U, LANES> {
|
||||
Mask(self.0.convert())
|
||||
}
|
||||
|
||||
/// Tests the value of the specified lane.
|
||||
///
|
||||
/// # Safety
|
||||
@ -571,7 +578,7 @@ macro_rules! impl_from {
|
||||
LaneCount<LANES>: SupportedLaneCount,
|
||||
{
|
||||
fn from(value: Mask<$from, LANES>) -> Self {
|
||||
Self(value.0.convert())
|
||||
value.cast()
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
@ -99,6 +99,29 @@ macro_rules! test_mask_api {
|
||||
assert_eq!(bitmask, 0b01);
|
||||
assert_eq!(core_simd::Mask::<$type, 2>::from_bitmask(bitmask), mask);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cast() {
|
||||
fn cast_impl<T: core_simd::MaskElement>()
|
||||
where
|
||||
core_simd::Mask<$type, 8>: Into<core_simd::Mask<T, 8>>,
|
||||
{
|
||||
let values = [true, false, false, true, false, false, true, false];
|
||||
let mask = core_simd::Mask::<$type, 8>::from_array(values);
|
||||
|
||||
let cast_mask = mask.cast::<T>();
|
||||
assert_eq!(values, cast_mask.to_array());
|
||||
|
||||
let into_mask: core_simd::Mask<T, 8> = mask.into();
|
||||
assert_eq!(values, into_mask.to_array());
|
||||
}
|
||||
|
||||
cast_impl::<i8>();
|
||||
cast_impl::<i16>();
|
||||
cast_impl::<i32>();
|
||||
cast_impl::<i64>();
|
||||
cast_impl::<isize>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user