Skip to content

Commit 2558bf2

Browse files
committed
Workaround for missing #[rustc_args_required_const(..)] support
cc #666
1 parent 6bf47ad commit 2558bf2

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

example/std_example.rs

+16
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ unsafe fn test_simd() {
7575
test_mm_cvtepi8_epi16();
7676
test_mm_cvtsi128_si64();
7777

78+
// FIXME(#666) implement `#[rustc_arg_required_const(..)]` support
79+
//test_mm_extract_epi8();
80+
7881
let mask1 = _mm_movemask_epi8(dbg!(_mm_setr_epi8(255u8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
7982
assert_eq!(mask1, 1);
8083
}
@@ -194,6 +197,19 @@ unsafe fn test_mm_cvtepi8_epi16() {
194197
assert_eq_m128i(r, e);
195198
}
196199

200+
#[target_feature(enable = "sse4.1")]
201+
unsafe fn test_mm_extract_epi8() {
202+
#[rustfmt::skip]
203+
let a = _mm_setr_epi8(
204+
-1, 1, 2, 3, 4, 5, 6, 7,
205+
8, 9, 10, 11, 12, 13, 14, 15
206+
);
207+
let r1 = _mm_extract_epi8(a, 0);
208+
let r2 = _mm_extract_epi8(a, 19);
209+
assert_eq!(r1, 0xFF);
210+
assert_eq!(r2, 3);
211+
}
212+
197213
#[derive(PartialEq)]
198214
enum LoopState {
199215
Continue(()),

src/constant.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -439,22 +439,19 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for TransPlaceInterpreter {
439439
pub fn mir_operand_get_const_val<'tcx>(
440440
fx: &FunctionCx<'_, 'tcx, impl Backend>,
441441
operand: &Operand<'tcx>,
442-
) -> Result<&'tcx Const<'tcx>, String> {
442+
) -> Option<&'tcx Const<'tcx>> {
443443
let place = match operand {
444-
Operand::Copy(place) => place,
445-
Operand::Constant(const_) => return Ok(force_eval_const(fx, const_.literal)),
446-
_ => return Err(format!("{:?}", operand)),
444+
Operand::Copy(place) | Operand::Move(place) => place,
445+
Operand::Constant(const_) => return Some(force_eval_const(fx, const_.literal)),
447446
};
448447

449448
assert!(place.projection.is_none());
450449
let static_ = match &place.base {
451-
PlaceBase::Static(static_) => {
452-
static_
453-
}
454-
PlaceBase::Local(_) => return Err("local".to_string()),
450+
PlaceBase::Static(static_) => static_,
451+
PlaceBase::Local(_) => return None,
455452
};
456453

457-
Ok(match &static_.kind {
454+
Some(match &static_.kind {
458455
StaticKind::Static(_) => unimplemented!(),
459456
StaticKind::Promoted(promoted) => {
460457
fx.tcx.const_eval(ParamEnv::reveal_all().and(GlobalId {

src/intrinsics.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,17 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
951951
};
952952

953953
simd_extract, (c v, o idx) {
954-
let idx_const = crate::constant::mir_operand_get_const_val(fx, idx).expect("simd_extract* idx not const");
954+
let idx_const = if let Some(idx_const) = crate::constant::mir_operand_get_const_val(fx, idx) {
955+
idx_const
956+
} else {
957+
fx.tcx.sess.span_warn(
958+
fx.mir.span,
959+
"`#[rustc_arg_required_const(..)]` is not yet supported. Calling this function will panic.",
960+
);
961+
crate::trap::trap_panic(fx, "`#[rustc_arg_required_const(..)]` is not yet supported.");
962+
return;
963+
};
964+
955965
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).expect(&format!("kind not scalar: {:?}", idx_const));
956966
let (_lane_type, lane_count) = lane_type_and_count(fx, v.layout(), intrinsic);
957967
if idx >= lane_count.into() {

0 commit comments

Comments
 (0)