Skip to content

Commit

Permalink
Rollup merge of #77504 - Amanieu:select_simd_bitmask, r=ecstatic-morse
Browse files Browse the repository at this point in the history
Support vectors with fewer than 8 elements for simd_select_bitmask

Resolves the issue raised here: rust-lang/stdarch#310 (comment)
  • Loading branch information
jonas-schievink authored Oct 3, 2020
2 parents 317d122 + e41a144 commit 5efe9be
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
10 changes: 7 additions & 3 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/simd-intrinsic/simd-intrinsic-generic-select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/test/ui/simd/simd-intrinsic-generic-select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 5efe9be

Please sign in to comment.