Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support vectors with fewer than 8 elements for simd_select_bitmask #77504

Merged
merged 1 commit into from
Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment above the require that explains this? I found the juxtaposition between this and the error message below a bit confusing.

"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);
}
}