miri/shims/x86/
sse3.rs

1use rustc_middle::mir;
2use rustc_middle::ty::Ty;
3use rustc_span::Symbol;
4use rustc_target::callconv::{Conv, FnAbi};
5
6use super::horizontal_bin_op;
7use crate::*;
8
9impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
10pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
11    fn emulate_x86_sse3_intrinsic(
12        &mut self,
13        link_name: Symbol,
14        abi: &FnAbi<'tcx, Ty<'tcx>>,
15        args: &[OpTy<'tcx>],
16        dest: &MPlaceTy<'tcx>,
17    ) -> InterpResult<'tcx, EmulateItemResult> {
18        let this = self.eval_context_mut();
19        this.expect_target_feature_for_intrinsic(link_name, "sse3")?;
20        // Prefix should have already been checked.
21        let unprefixed_name = link_name.as_str().strip_prefix("llvm.x86.sse3.").unwrap();
22
23        match unprefixed_name {
24            // Used to implement the _mm_h{add,sub}_p{s,d} functions.
25            // Horizontally add/subtract adjacent floating point values
26            // in `left` and `right`.
27            "hadd.ps" | "hadd.pd" | "hsub.ps" | "hsub.pd" => {
28                let [left, right] = this.check_shim(abi, Conv::C, link_name, args)?;
29
30                let which = match unprefixed_name {
31                    "hadd.ps" | "hadd.pd" => mir::BinOp::Add,
32                    "hsub.ps" | "hsub.pd" => mir::BinOp::Sub,
33                    _ => unreachable!(),
34                };
35
36                horizontal_bin_op(this, which, /*saturating*/ false, left, right, dest)?;
37            }
38            // Used to implement the _mm_lddqu_si128 function.
39            // Reads a 128-bit vector from an unaligned pointer. This intrinsic
40            // is expected to perform better than a regular unaligned read when
41            // the data crosses a cache line, but for Miri this is just a regular
42            // unaligned read.
43            "ldu.dq" => {
44                let [src_ptr] = this.check_shim(abi, Conv::C, link_name, args)?;
45                let src_ptr = this.read_pointer(src_ptr)?;
46                let dest = dest.force_mplace(this)?;
47
48                this.mem_copy(src_ptr, dest.ptr(), dest.layout.size, /*nonoverlapping*/ true)?;
49            }
50            _ => return interp_ok(EmulateItemResult::NotSupported),
51        }
52        interp_ok(EmulateItemResult::NeedsReturn)
53    }
54}