Support vectors with fewer than 8 elements for simd_select_bitmask

This commit is contained in:
Amanieu d'Antras 2020-10-03 16:13:06 +01:00
parent 6f56fbdc1c
commit e41a14412e
4 changed files with 37 additions and 8 deletions

View File

@ -793,14 +793,18 @@ fn generic_simd_intrinsic(
require_simd!(arg_tys[1], "argument");
let v_len = arg_tys[1].simd_size(tcx);
require!(
m_len == v_len,
// Allow masks for vectors with fewer than 8 elements to be
// represented with a u8 or i8.
m_len == v_len || (m_len == 8 && v_len < 8),
"mismatched lengths: mask length `{}` != other vector length `{}`",
m_len,
v_len
);
let i1 = bx.type_i1();
let i1xn = bx.type_vector(i1, m_len);
let m_i1s = bx.bitcast(args[0].immediate(), i1xn);
let im = bx.type_ix(v_len);
let i1xn = bx.type_vector(i1, v_len);
let m_im = bx.trunc(args[0].immediate(), im);
let m_i1s = bx.bitcast(m_im, i1xn);
return Ok(bx.select(m_i1s, args[1].immediate(), args[2].immediate()));
}

View File

@ -49,8 +49,8 @@ fn main() {
simd_select(m4, 0u32, 1u32);
//~^ ERROR found non-SIMD `u32`
simd_select_bitmask(0u8, x, x);
//~^ ERROR mask length `8` != other vector length `4`
simd_select_bitmask(0u16, x, x);
//~^ ERROR mask length `16` != other vector length `4`
//
simd_select_bitmask(0u8, 1u32, 2u32);
//~^ ERROR found non-SIMD `u32`

View File

@ -22,11 +22,11 @@ error[E0511]: invalid monomorphization of `simd_select` intrinsic: expected SIMD
LL | simd_select(m4, 0u32, 1u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_select_bitmask` intrinsic: mismatched lengths: mask length `8` != other vector length `4`
error[E0511]: invalid monomorphization of `simd_select_bitmask` intrinsic: mismatched lengths: mask length `16` != other vector length `4`
--> $DIR/simd-intrinsic-generic-select.rs:52:9
|
LL | simd_select_bitmask(0u8, x, x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | simd_select_bitmask(0u16, x, x);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_select_bitmask` intrinsic: expected SIMD argument type, found non-SIMD `u32`
--> $DIR/simd-intrinsic-generic-select.rs:55:9

View File

@ -167,4 +167,29 @@ fn main() {
let e = u32x8(8, 9, 10, 11, 4, 5, 6, 7);
assert_eq!(r, e);
}
unsafe {
let a = u32x4(0, 1, 2, 3);
let b = u32x4(4, 5, 6, 7);
let r: u32x4 = simd_select_bitmask(0u8, a, b);
let e = b;
assert_eq!(r, e);
let r: u32x4 = simd_select_bitmask(0xfu8, a, b);
let e = a;
assert_eq!(r, e);
let r: u32x4 = simd_select_bitmask(0b0101u8, a, b);
let e = u32x4(0, 5, 2, 7);
assert_eq!(r, e);
let r: u32x4 = simd_select_bitmask(0b1010u8, a, b);
let e = u32x4(4, 1, 6, 3);
assert_eq!(r, e);
let r: u32x4 = simd_select_bitmask(0b1100u8, a, b);
let e = u32x4(4, 5, 2, 3);
assert_eq!(r, e);
}
}