simd_select_bitmask: support passing the mask as an array

This commit is contained in:
Ralf Jung 2023-12-03 11:28:40 +01:00
parent 6318e9dd89
commit 11db9de728
2 changed files with 28 additions and 3 deletions

View File

@ -386,7 +386,6 @@ enum Op {
let (dest, dest_len) = this.place_to_simd(dest)?;
let bitmask_len = dest_len.max(8);
assert!(mask.layout.ty.is_integral());
assert!(bitmask_len <= 64);
assert_eq!(bitmask_len, mask.layout.size.bits());
assert_eq!(dest_len, yes_len);
@ -394,8 +393,18 @@ enum Op {
let dest_len = u32::try_from(dest_len).unwrap();
let bitmask_len = u32::try_from(bitmask_len).unwrap();
let mask: u64 =
this.read_scalar(mask)?.to_bits(mask.layout.size)?.try_into().unwrap();
// The mask can be a single integer or an array.
let mask: u64 = match mask.layout.ty.kind() {
ty::Int(..) | ty::Uint(..) =>
this.read_scalar(mask)?.to_bits(mask.layout.size)?.try_into().unwrap(),
ty::Array(elem, _) if matches!(elem.kind(), ty::Uint(ty::UintTy::U8)) => {
let mask_ty = this.machine.layouts.uint(mask.layout.size).unwrap();
let mask = mask.transmute(mask_ty, this)?;
this.read_scalar(&mask)?.to_bits(mask_ty.size)?.try_into().unwrap()
}
_ => bug!("simd_select_bitmask: invalid mask type {}", mask.layout.ty),
};
for i in 0..dest_len {
let mask = mask
& 1u64

View File

@ -247,6 +247,22 @@ fn simd_mask() {
assert_eq!(bitmask2, [0b0001]);
}
}
// This used to cause an ICE.
let bitmask = u8x8::from_array([0b01000101, 0, 0, 0, 0, 0, 0, 0]);
assert_eq!(
mask32x8::from_bitmask_vector(bitmask),
mask32x8::from_array([true, false, true, false, false, false, true, false]),
);
let bitmask =
u8x16::from_array([0b01000101, 0b11110000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
assert_eq!(
mask32x16::from_bitmask_vector(bitmask),
mask32x16::from_array([
true, false, true, false, false, false, true, false, false, false, false, false, true,
true, true, true,
]),
);
}
fn simd_cast() {