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

Commit a45f181

Browse files
committed
Auto merge of rust-lang#2989 - eduardosm:x86-intrinsics, r=RalfJung
miri: implement some `llvm.x86.sse.*` intrinsics and add tests PR moved from rust-lang#113932. 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). r? `@RalfJung` The first commit is the same that the commit in the PR I had opened in the Rust repository. I addressed review comments in additional commits to make it easier to review. I also fixed formatting and clippy warnings.
2 parents 6276e5a + 01140a3 commit a45f181

File tree

6 files changed

+1720
-0
lines changed

6 files changed

+1720
-0
lines changed

Diff for: src/tools/miri/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
clippy::enum_variant_names,
2222
clippy::field_reassign_with_default,
2323
clippy::manual_map,
24+
clippy::neg_cmp_op_on_partial_ord,
2425
clippy::new_without_default,
2526
clippy::single_match,
2627
clippy::useless_format,

Diff for: src/tools/miri/src/shims/foreign_items.rs

+33
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,33 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
942942
this.write_scalar(Scalar::from_u64(res.to_bits()), dest)?;
943943
}
944944

945+
"llvm.prefetch" => {
946+
let [p, rw, loc, ty] =
947+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
948+
949+
let _ = this.read_pointer(p)?;
950+
let rw = this.read_scalar(rw)?.to_i32()?;
951+
let loc = this.read_scalar(loc)?.to_i32()?;
952+
let ty = this.read_scalar(ty)?.to_i32()?;
953+
954+
if ty == 1 {
955+
// Data cache prefetch.
956+
// Notably, we do not have to check the pointer, this operation is never UB!
957+
958+
if !matches!(rw, 0 | 1) {
959+
throw_unsup_format!("invalid `rw` value passed to `llvm.prefetch`: {}", rw);
960+
}
961+
if !matches!(loc, 0..=3) {
962+
throw_unsup_format!(
963+
"invalid `loc` value passed to `llvm.prefetch`: {}",
964+
loc
965+
);
966+
}
967+
} else {
968+
throw_unsup_format!("unsupported `llvm.prefetch` type argument: {}", ty);
969+
}
970+
}
971+
945972
// Architecture-specific shims
946973
"llvm.x86.addcarry.64" if this.tcx.sess.target.arch == "x86_64" => {
947974
// Computes u8+u64+u64, returning tuple (u8,u64) comprising the output carry and truncated sum.
@@ -994,6 +1021,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
9941021
}
9951022
}
9961023

1024+
name if name.starts_with("llvm.x86.sse.") => {
1025+
return shims::x86::sse::EvalContextExt::emulate_x86_sse_intrinsic(
1026+
this, link_name, abi, args, dest,
1027+
);
1028+
}
1029+
9971030
// Platform-specific shims
9981031
_ =>
9991032
return match this.tcx.sess.target.os.as_ref() {

Diff for: 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;

Diff for: 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)