Skip to content

Commit 1dcbe6c

Browse files
committed
rustc_middle: add Scalar::from_i8 and Scalar::from_i16 and use them in Miri
1 parent 3448551 commit 1dcbe6c

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/shims/x86/sse2.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_apfloat::{
55
use rustc_middle::ty::layout::LayoutOf as _;
66
use rustc_middle::ty::Ty;
77
use rustc_span::Symbol;
8-
use rustc_target::abi::Size;
98
use rustc_target::spec::abi::Abi;
109

1110
use super::FloatCmpOp;
@@ -112,7 +111,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
112111

113112
// Values are expanded from i16 to i32, so multiplication cannot overflow.
114113
let res = i32::from(left).checked_mul(i32::from(right)).unwrap() >> 16;
115-
this.write_scalar(Scalar::from_int(res, Size::from_bits(16)), &dest)?;
114+
this.write_scalar(Scalar::from_i16(res.try_into().unwrap()), &dest)?;
116115
}
117116
}
118117
// Used to implement the _mm_mulhi_epu16 function.
@@ -431,11 +430,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
431430
let right_res =
432431
i8::try_from(right).unwrap_or(if right < 0 { i8::MIN } else { i8::MAX });
433432

434-
this.write_scalar(Scalar::from_int(left_res, Size::from_bits(8)), &left_dest)?;
435-
this.write_scalar(
436-
Scalar::from_int(right_res, Size::from_bits(8)),
437-
&right_dest,
438-
)?;
433+
this.write_scalar(Scalar::from_i8(left_res.try_into().unwrap()), &left_dest)?;
434+
this.write_scalar(Scalar::from_i8(right_res.try_into().unwrap()), &right_dest)?;
439435
}
440436
}
441437
// Used to implement the _mm_packus_epi16 function.
@@ -495,9 +491,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
495491
let right_res =
496492
i16::try_from(right).unwrap_or(if right < 0 { i16::MIN } else { i16::MAX });
497493

498-
this.write_scalar(Scalar::from_int(left_res, Size::from_bits(16)), &left_dest)?;
494+
this.write_scalar(Scalar::from_i16(left_res.try_into().unwrap()), &left_dest)?;
499495
this.write_scalar(
500-
Scalar::from_int(right_res, Size::from_bits(16)),
496+
Scalar::from_i16(right_res.try_into().unwrap()),
501497
&right_dest,
502498
)?;
503499
}

0 commit comments

Comments
 (0)