Skip to content

Commit ea88de2

Browse files
committed
miri: reduce code duplication in SSE cvtsi2ss/cvtsi642ss
1 parent 89a017d commit ea88de2

File tree

1 file changed

+12
-37
lines changed

1 file changed

+12
-37
lines changed

src/shims/x86/sse.rs

+12-37
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
204204

205205
this.write_scalar(res, dest)?;
206206
}
207-
// Used to implement the _mm_cvtsi32_ss function.
208-
// Converts `right` from i32 to f32. Returns a SIMD vector with
207+
// Used to implement the _mm_cvtsi32_ss and _mm_cvtsi64_ss functions.
208+
// Converts `right` from i32/i64 to f32. Returns a SIMD vector with
209209
// the result in the first component and the remaining components
210210
// are copied from `left`.
211211
// https://www.felixcloutier.com/x86/cvtsi2ss
212-
"cvtsi2ss" => {
212+
"cvtsi2ss" | "cvtsi642ss" => {
213213
let [left, right] =
214214
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
215215

@@ -218,42 +218,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
218218

219219
assert_eq!(dest_len, left_len);
220220

221-
let right = this.read_scalar(right)?.to_i32()?;
222-
223-
let res0 = Scalar::from_f32(Single::from_i128(right.into()).value);
224-
this.write_scalar(res0, &this.project_index(&dest, 0)?)?;
221+
let right = this.read_immediate(right)?;
222+
let dest0 = this.project_index(&dest, 0)?;
223+
let res0 = this.int_to_int_or_float(&right, dest0.layout.ty)?;
224+
this.write_immediate(res0, &dest0)?;
225225

226226
for i in 1..dest_len {
227-
let left = this.read_immediate(&this.project_index(&left, i)?)?;
228-
let dest = this.project_index(&dest, i)?;
229-
230-
this.write_immediate(*left, &dest)?;
231-
}
232-
}
233-
// Used to implement the _mm_cvtsi64_ss function.
234-
// Converts `right` from i64 to f32. Returns a SIMD vector with
235-
// the result in the first component and the remaining components
236-
// are copied from `left`.
237-
// https://www.felixcloutier.com/x86/cvtsi2ss
238-
"cvtsi642ss" => {
239-
let [left, right] =
240-
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
241-
242-
let (left, left_len) = this.operand_to_simd(left)?;
243-
let (dest, dest_len) = this.place_to_simd(dest)?;
244-
245-
assert_eq!(dest_len, left_len);
246-
247-
let right = this.read_scalar(right)?.to_i64()?;
248-
249-
let res0 = Scalar::from_f32(Single::from_i128(right.into()).value);
250-
this.write_scalar(res0, &this.project_index(&dest, 0)?)?;
251-
252-
for i in 1..dest_len {
253-
let left = this.read_immediate(&this.project_index(&left, i)?)?;
254-
let dest = this.project_index(&dest, i)?;
255-
256-
this.write_immediate(*left, &dest)?;
227+
this.copy_op(
228+
&this.project_index(&left, i)?,
229+
&this.project_index(&dest, i)?,
230+
/*allow_transmute*/ false,
231+
)?;
257232
}
258233
}
259234
// Used to implement the _mm_movemask_ps function.

0 commit comments

Comments
 (0)