rustc_middle: add Scalar::from_i8 and Scalar::from_i16 and use them in Miri

This commit is contained in:
Eduardo Sánchez Muñoz 2023-09-13 19:41:21 +02:00
parent 76e59c71e8
commit 68687e2535
2 changed files with 15 additions and 9 deletions

View File

@ -266,6 +266,16 @@ pub fn from_int(i: impl Into<i128>, size: Size) -> Self {
.unwrap_or_else(|| bug!("Signed value {:#x} does not fit in {} bits", i, size.bits()))
}
#[inline]
pub fn from_i8(i: i8) -> Self {
Self::from_int(i, Size::from_bits(8))
}
#[inline]
pub fn from_i16(i: i16) -> Self {
Self::from_int(i, Size::from_bits(16))
}
#[inline]
pub fn from_i32(i: i32) -> Self {
Self::from_int(i, Size::from_bits(32))

View File

@ -5,7 +5,6 @@
use rustc_middle::ty::layout::LayoutOf as _;
use rustc_middle::ty::Ty;
use rustc_span::Symbol;
use rustc_target::abi::Size;
use rustc_target::spec::abi::Abi;
use super::FloatCmpOp;
@ -112,7 +111,7 @@ fn emulate_x86_sse2_intrinsic(
// Values are expanded from i16 to i32, so multiplication cannot overflow.
let res = i32::from(left).checked_mul(i32::from(right)).unwrap() >> 16;
this.write_scalar(Scalar::from_int(res, Size::from_bits(16)), &dest)?;
this.write_scalar(Scalar::from_i16(res.try_into().unwrap()), &dest)?;
}
}
// Used to implement the _mm_mulhi_epu16 function.
@ -431,11 +430,8 @@ enum ShiftOp {
let right_res =
i8::try_from(right).unwrap_or(if right < 0 { i8::MIN } else { i8::MAX });
this.write_scalar(Scalar::from_int(left_res, Size::from_bits(8)), &left_dest)?;
this.write_scalar(
Scalar::from_int(right_res, Size::from_bits(8)),
&right_dest,
)?;
this.write_scalar(Scalar::from_i8(left_res.try_into().unwrap()), &left_dest)?;
this.write_scalar(Scalar::from_i8(right_res.try_into().unwrap()), &right_dest)?;
}
}
// Used to implement the _mm_packus_epi16 function.
@ -495,9 +491,9 @@ enum ShiftOp {
let right_res =
i16::try_from(right).unwrap_or(if right < 0 { i16::MIN } else { i16::MAX });
this.write_scalar(Scalar::from_int(left_res, Size::from_bits(16)), &left_dest)?;
this.write_scalar(Scalar::from_i16(left_res.try_into().unwrap()), &left_dest)?;
this.write_scalar(
Scalar::from_int(right_res, Size::from_bits(16)),
Scalar::from_i16(right_res.try_into().unwrap()),
&right_dest,
)?;
}