Skip to content
/ rust Public
forked from rust-lang/rust

Commit 01140a3

Browse files
committed
miri: implement some llvm.x86.sse.* intrinsics and add tests
Implements LLVM intrisics needed to run most SSE functions from `core::arch::x86{,_64}`. Also adds miri tests for those functions (mostly copied from core_arch tests).
1 parent f21c657 commit 01140a3

File tree

6 files changed

+1720
-0
lines changed

6 files changed

+1720
-0
lines changed

src/tools/miri/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
clippy::enum_variant_names,
2020
clippy::field_reassign_with_default,
2121
clippy::manual_map,
22+
clippy::neg_cmp_op_on_partial_ord,
2223
clippy::new_without_default,
2324
clippy::single_match,
2425
clippy::useless_format,

src/tools/miri/src/shims/foreign_items.rs

+33
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,33 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
918918
this.write_scalar(Scalar::from_f64(res), dest)?;
919919
}
920920

921+
"llvm.prefetch" => {
922+
let [p, rw, loc, ty] =
923+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
924+
925+
let _ = this.read_pointer(p)?;
926+
let rw = this.read_scalar(rw)?.to_i32()?;
927+
let loc = this.read_scalar(loc)?.to_i32()?;
928+
let ty = this.read_scalar(ty)?.to_i32()?;
929+
930+
if ty == 1 {
931+
// Data cache prefetch.
932+
// Notably, we do not have to check the pointer, this operation is never UB!
933+
934+
if !matches!(rw, 0 | 1) {
935+
throw_unsup_format!("invalid `rw` value passed to `llvm.prefetch`: {}", rw);
936+
}
937+
if !matches!(loc, 0..=3) {
938+
throw_unsup_format!(
939+
"invalid `loc` value passed to `llvm.prefetch`: {}",
940+
loc
941+
);
942+
}
943+
} else {
944+
throw_unsup_format!("unsupported `llvm.prefetch` type argument: {}", ty);
945+
}
946+
}
947+
921948
// Architecture-specific shims
922949
"llvm.x86.addcarry.64" if this.tcx.sess.target.arch == "x86_64" => {
923950
// Computes u8+u64+u64, returning tuple (u8,u64) comprising the output carry and truncated sum.
@@ -970,6 +997,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
970997
}
971998
}
972999

1000+
name if name.starts_with("llvm.x86.sse.") => {
1001+
return shims::x86::sse::EvalContextExt::emulate_x86_sse_intrinsic(
1002+
this, link_name, abi, args, dest,
1003+
);
1004+
}
1005+
9731006
// Platform-specific shims
9741007
_ =>
9751008
return match this.tcx.sess.target.os.as_ref() {

src/tools/miri/src/shims/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod foreign_items;
77
pub mod intrinsics;
88
pub mod unix;
99
pub mod windows;
10+
mod x86;
1011

1112
pub mod dlsym;
1213
pub mod env;

src/tools/miri/src/shims/x86/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub(super) mod sse;

0 commit comments

Comments
 (0)