Skip to content

Commit ccbcbee

Browse files
authored
Rollup merge of rust-lang#137953 - RalfJung:simd-intrinsic-masks, r=WaffleLapkin
simd intrinsics with mask: accept unsigned integer masks, and fix some of the errors It's not clear at all why the mask would have to be signed, it is anyway interpreted bitwise. The backend should just make sure that works no matter the surface-level type; our LLVM backend already does this correctly. The note of "the mask may be widened, which only has the correct behavior for signed integers" explains... nothing? Why can't the code do the widening correctly? If necessary, just cast to the signed type first... Also while we are at it, fix the errors. For simd_masked_load/store, the errors talked about the "third argument" but they meant the first argument (the mask is the first argument there). They also used the wrong type for `expected_element`. I have extremely low confidence in the GCC part of this PR. See [discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/257879-project-portable-simd/topic/On.20the.20sign.20of.20masks)
2 parents e32e494 + fc4afea commit ccbcbee

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/intrinsic/simd.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,14 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
447447
m_len == v_len,
448448
InvalidMonomorphization::MismatchedLengths { span, name, m_len, v_len }
449449
);
450+
// TODO: also support unsigned integers.
450451
match *m_elem_ty.kind() {
451452
ty::Int(_) => {}
452-
_ => return_error!(InvalidMonomorphization::MaskType { span, name, ty: m_elem_ty }),
453+
_ => return_error!(InvalidMonomorphization::MaskWrongElementType {
454+
span,
455+
name,
456+
ty: m_elem_ty
457+
}),
453458
}
454459
return Ok(bx.vector_select(args[0].immediate(), args[1].immediate(), args[2].immediate()));
455460
}
@@ -991,19 +996,15 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
991996
assert_eq!(pointer_count - 1, ptr_count(element_ty0));
992997
assert_eq!(underlying_ty, non_ptr(element_ty0));
993998

994-
// The element type of the third argument must be a signed integer type of any width:
999+
// The element type of the third argument must be an integer type of any width:
1000+
// TODO: also support unsigned integers.
9951001
let (_, element_ty2) = arg_tys[2].simd_size_and_type(bx.tcx());
9961002
match *element_ty2.kind() {
9971003
ty::Int(_) => (),
9981004
_ => {
9991005
require!(
10001006
false,
1001-
InvalidMonomorphization::ThirdArgElementType {
1002-
span,
1003-
name,
1004-
expected_element: element_ty2,
1005-
third_arg: arg_tys[2]
1006-
}
1007+
InvalidMonomorphization::MaskWrongElementType { span, name, ty: element_ty2 }
10071008
);
10081009
}
10091010
}
@@ -1109,17 +1110,13 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
11091110
assert_eq!(underlying_ty, non_ptr(element_ty0));
11101111

11111112
// The element type of the third argument must be a signed integer type of any width:
1113+
// TODO: also support unsigned integers.
11121114
match *element_ty2.kind() {
11131115
ty::Int(_) => (),
11141116
_ => {
11151117
require!(
11161118
false,
1117-
InvalidMonomorphization::ThirdArgElementType {
1118-
span,
1119-
name,
1120-
expected_element: element_ty2,
1121-
third_arg: arg_tys[2]
1122-
}
1119+
InvalidMonomorphization::MaskWrongElementType { span, name, ty: element_ty2 }
11231120
);
11241121
}
11251122
}

0 commit comments

Comments
 (0)