diff options
| author | Yoh Deadfall <yoh.deadfall@hotmail.com> | 2024-11-11 22:31:47 +0300 |
|---|---|---|
| committer | Yoh Deadfall <yoh.deadfall@hotmail.com> | 2024-11-11 22:31:47 +0300 |
| commit | e43a5c0ac558773686278b1b3ce2f5067553c9cd (patch) | |
| tree | 205f7cd4ca2b08b78d92a70151c10e7c5f56621f | |
| parent | e2b70276611a524a5de8c4816d2260d44b1ca2b4 (diff) | |
| download | rust-e43a5c0ac558773686278b1b3ce2f5067553c9cd.tar.gz rust-e43a5c0ac558773686278b1b3ce2f5067553c9cd.zip | |
Renamed this arguments to ecx
| -rw-r--r-- | src/tools/miri/src/helpers.rs | 4 | ||||
| -rw-r--r-- | src/tools/miri/src/machine.rs | 12 | ||||
| -rw-r--r-- | src/tools/miri/src/provenance_gc.rs | 20 | ||||
| -rw-r--r-- | src/tools/miri/src/shims/foreign_items.rs | 26 | ||||
| -rw-r--r-- | src/tools/miri/src/shims/unix/android/thread.rs | 26 | ||||
| -rw-r--r-- | src/tools/miri/src/shims/unix/linux/sync.rs | 72 | ||||
| -rw-r--r-- | src/tools/miri/src/shims/unix/linux/syscall.rs | 28 | ||||
| -rw-r--r-- | src/tools/miri/src/shims/x86/aesni.rs | 19 | ||||
| -rw-r--r-- | src/tools/miri/src/shims/x86/gfni.rs | 18 | ||||
| -rw-r--r-- | src/tools/miri/src/shims/x86/mod.rs | 458 | ||||
| -rw-r--r-- | src/tools/miri/src/shims/x86/sha.rs | 12 | ||||
| -rw-r--r-- | src/tools/miri/src/shims/x86/sse42.rs | 70 |
12 files changed, 382 insertions, 383 deletions
diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index 526030bef2e..b28bd2eacb7 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -1009,7 +1009,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { let this = self.eval_context_ref(); fn float_to_int_inner<'tcx, F: rustc_apfloat::Float>( - this: &MiriInterpCx<'tcx>, + ecx: &MiriInterpCx<'tcx>, src: F, cast_to: TyAndLayout<'tcx>, round: rustc_apfloat::Round, @@ -1029,7 +1029,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // Nothing else _ => span_bug!( - this.cur_span(), + ecx.cur_span(), "attempted float-to-int conversion with non-int output type {}", cast_to.ty, ), diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 9668998aaa3..6e9d8d3a65e 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -730,20 +730,20 @@ impl<'tcx> MiriMachine<'tcx> { } pub(crate) fn late_init( - this: &mut MiriInterpCx<'tcx>, + ecx: &mut MiriInterpCx<'tcx>, config: &MiriConfig, on_main_stack_empty: StackEmptyCallback<'tcx>, ) -> InterpResult<'tcx> { - EnvVars::init(this, config)?; - MiriMachine::init_extern_statics(this)?; - ThreadManager::init(this, on_main_stack_empty); + EnvVars::init(ecx, config)?; + MiriMachine::init_extern_statics(ecx)?; + ThreadManager::init(ecx, on_main_stack_empty); interp_ok(()) } - pub(crate) fn add_extern_static(this: &mut MiriInterpCx<'tcx>, name: &str, ptr: Pointer) { + pub(crate) fn add_extern_static(ecx: &mut MiriInterpCx<'tcx>, name: &str, ptr: Pointer) { // This got just allocated, so there definitely is a pointer here. let ptr = ptr.into_pointer_or_addr().unwrap(); - this.machine.extern_statics.try_insert(Symbol::intern(name), ptr).unwrap(); + ecx.machine.extern_statics.try_insert(Symbol::intern(name), ptr).unwrap(); } pub(crate) fn communicate(&self) -> bool { diff --git a/src/tools/miri/src/provenance_gc.rs b/src/tools/miri/src/provenance_gc.rs index 6042a9eb2eb..b3d715db9cd 100644 --- a/src/tools/miri/src/provenance_gc.rs +++ b/src/tools/miri/src/provenance_gc.rs @@ -195,10 +195,10 @@ impl LiveAllocs<'_, '_> { } } -fn remove_unreachable_tags<'tcx>(this: &mut MiriInterpCx<'tcx>, tags: FxHashSet<BorTag>) { +fn remove_unreachable_tags<'tcx>(ecx: &mut MiriInterpCx<'tcx>, tags: FxHashSet<BorTag>) { // Avoid iterating all allocations if there's no borrow tracker anyway. - if this.machine.borrow_tracker.is_some() { - this.memory.alloc_map().iter(|it| { + if ecx.machine.borrow_tracker.is_some() { + ecx.memory.alloc_map().iter(|it| { for (_id, (_kind, alloc)) in it { alloc.extra.borrow_tracker.as_ref().unwrap().remove_unreachable_tags(&tags); } @@ -206,16 +206,16 @@ fn remove_unreachable_tags<'tcx>(this: &mut MiriInterpCx<'tcx>, tags: FxHashSet< } } -fn remove_unreachable_allocs<'tcx>(this: &mut MiriInterpCx<'tcx>, allocs: FxHashSet<AllocId>) { - let allocs = LiveAllocs { ecx: this, collected: allocs }; - this.machine.allocation_spans.borrow_mut().retain(|id, _| allocs.is_live(*id)); - this.machine.symbolic_alignment.borrow_mut().retain(|id, _| allocs.is_live(*id)); - this.machine.alloc_addresses.borrow_mut().remove_unreachable_allocs(&allocs); - if let Some(borrow_tracker) = &this.machine.borrow_tracker { +fn remove_unreachable_allocs<'tcx>(ecx: &mut MiriInterpCx<'tcx>, allocs: FxHashSet<AllocId>) { + let allocs = LiveAllocs { ecx, collected: allocs }; + ecx.machine.allocation_spans.borrow_mut().retain(|id, _| allocs.is_live(*id)); + ecx.machine.symbolic_alignment.borrow_mut().retain(|id, _| allocs.is_live(*id)); + ecx.machine.alloc_addresses.borrow_mut().remove_unreachable_allocs(&allocs); + if let Some(borrow_tracker) = &ecx.machine.borrow_tracker { borrow_tracker.borrow_mut().remove_unreachable_allocs(&allocs); } // Clean up core (non-Miri-specific) state. - this.remove_unreachable_allocs(&allocs.collected); + ecx.remove_unreachable_allocs(&allocs.collected); } impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {} diff --git a/src/tools/miri/src/shims/foreign_items.rs b/src/tools/miri/src/shims/foreign_items.rs index b74491a2f8e..4dc857ef30b 100644 --- a/src/tools/miri/src/shims/foreign_items.rs +++ b/src/tools/miri/src/shims/foreign_items.rs @@ -496,14 +496,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { // Rust allocation "__rust_alloc" | "miri_alloc" => { - let default = |this: &mut MiriInterpCx<'tcx>| { + let default = |ecx: &mut MiriInterpCx<'tcx>| { // Only call `check_shim` when `#[global_allocator]` isn't used. When that // macro is used, we act like no shim exists, so that the exported function can run. - let [size, align] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?; - let size = this.read_target_usize(size)?; - let align = this.read_target_usize(align)?; + let [size, align] = ecx.check_shim(abi, ExternAbi::Rust, link_name, args)?; + let size = ecx.read_target_usize(size)?; + let align = ecx.read_target_usize(align)?; - this.check_rustc_alloc_request(size, align)?; + ecx.check_rustc_alloc_request(size, align)?; let memory_kind = match link_name.as_str() { "__rust_alloc" => MiriMemoryKind::Rust, @@ -511,13 +511,13 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { _ => unreachable!(), }; - let ptr = this.allocate_ptr( + let ptr = ecx.allocate_ptr( Size::from_bytes(size), Align::from_bytes(align).unwrap(), memory_kind.into(), )?; - this.write_pointer(ptr, dest) + ecx.write_pointer(ptr, dest) }; match link_name.as_str() { @@ -555,14 +555,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { }); } "__rust_dealloc" | "miri_dealloc" => { - let default = |this: &mut MiriInterpCx<'tcx>| { + let default = |ecx: &mut MiriInterpCx<'tcx>| { // See the comment for `__rust_alloc` why `check_shim` is only called in the // default case. let [ptr, old_size, align] = - this.check_shim(abi, ExternAbi::Rust, link_name, args)?; - let ptr = this.read_pointer(ptr)?; - let old_size = this.read_target_usize(old_size)?; - let align = this.read_target_usize(align)?; + ecx.check_shim(abi, ExternAbi::Rust, link_name, args)?; + let ptr = ecx.read_pointer(ptr)?; + let old_size = ecx.read_target_usize(old_size)?; + let align = ecx.read_target_usize(align)?; let memory_kind = match link_name.as_str() { "__rust_dealloc" => MiriMemoryKind::Rust, @@ -571,7 +571,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { }; // No need to check old_size/align; we anyway check that they match the allocation. - this.deallocate_ptr( + ecx.deallocate_ptr( ptr, Some((Size::from_bytes(old_size), Align::from_bytes(align).unwrap())), memory_kind.into(), diff --git a/src/tools/miri/src/shims/unix/android/thread.rs b/src/tools/miri/src/shims/unix/android/thread.rs index 093b7405ccd..f8a0b3a85a2 100644 --- a/src/tools/miri/src/shims/unix/android/thread.rs +++ b/src/tools/miri/src/shims/unix/android/thread.rs @@ -8,7 +8,7 @@ use crate::*; const TASK_COMM_LEN: usize = 16; pub fn prctl<'tcx>( - this: &mut MiriInterpCx<'tcx>, + ecx: &mut MiriInterpCx<'tcx>, link_name: Symbol, abi: ExternAbi, args: &[OpTy<'tcx>], @@ -16,41 +16,41 @@ pub fn prctl<'tcx>( ) -> InterpResult<'tcx> { // We do not use `check_shim` here because `prctl` is variadic. The argument // count is checked bellow. - this.check_abi_and_shim_symbol_clash(abi, ExternAbi::C { unwind: false }, link_name)?; + ecx.check_abi_and_shim_symbol_clash(abi, ExternAbi::C { unwind: false }, link_name)?; // FIXME: Use constants once https://github.com/rust-lang/libc/pull/3941 backported to the 0.2 branch. let pr_set_name = 15; let pr_get_name = 16; let [op] = check_min_arg_count("prctl", args)?; - let res = match this.read_scalar(op)?.to_i32()? { + let res = match ecx.read_scalar(op)?.to_i32()? { op if op == pr_set_name => { let [_, name] = check_min_arg_count("prctl(PR_SET_NAME, ...)", args)?; - let name = this.read_scalar(name)?; - let thread = this.pthread_self()?; + let name = ecx.read_scalar(name)?; + let thread = ecx.pthread_self()?; // The Linux kernel silently truncates long names. // https://www.man7.org/linux/man-pages/man2/PR_SET_NAME.2const.html let res = - this.pthread_setname_np(thread, name, TASK_COMM_LEN, /* truncate */ true)?; + ecx.pthread_setname_np(thread, name, TASK_COMM_LEN, /* truncate */ true)?; assert_eq!(res, ThreadNameResult::Ok); Scalar::from_u32(0) } op if op == pr_get_name => { let [_, name] = check_min_arg_count("prctl(PR_GET_NAME, ...)", args)?; - let name = this.read_scalar(name)?; - let thread = this.pthread_self()?; - let len = Scalar::from_target_usize(TASK_COMM_LEN as u64, this); - this.check_ptr_access( - name.to_pointer(this)?, + let name = ecx.read_scalar(name)?; + let thread = ecx.pthread_self()?; + let len = Scalar::from_target_usize(TASK_COMM_LEN as u64, ecx); + ecx.check_ptr_access( + name.to_pointer(ecx)?, Size::from_bytes(TASK_COMM_LEN), CheckInAllocMsg::MemoryAccessTest, )?; - let res = this.pthread_getname_np(thread, name, len, /* truncate*/ false)?; + let res = ecx.pthread_getname_np(thread, name, len, /* truncate*/ false)?; assert_eq!(res, ThreadNameResult::Ok); Scalar::from_u32(0) } op => throw_unsup_format!("Miri does not support `prctl` syscall with op={}", op), }; - this.write_scalar(res, dest)?; + ecx.write_scalar(res, dest)?; interp_ok(()) } diff --git a/src/tools/miri/src/shims/unix/linux/sync.rs b/src/tools/miri/src/shims/unix/linux/sync.rs index 01b011d3504..51124fb2a00 100644 --- a/src/tools/miri/src/shims/unix/linux/sync.rs +++ b/src/tools/miri/src/shims/unix/linux/sync.rs @@ -9,7 +9,7 @@ struct LinuxFutex { /// Implementation of the SYS_futex syscall. /// `args` is the arguments *including* the syscall number. pub fn futex<'tcx>( - this: &mut MiriInterpCx<'tcx>, + ecx: &mut MiriInterpCx<'tcx>, args: &[OpTy<'tcx>], dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx> { @@ -26,19 +26,19 @@ pub fn futex<'tcx>( // The first three arguments (after the syscall number itself) are the same to all futex operations: // (int *addr, int op, int val). // We checked above that these definitely exist. - let addr = this.read_pointer(addr)?; - let op = this.read_scalar(op)?.to_i32()?; - let val = this.read_scalar(val)?.to_i32()?; + let addr = ecx.read_pointer(addr)?; + let op = ecx.read_scalar(op)?.to_i32()?; + let val = ecx.read_scalar(val)?.to_i32()?; // This is a vararg function so we have to bring our own type for this pointer. - let addr = this.ptr_to_mplace(addr, this.machine.layouts.i32); + let addr = ecx.ptr_to_mplace(addr, ecx.machine.layouts.i32); - let futex_private = this.eval_libc_i32("FUTEX_PRIVATE_FLAG"); - let futex_wait = this.eval_libc_i32("FUTEX_WAIT"); - let futex_wait_bitset = this.eval_libc_i32("FUTEX_WAIT_BITSET"); - let futex_wake = this.eval_libc_i32("FUTEX_WAKE"); - let futex_wake_bitset = this.eval_libc_i32("FUTEX_WAKE_BITSET"); - let futex_realtime = this.eval_libc_i32("FUTEX_CLOCK_REALTIME"); + let futex_private = ecx.eval_libc_i32("FUTEX_PRIVATE_FLAG"); + let futex_wait = ecx.eval_libc_i32("FUTEX_WAIT"); + let futex_wait_bitset = ecx.eval_libc_i32("FUTEX_WAIT_BITSET"); + let futex_wake = ecx.eval_libc_i32("FUTEX_WAKE"); + let futex_wake_bitset = ecx.eval_libc_i32("FUTEX_WAKE_BITSET"); + let futex_realtime = ecx.eval_libc_i32("FUTEX_CLOCK_REALTIME"); // FUTEX_PRIVATE enables an optimization that stops it from working across processes. // Miri doesn't support that anyway, so we ignore that flag. @@ -57,9 +57,9 @@ pub fn futex<'tcx>( let (timeout, bitset) = if wait_bitset { let [_, _, _, _, timeout, uaddr2, bitset] = check_min_arg_count("`syscall(SYS_futex, FUTEX_WAIT_BITSET, ...)`", args)?; - let _timeout = this.read_pointer(timeout)?; - let _uaddr2 = this.read_pointer(uaddr2)?; - (timeout, this.read_scalar(bitset)?.to_u32()?) + let _timeout = ecx.read_pointer(timeout)?; + let _uaddr2 = ecx.read_pointer(uaddr2)?; + (timeout, ecx.read_scalar(bitset)?.to_u32()?) } else { let [_, _, _, _, timeout] = check_min_arg_count("`syscall(SYS_futex, FUTEX_WAIT, ...)`", args)?; @@ -67,21 +67,21 @@ pub fn futex<'tcx>( }; if bitset == 0 { - return this.set_last_error_and_return(LibcError("EINVAL"), dest); + return ecx.set_last_error_and_return(LibcError("EINVAL"), dest); } - let timeout = this.deref_pointer_as(timeout, this.libc_ty_layout("timespec"))?; - let timeout = if this.ptr_is_null(timeout.ptr())? { + let timeout = ecx.deref_pointer_as(timeout, ecx.libc_ty_layout("timespec"))?; + let timeout = if ecx.ptr_is_null(timeout.ptr())? { None } else { - let duration = match this.read_timespec(&timeout)? { + let duration = match ecx.read_timespec(&timeout)? { Some(duration) => duration, None => { - return this.set_last_error_and_return(LibcError("EINVAL"), dest); + return ecx.set_last_error_and_return(LibcError("EINVAL"), dest); } }; let timeout_clock = if op & futex_realtime == futex_realtime { - this.check_no_isolation( + ecx.check_no_isolation( "`futex` syscall with `op=FUTEX_WAIT` and non-null timeout with `FUTEX_CLOCK_REALTIME`", )?; TimeoutClock::RealTime @@ -139,36 +139,36 @@ pub fn futex<'tcx>( // // Thankfully, preemptions cannot happen inside a Miri shim, so we do not need to // do anything special to guarantee fence-load-comparison atomicity. - this.atomic_fence(AtomicFenceOrd::SeqCst)?; + ecx.atomic_fence(AtomicFenceOrd::SeqCst)?; // Read an `i32` through the pointer, regardless of any wrapper types. // It's not uncommon for `addr` to be passed as another type than `*mut i32`, such as `*const AtomicI32`. // We do an acquire read -- it only seems reasonable that if we observe a value here, we // actually establish an ordering with that value. - let futex_val = this.read_scalar_atomic(&addr, AtomicReadOrd::Acquire)?.to_i32()?; + let futex_val = ecx.read_scalar_atomic(&addr, AtomicReadOrd::Acquire)?.to_i32()?; if val == futex_val { // The value still matches, so we block the thread and make it wait for FUTEX_WAKE. // This cannot fail since we already did an atomic acquire read on that pointer. // Acquire reads are only allowed on mutable memory. - let futex_ref = this + let futex_ref = ecx .get_sync_or_init(addr.ptr(), |_| LinuxFutex { futex: Default::default() }) .unwrap() .futex .clone(); - this.futex_wait( + ecx.futex_wait( futex_ref, bitset, timeout, - Scalar::from_target_isize(0, this), // retval_succ - Scalar::from_target_isize(-1, this), // retval_timeout + Scalar::from_target_isize(0, ecx), // retval_succ + Scalar::from_target_isize(-1, ecx), // retval_timeout dest.clone(), LibcError("ETIMEDOUT"), // errno_timeout ); } else { // The futex value doesn't match the expected value, so we return failure // right away without sleeping: -1 and errno set to EAGAIN. - return this.set_last_error_and_return(LibcError("EAGAIN"), dest); + return ecx.set_last_error_and_return(LibcError("EAGAIN"), dest); } } // FUTEX_WAKE: (int *addr, int op = FUTEX_WAKE, int val) @@ -179,42 +179,42 @@ pub fn futex<'tcx>( // Same as FUTEX_WAKE, but allows you to specify a bitset to select which threads to wake up. op if op == futex_wake || op == futex_wake_bitset => { let Some(futex_ref) = - this.get_sync_or_init(addr.ptr(), |_| LinuxFutex { futex: Default::default() }) + ecx.get_sync_or_init(addr.ptr(), |_| LinuxFutex { futex: Default::default() }) else { // No AllocId, or no live allocation at that AllocId. // Return an error code. (That seems nicer than silently doing something non-intuitive.) // This means that if an address gets reused by a new allocation, // we'll use an independent futex queue for this... that seems acceptable. - return this.set_last_error_and_return(LibcError("EFAULT"), dest); + return ecx.set_last_error_and_return(LibcError("EFAULT"), dest); }; let futex_ref = futex_ref.futex.clone(); let bitset = if op == futex_wake_bitset { let [_, _, _, _, timeout, uaddr2, bitset] = check_min_arg_count("`syscall(SYS_futex, FUTEX_WAKE_BITSET, ...)`", args)?; - let _timeout = this.read_pointer(timeout)?; - let _uaddr2 = this.read_pointer(uaddr2)?; - this.read_scalar(bitset)?.to_u32()? + let _timeout = ecx.read_pointer(timeout)?; + let _uaddr2 = ecx.read_pointer(uaddr2)?; + ecx.read_scalar(bitset)?.to_u32()? } else { u32::MAX }; if bitset == 0 { - return this.set_last_error_and_return(LibcError("EINVAL"), dest); + return ecx.set_last_error_and_return(LibcError("EINVAL"), dest); } // Together with the SeqCst fence in futex_wait, this makes sure that futex_wait // will see the latest value on addr which could be changed by our caller // before doing the syscall. - this.atomic_fence(AtomicFenceOrd::SeqCst)?; + ecx.atomic_fence(AtomicFenceOrd::SeqCst)?; let mut n = 0; #[expect(clippy::arithmetic_side_effects)] for _ in 0..val { - if this.futex_wake(&futex_ref, bitset)? { + if ecx.futex_wake(&futex_ref, bitset)? { n += 1; } else { break; } } - this.write_scalar(Scalar::from_target_isize(n, this), dest)?; + ecx.write_scalar(Scalar::from_target_isize(n, ecx), dest)?; } op => throw_unsup_format!("Miri does not support `futex` syscall with op={}", op), } diff --git a/src/tools/miri/src/shims/unix/linux/syscall.rs b/src/tools/miri/src/shims/unix/linux/syscall.rs index 0d7032adab4..9f6935f096b 100644 --- a/src/tools/miri/src/shims/unix/linux/syscall.rs +++ b/src/tools/miri/src/shims/unix/linux/syscall.rs @@ -7,7 +7,7 @@ use crate::shims::unix::linux::sync::futex; use crate::*; pub fn syscall<'tcx>( - this: &mut MiriInterpCx<'tcx>, + ecx: &mut MiriInterpCx<'tcx>, link_name: Symbol, abi: ExternAbi, args: &[OpTy<'tcx>], @@ -15,18 +15,18 @@ pub fn syscall<'tcx>( ) -> InterpResult<'tcx> { // We do not use `check_shim` here because `syscall` is variadic. The argument // count is checked bellow. - this.check_abi_and_shim_symbol_clash(abi, ExternAbi::C { unwind: false }, link_name)?; + ecx.check_abi_and_shim_symbol_clash(abi, ExternAbi::C { unwind: false }, link_name)?; // The syscall variadic function is legal to call with more arguments than needed, // extra arguments are simply ignored. The important check is that when we use an // argument, we have to also check all arguments *before* it to ensure that they // have the right type. - let sys_getrandom = this.eval_libc("SYS_getrandom").to_target_usize(this)?; - let sys_futex = this.eval_libc("SYS_futex").to_target_usize(this)?; - let sys_eventfd2 = this.eval_libc("SYS_eventfd2").to_target_usize(this)?; + let sys_getrandom = ecx.eval_libc("SYS_getrandom").to_target_usize(ecx)?; + let sys_futex = ecx.eval_libc("SYS_futex").to_target_usize(ecx)?; + let sys_eventfd2 = ecx.eval_libc("SYS_eventfd2").to_target_usize(ecx)?; let [op] = check_min_arg_count("syscall", args)?; - match this.read_target_usize(op)? { + match ecx.read_target_usize(op)? { // `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)` // is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>). num if num == sys_getrandom => { @@ -34,25 +34,25 @@ pub fn syscall<'tcx>( // The first argument is the syscall id, so skip over it. let [_, ptr, len, flags] = check_min_arg_count("syscall(SYS_getrandom, ...)", args)?; - let ptr = this.read_pointer(ptr)?; - let len = this.read_target_usize(len)?; + let ptr = ecx.read_pointer(ptr)?; + let len = ecx.read_target_usize(len)?; // The only supported flags are GRND_RANDOM and GRND_NONBLOCK, // neither of which have any effect on our current PRNG. // See <https://github.com/rust-lang/rust/pull/79196> for a discussion of argument sizes. - let _flags = this.read_scalar(flags)?.to_i32()?; + let _flags = ecx.read_scalar(flags)?.to_i32()?; - this.gen_random(ptr, len)?; - this.write_scalar(Scalar::from_target_usize(len, this), dest)?; + ecx.gen_random(ptr, len)?; + ecx.write_scalar(Scalar::from_target_usize(len, ecx), dest)?; } // `futex` is used by some synchronization primitives. num if num == sys_futex => { - futex(this, args, dest)?; + futex(ecx, args, dest)?; } num if num == sys_eventfd2 => { let [_, initval, flags] = check_min_arg_count("syscall(SYS_evetfd2, ...)", args)?; - let result = this.eventfd(initval, flags)?; - this.write_int(result.to_i32()?, dest)?; + let result = ecx.eventfd(initval, flags)?; + ecx.write_int(result.to_i32()?, dest)?; } num => { throw_unsup_format!("syscall: unsupported syscall number {num}"); diff --git a/src/tools/miri/src/shims/x86/aesni.rs b/src/tools/miri/src/shims/x86/aesni.rs index 33b1f27713c..4c6c1cefeb1 100644 --- a/src/tools/miri/src/shims/x86/aesni.rs +++ b/src/tools/miri/src/shims/x86/aesni.rs @@ -132,7 +132,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // Performs an AES round (given by `f`) on each 128-bit word of // `state` with the corresponding 128-bit key of `key`. fn aes_round<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, state: &OpTy<'tcx>, key: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, @@ -145,21 +145,20 @@ fn aes_round<'tcx>( assert_eq!(dest.layout.size.bytes() % 16, 0); let len = dest.layout.size.bytes() / 16; - let u128_array_layout = - this.layout_of(Ty::new_array(this.tcx.tcx, this.tcx.types.u128, len))?; + let u128_array_layout = ecx.layout_of(Ty::new_array(ecx.tcx.tcx, ecx.tcx.types.u128, len))?; - let state = state.transmute(u128_array_layout, this)?; - let key = key.transmute(u128_array_layout, this)?; - let dest = dest.transmute(u128_array_layout, this)?; + let state = state.transmute(u128_array_layout, ecx)?; + let key = key.transmute(u128_array_layout, ecx)?; + let dest = dest.transmute(u128_array_layout, ecx)?; for i in 0..len { - let state = this.read_scalar(&this.project_index(&state, i)?)?.to_u128()?; - let key = this.read_scalar(&this.project_index(&key, i)?)?.to_u128()?; - let dest = this.project_index(&dest, i)?; + let state = ecx.read_scalar(&ecx.project_index(&state, i)?)?.to_u128()?; + let key = ecx.read_scalar(&ecx.project_index(&key, i)?)?.to_u128()?; + let dest = ecx.project_index(&dest, i)?; let res = f(state, key); - this.write_scalar(Scalar::from_u128(res), &dest)?; + ecx.write_scalar(Scalar::from_u128(res), &dest)?; } interp_ok(()) diff --git a/src/tools/miri/src/shims/x86/gfni.rs b/src/tools/miri/src/shims/x86/gfni.rs index 7b92d422cc5..92010345f55 100644 --- a/src/tools/miri/src/shims/x86/gfni.rs +++ b/src/tools/miri/src/shims/x86/gfni.rs @@ -75,21 +75,21 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { /// If `inverse` is set, then the inverse transformation with respect to the reduction polynomial /// x^8 + x^4 + x^3 + x + 1 is performed instead. fn affine_transform<'tcx>( - this: &mut MiriInterpCx<'tcx>, + ecx: &mut MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, imm8: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, inverse: bool, ) -> InterpResult<'tcx, ()> { - let (left, left_len) = this.project_to_simd(left)?; - let (right, right_len) = this.project_to_simd(right)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (left, left_len) = ecx.project_to_simd(left)?; + let (right, right_len) = ecx.project_to_simd(right)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(dest_len, right_len); assert_eq!(dest_len, left_len); - let imm8 = this.read_scalar(imm8)?.to_u8()?; + let imm8 = ecx.read_scalar(imm8)?.to_u8()?; // Each 8x8 bit matrix gets multiplied with eight bit vectors. // Therefore, the iteration is done in chunks of eight. @@ -98,13 +98,13 @@ fn affine_transform<'tcx>( let mut matrix = [0u8; 8]; for j in 0..8 { matrix[usize::try_from(j).unwrap()] = - this.read_scalar(&this.project_index(&right, i.wrapping_add(j))?)?.to_u8()?; + ecx.read_scalar(&ecx.project_index(&right, i.wrapping_add(j))?)?.to_u8()?; } // Multiply the matrix with the vector and perform the addition. for j in 0..8 { let index = i.wrapping_add(j); - let left = this.read_scalar(&this.project_index(&left, index)?)?.to_u8()?; + let left = ecx.read_scalar(&ecx.project_index(&left, index)?)?.to_u8()?; let left = if inverse { TABLE[usize::from(left)] } else { left }; let mut res = 0; @@ -124,8 +124,8 @@ fn affine_transform<'tcx>( // Perform the addition. res ^= imm8; - let dest = this.project_index(&dest, index)?; - this.write_scalar(Scalar::from_u8(res), &dest)?; + let dest = ecx.project_index(&dest, index)?; + ecx.write_scalar(Scalar::from_u8(res), &dest)?; } } diff --git a/src/tools/miri/src/shims/x86/mod.rs b/src/tools/miri/src/shims/x86/mod.rs index 433e9e966f2..66c8f3b4c2b 100644 --- a/src/tools/miri/src/shims/x86/mod.rs +++ b/src/tools/miri/src/shims/x86/mod.rs @@ -226,7 +226,7 @@ impl FloatBinOp { /// Convert from the `imm` argument used to specify the comparison /// operation in intrinsics such as `llvm.x86.sse.cmp.ss`. fn cmp_from_imm<'tcx>( - this: &crate::MiriInterpCx<'tcx>, + ecx: &crate::MiriInterpCx<'tcx>, imm: i8, intrinsic: Symbol, ) -> InterpResult<'tcx, Self> { @@ -260,7 +260,7 @@ impl FloatBinOp { }; // When bit 3 is 1 (only possible in AVX), unord is toggled. if imm & 0b1000 != 0 { - this.expect_target_feature_for_intrinsic(intrinsic, "avx")?; + ecx.expect_target_feature_for_intrinsic(intrinsic, "avx")?; unord = !unord; } interp_ok(Self::Cmp { gt, lt, eq, unord }) @@ -327,28 +327,28 @@ fn bin_op_float<'tcx, F: rustc_apfloat::Float>( /// Performs `which` operation on the first component of `left` and `right` /// and copies the other components from `left`. The result is stored in `dest`. fn bin_op_simd_float_first<'tcx, F: rustc_apfloat::Float>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, which: FloatBinOp, left: &OpTy<'tcx>, right: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (left, left_len) = this.project_to_simd(left)?; - let (right, right_len) = this.project_to_simd(right)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (left, left_len) = ecx.project_to_simd(left)?; + let (right, right_len) = ecx.project_to_simd(right)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(dest_len, left_len); assert_eq!(dest_len, right_len); let res0 = bin_op_float::<F>( which, - &this.read_immediate(&this.project_index(&left, 0)?)?, - &this.read_immediate(&this.project_index(&right, 0)?)?, + &ecx.read_immediate(&ecx.project_index(&left, 0)?)?, + &ecx.read_immediate(&ecx.project_index(&right, 0)?)?, )?; - this.write_scalar(res0, &this.project_index(&dest, 0)?)?; + ecx.write_scalar(res0, &ecx.project_index(&dest, 0)?)?; for i in 1..dest_len { - this.copy_op(&this.project_index(&left, i)?, &this.project_index(&dest, i)?)?; + ecx.copy_op(&ecx.project_index(&left, i)?, &ecx.project_index(&dest, i)?)?; } interp_ok(()) @@ -357,26 +357,26 @@ fn bin_op_simd_float_first<'tcx, F: rustc_apfloat::Float>( /// Performs `which` operation on each component of `left` and /// `right`, storing the result is stored in `dest`. fn bin_op_simd_float_all<'tcx, F: rustc_apfloat::Float>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, which: FloatBinOp, left: &OpTy<'tcx>, right: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (left, left_len) = this.project_to_simd(left)?; - let (right, right_len) = this.project_to_simd(right)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (left, left_len) = ecx.project_to_simd(left)?; + let (right, right_len) = ecx.project_to_simd(right)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(dest_len, left_len); assert_eq!(dest_len, right_len); for i in 0..dest_len { - let left = this.read_immediate(&this.project_index(&left, i)?)?; - let right = this.read_immediate(&this.project_index(&right, i)?)?; - let dest = this.project_index(&dest, i)?; + let left = ecx.read_immediate(&ecx.project_index(&left, i)?)?; + let right = ecx.read_immediate(&ecx.project_index(&right, i)?)?; + let dest = ecx.project_index(&dest, i)?; let res = bin_op_float::<F>(which, &left, &right)?; - this.write_scalar(res, &dest)?; + ecx.write_scalar(res, &dest)?; } interp_ok(()) @@ -398,7 +398,7 @@ enum FloatUnaryOp { /// Performs `which` scalar operation on `op` and returns the result. fn unary_op_f32<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, which: FloatUnaryOp, op: &ImmTy<'tcx>, ) -> InterpResult<'tcx, Scalar> { @@ -408,7 +408,7 @@ fn unary_op_f32<'tcx>( let div = (Single::from_u128(1).value / op).value; // Apply a relative error with a magnitude on the order of 2^-12 to simulate the // inaccuracy of RCP. - let res = apply_random_float_error(this, div, -12); + let res = apply_random_float_error(ecx, div, -12); interp_ok(Scalar::from_f32(res)) } FloatUnaryOp::Rsqrt => { @@ -418,7 +418,7 @@ fn unary_op_f32<'tcx>( let rsqrt = (Single::from_u128(1).value / sqrt).value; // Apply a relative error with a magnitude on the order of 2^-12 to simulate the // inaccuracy of RSQRT. - let res = apply_random_float_error(this, rsqrt, -12); + let res = apply_random_float_error(ecx, rsqrt, -12); interp_ok(Scalar::from_f32(res)) } } @@ -427,11 +427,11 @@ fn unary_op_f32<'tcx>( /// Disturbes a floating-point result by a relative error on the order of (-2^scale, 2^scale). #[expect(clippy::arithmetic_side_effects)] // floating point arithmetic cannot panic fn apply_random_float_error<F: rustc_apfloat::Float>( - this: &mut crate::MiriInterpCx<'_>, + ecx: &mut crate::MiriInterpCx<'_>, val: F, err_scale: i32, ) -> F { - let rng = this.machine.rng.get_mut(); + let rng = ecx.machine.rng.get_mut(); // generates rand(0, 2^64) * 2^(scale - 64) = rand(0, 1) * 2^scale let err = F::from_u128(rng.gen::<u64>().into()).value.scalbn(err_scale.strict_sub(64)); // give it a random sign @@ -443,21 +443,21 @@ fn apply_random_float_error<F: rustc_apfloat::Float>( /// Performs `which` operation on the first component of `op` and copies /// the other components. The result is stored in `dest`. fn unary_op_ss<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, which: FloatUnaryOp, op: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (op, op_len) = this.project_to_simd(op)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (op, op_len) = ecx.project_to_simd(op)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(dest_len, op_len); - let res0 = unary_op_f32(this, which, &this.read_immediate(&this.project_index(&op, 0)?)?)?; - this.write_scalar(res0, &this.project_index(&dest, 0)?)?; + let res0 = unary_op_f32(ecx, which, &ecx.read_immediate(&ecx.project_index(&op, 0)?)?)?; + ecx.write_scalar(res0, &ecx.project_index(&dest, 0)?)?; for i in 1..dest_len { - this.copy_op(&this.project_index(&op, i)?, &this.project_index(&dest, i)?)?; + ecx.copy_op(&ecx.project_index(&op, i)?, &ecx.project_index(&dest, i)?)?; } interp_ok(()) @@ -466,22 +466,22 @@ fn unary_op_ss<'tcx>( /// Performs `which` operation on each component of `op`, storing the /// result is stored in `dest`. fn unary_op_ps<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, which: FloatUnaryOp, op: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (op, op_len) = this.project_to_simd(op)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (op, op_len) = ecx.project_to_simd(op)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(dest_len, op_len); for i in 0..dest_len { - let op = this.read_immediate(&this.project_index(&op, i)?)?; - let dest = this.project_index(&dest, i)?; + let op = ecx.read_immediate(&ecx.project_index(&op, i)?)?; + let dest = ecx.project_index(&dest, i)?; - let res = unary_op_f32(this, which, &op)?; - this.write_scalar(res, &dest)?; + let res = unary_op_f32(ecx, which, &op)?; + ecx.write_scalar(res, &dest)?; } interp_ok(()) @@ -503,14 +503,14 @@ enum ShiftOp { /// For arithmetic right-shifts, when right is larger than BITS - 1, the sign /// bit is copied to all bits. fn shift_simd_by_scalar<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, which: ShiftOp, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (left, left_len) = this.project_to_simd(left)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (left, left_len) = ecx.project_to_simd(left)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(dest_len, left_len); // `right` may have a different length, and we only care about its @@ -520,11 +520,11 @@ fn shift_simd_by_scalar<'tcx>( // by checked_{shl,shr} (u32). // It is ok to saturate the value to u32::MAX because any value // above BITS - 1 will produce the same result. - let shift = u32::try_from(extract_first_u64(this, right)?).unwrap_or(u32::MAX); + let shift = u32::try_from(extract_first_u64(ecx, right)?).unwrap_or(u32::MAX); for i in 0..dest_len { - let left = this.read_scalar(&this.project_index(&left, i)?)?; - let dest = this.project_index(&dest, i)?; + let left = ecx.read_scalar(&ecx.project_index(&left, i)?)?; + let dest = ecx.project_index(&dest, i)?; let res = match which { ShiftOp::Left => { @@ -547,7 +547,7 @@ fn shift_simd_by_scalar<'tcx>( Scalar::from_int(res, dest.layout.size) } }; - this.write_scalar(res, &dest)?; + ecx.write_scalar(res, &dest)?; } interp_ok(()) @@ -559,23 +559,23 @@ fn shift_simd_by_scalar<'tcx>( /// For arithmetic right-shifts, when right is larger than BITS - 1, the sign /// bit is copied to all bits. fn shift_simd_by_simd<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, which: ShiftOp, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (left, left_len) = this.project_to_simd(left)?; - let (right, right_len) = this.project_to_simd(right)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (left, left_len) = ecx.project_to_simd(left)?; + let (right, right_len) = ecx.project_to_simd(right)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(dest_len, left_len); assert_eq!(dest_len, right_len); for i in 0..dest_len { - let left = this.read_scalar(&this.project_index(&left, i)?)?; - let right = this.read_scalar(&this.project_index(&right, i)?)?; - let dest = this.project_index(&dest, i)?; + let left = ecx.read_scalar(&ecx.project_index(&left, i)?)?; + let right = ecx.read_scalar(&ecx.project_index(&right, i)?)?; + let dest = ecx.project_index(&dest, i)?; // It is ok to saturate the value to u32::MAX because any value // above BITS - 1 will produce the same result. @@ -602,7 +602,7 @@ fn shift_simd_by_simd<'tcx>( Scalar::from_int(res, dest.layout.size) } }; - this.write_scalar(res, &dest)?; + ecx.write_scalar(res, &dest)?; } interp_ok(()) @@ -611,44 +611,44 @@ fn shift_simd_by_simd<'tcx>( /// Takes a 128-bit vector, transmutes it to `[u64; 2]` and extracts /// the first value. fn extract_first_u64<'tcx>( - this: &crate::MiriInterpCx<'tcx>, + ecx: &crate::MiriInterpCx<'tcx>, op: &OpTy<'tcx>, ) -> InterpResult<'tcx, u64> { // Transmute vector to `[u64; 2]` - let array_layout = this.layout_of(Ty::new_array(this.tcx.tcx, this.tcx.types.u64, 2))?; - let op = op.transmute(array_layout, this)?; + let array_layout = ecx.layout_of(Ty::new_array(ecx.tcx.tcx, ecx.tcx.types.u64, 2))?; + let op = op.transmute(array_layout, ecx)?; // Get the first u64 from the array - this.read_scalar(&this.project_index(&op, 0)?)?.to_u64() + ecx.read_scalar(&ecx.project_index(&op, 0)?)?.to_u64() } // Rounds the first element of `right` according to `rounding` // and copies the remaining elements from `left`. fn round_first<'tcx, F: rustc_apfloat::Float>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, rounding: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (left, left_len) = this.project_to_simd(left)?; - let (right, right_len) = this.project_to_simd(right)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (left, left_len) = ecx.project_to_simd(left)?; + let (right, right_len) = ecx.project_to_simd(right)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(dest_len, left_len); assert_eq!(dest_len, right_len); - let rounding = rounding_from_imm(this.read_scalar(rounding)?.to_i32()?)?; + let rounding = rounding_from_imm(ecx.read_scalar(rounding)?.to_i32()?)?; - let op0: F = this.read_scalar(&this.project_index(&right, 0)?)?.to_float()?; + let op0: F = ecx.read_scalar(&ecx.project_index(&right, 0)?)?.to_float()?; let res = op0.round_to_integral(rounding).value; - this.write_scalar( + ecx.write_scalar( Scalar::from_uint(res.to_bits(), Size::from_bits(F::BITS)), - &this.project_index(&dest, 0)?, + &ecx.project_index(&dest, 0)?, )?; for i in 1..dest_len { - this.copy_op(&this.project_index(&left, i)?, &this.project_index(&dest, i)?)?; + ecx.copy_op(&ecx.project_index(&left, i)?, &ecx.project_index(&dest, i)?)?; } interp_ok(()) @@ -656,24 +656,24 @@ fn round_first<'tcx, F: rustc_apfloat::Float>( // Rounds all elements of `op` according to `rounding`. fn round_all<'tcx, F: rustc_apfloat::Float>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, op: &OpTy<'tcx>, rounding: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (op, op_len) = this.project_to_simd(op)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (op, op_len) = ecx.project_to_simd(op)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(dest_len, op_len); - let rounding = rounding_from_imm(this.read_scalar(rounding)?.to_i32()?)?; + let rounding = rounding_from_imm(ecx.read_scalar(rounding)?.to_i32()?)?; for i in 0..dest_len { - let op: F = this.read_scalar(&this.project_index(&op, i)?)?.to_float()?; + let op: F = ecx.read_scalar(&ecx.project_index(&op, i)?)?.to_float()?; let res = op.round_to_integral(rounding).value; - this.write_scalar( + ecx.write_scalar( Scalar::from_uint(res.to_bits(), Size::from_bits(F::BITS)), - &this.project_index(&dest, i)?, + &ecx.project_index(&dest, i)?, )?; } @@ -708,31 +708,31 @@ fn rounding_from_imm<'tcx>(rounding: i32) -> InterpResult<'tcx, rustc_apfloat::R /// If `op` has more elements than `dest`, extra elements are ignored. If `op` /// has less elements than `dest`, the rest is filled with zeros. fn convert_float_to_int<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, op: &OpTy<'tcx>, rnd: rustc_apfloat::Round, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (op, op_len) = this.project_to_simd(op)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (op, op_len) = ecx.project_to_simd(op)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; // Output must be *signed* integers. - assert!(matches!(dest.layout.field(this, 0).ty.kind(), ty::Int(_))); + assert!(matches!(dest.layout.field(ecx, 0).ty.kind(), ty::Int(_))); for i in 0..op_len.min(dest_len) { - let op = this.read_immediate(&this.project_index(&op, i)?)?; - let dest = this.project_index(&dest, i)?; + let op = ecx.read_immediate(&ecx.project_index(&op, i)?)?; + let dest = ecx.project_index(&dest, i)?; - let res = this.float_to_int_checked(&op, dest.layout, rnd)?.unwrap_or_else(|| { + let res = ecx.float_to_int_checked(&op, dest.layout, rnd)?.unwrap_or_else(|| { // Fallback to minimum according to SSE/AVX semantics. ImmTy::from_int(dest.layout.size.signed_int_min(), dest.layout) }); - this.write_immediate(*res, &dest)?; + ecx.write_immediate(*res, &dest)?; } // Fill remainder with zeros for i in op_len..dest_len { - let dest = this.project_index(&dest, i)?; - this.write_scalar(Scalar::from_int(0, dest.layout.size), &dest)?; + let dest = ecx.project_index(&dest, i)?; + ecx.write_scalar(Scalar::from_int(0, dest.layout.size), &dest)?; } interp_ok(()) @@ -743,26 +743,26 @@ fn convert_float_to_int<'tcx>( /// In case of overflow (when the operand is the minimum value), the operation /// will wrap around. fn int_abs<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, op: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (op, op_len) = this.project_to_simd(op)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (op, op_len) = ecx.project_to_simd(op)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(op_len, dest_len); - let zero = ImmTy::from_int(0, op.layout.field(this, 0)); + let zero = ImmTy::from_int(0, op.layout.field(ecx, 0)); for i in 0..dest_len { - let op = this.read_immediate(&this.project_index(&op, i)?)?; - let dest = this.project_index(&dest, i)?; + let op = ecx.read_immediate(&ecx.project_index(&op, i)?)?; + let dest = ecx.project_index(&dest, i)?; - let lt_zero = this.binary_op(mir::BinOp::Lt, &op, &zero)?; + let lt_zero = ecx.binary_op(mir::BinOp::Lt, &op, &zero)?; let res = - if lt_zero.to_scalar().to_bool()? { this.unary_op(mir::UnOp::Neg, &op)? } else { op }; + if lt_zero.to_scalar().to_bool()? { ecx.unary_op(mir::UnOp::Neg, &op)? } else { op }; - this.write_immediate(*res, &dest)?; + ecx.write_immediate(*res, &dest)?; } interp_ok(()) @@ -776,25 +776,25 @@ fn int_abs<'tcx>( /// * The third element is the `op` vector split into chunks, i.e, it's /// type is `[[T; M]; N]` where `T` is the element type of `op`. fn split_simd_to_128bit_chunks<'tcx, P: Projectable<'tcx, Provenance>>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, op: &P, ) -> InterpResult<'tcx, (u64, u64, P)> { let simd_layout = op.layout(); - let (simd_len, element_ty) = simd_layout.ty.simd_size_and_type(this.tcx.tcx); + let (simd_len, element_ty) = simd_layout.ty.simd_size_and_type(ecx.tcx.tcx); assert_eq!(simd_layout.size.bits() % 128, 0); let num_chunks = simd_layout.size.bits() / 128; let items_per_chunk = simd_len.strict_div(num_chunks); // Transmute to `[[T; items_per_chunk]; num_chunks]` - let chunked_layout = this + let chunked_layout = ecx .layout_of(Ty::new_array( - this.tcx.tcx, - Ty::new_array(this.tcx.tcx, element_ty, items_per_chunk), + ecx.tcx.tcx, + Ty::new_array(ecx.tcx.tcx, element_ty, items_per_chunk), num_chunks, )) .unwrap(); - let chunked_op = op.transmute(chunked_layout, this)?; + let chunked_op = op.transmute(chunked_layout, ecx)?; interp_ok((num_chunks, items_per_chunk, chunked_op)) } @@ -809,7 +809,7 @@ fn split_simd_to_128bit_chunks<'tcx, P: Projectable<'tcx, Provenance>>( /// the is i-th 128-bit chunk of `dest` is calculated with the i-th /// 128-bit chunks of `left` and `right`). fn horizontal_bin_op<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, which: mir::BinOp, saturating: bool, left: &OpTy<'tcx>, @@ -819,15 +819,15 @@ fn horizontal_bin_op<'tcx>( assert_eq!(left.layout, dest.layout); assert_eq!(right.layout, dest.layout); - let (num_chunks, items_per_chunk, left) = split_simd_to_128bit_chunks(this, left)?; - let (_, _, right) = split_simd_to_128bit_chunks(this, right)?; - let (_, _, dest) = split_simd_to_128bit_chunks(this, dest)?; + let (num_chunks, items_per_chunk, left) = split_simd_to_128bit_chunks(ecx, left)?; + let (_, _, right) = split_simd_to_128bit_chunks(ecx, right)?; + let (_, _, dest) = split_simd_to_128bit_chunks(ecx, dest)?; let middle = items_per_chunk / 2; for i in 0..num_chunks { - let left = this.project_index(&left, i)?; - let right = this.project_index(&right, i)?; - let dest = this.project_index(&dest, i)?; + let left = ecx.project_index(&left, i)?; + let right = ecx.project_index(&right, i)?; + let dest = ecx.project_index(&dest, i)?; for j in 0..items_per_chunk { // `j` is the index in `dest` @@ -835,16 +835,16 @@ fn horizontal_bin_op<'tcx>( let (k, src) = if j < middle { (j, &left) } else { (j.strict_sub(middle), &right) }; // `base_i` is the index of the first item of the 2-item chunk in `src` let base_i = k.strict_mul(2); - let lhs = this.read_immediate(&this.project_index(src, base_i)?)?; - let rhs = this.read_immediate(&this.project_index(src, base_i.strict_add(1))?)?; + let lhs = ecx.read_immediate(&ecx.project_index(src, base_i)?)?; + let rhs = ecx.read_immediate(&ecx.project_index(src, base_i.strict_add(1))?)?; let res = if saturating { - Immediate::from(this.saturating_arith(which, &lhs, &rhs)?) + Immediate::from(ecx.saturating_arith(which, &lhs, &rhs)?) } else { - *this.binary_op(which, &lhs, &rhs)? + *ecx.binary_op(which, &lhs, &rhs)? }; - this.write_immediate(res, &this.project_index(&dest, j)?)?; + ecx.write_immediate(res, &ecx.project_index(&dest, j)?)?; } } @@ -860,7 +860,7 @@ fn horizontal_bin_op<'tcx>( /// the is i-th 128-bit chunk of `dest` is calculated with the i-th /// 128-bit blocks of `left` and `right`). fn conditional_dot_product<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, imm: &OpTy<'tcx>, @@ -869,20 +869,20 @@ fn conditional_dot_product<'tcx>( assert_eq!(left.layout, dest.layout); assert_eq!(right.layout, dest.layout); - let (num_chunks, items_per_chunk, left) = split_simd_to_128bit_chunks(this, left)?; - let (_, _, right) = split_simd_to_128bit_chunks(this, right)?; - let (_, _, dest) = split_simd_to_128bit_chunks(this, dest)?; + let (num_chunks, items_per_chunk, left) = split_simd_to_128bit_chunks(ecx, left)?; + let (_, _, right) = split_simd_to_128bit_chunks(ecx, right)?; + let (_, _, dest) = split_simd_to_128bit_chunks(ecx, dest)?; - let element_layout = left.layout.field(this, 0).field(this, 0); + let element_layout = left.layout.field(ecx, 0).field(ecx, 0); assert!(items_per_chunk <= 4); // `imm` is a `u8` for SSE4.1 or an `i32` for AVX :/ - let imm = this.read_scalar(imm)?.to_uint(imm.layout.size)?; + let imm = ecx.read_scalar(imm)?.to_uint(imm.layout.size)?; for i in 0..num_chunks { - let left = this.project_index(&left, i)?; - let right = this.project_index(&right, i)?; - let dest = this.project_index(&dest, i)?; + let left = ecx.project_index(&left, i)?; + let right = ecx.project_index(&right, i)?; + let dest = ecx.project_index(&dest, i)?; // Calculate dot product // Elements are floating point numbers, but we can use `from_int` @@ -890,22 +890,22 @@ fn conditional_dot_product<'tcx>( let mut sum = ImmTy::from_int(0u8, element_layout); for j in 0..items_per_chunk { if imm & (1 << j.strict_add(4)) != 0 { - let left = this.read_immediate(&this.project_index(&left, j)?)?; - let right = this.read_immediate(&this.project_index(&right, j)?)?; + let left = ecx.read_immediate(&ecx.project_index(&left, j)?)?; + let right = ecx.read_immediate(&ecx.project_index(&right, j)?)?; - let mul = this.binary_op(mir::BinOp::Mul, &left, &right)?; - sum = this.binary_op(mir::BinOp::Add, &sum, &mul)?; + let mul = ecx.binary_op(mir::BinOp::Mul, &left, &right)?; + sum = ecx.binary_op(mir::BinOp::Add, &sum, &mul)?; } } // Write to destination (conditioned to imm) for j in 0..items_per_chunk { - let dest = this.project_index(&dest, j)?; + let dest = ecx.project_index(&dest, j)?; if imm & (1 << j) != 0 { - this.write_immediate(*sum, &dest)?; + ecx.write_immediate(*sum, &dest)?; } else { - this.write_scalar(Scalar::from_int(0u8, element_layout.size), &dest)?; + ecx.write_scalar(Scalar::from_int(0u8, element_layout.size), &dest)?; } } } @@ -918,25 +918,25 @@ fn conditional_dot_product<'tcx>( /// The first is true when all the bits of `op & mask` are zero. /// The second is true when `(op & mask) == mask` fn test_bits_masked<'tcx>( - this: &crate::MiriInterpCx<'tcx>, + ecx: &crate::MiriInterpCx<'tcx>, op: &OpTy<'tcx>, mask: &OpTy<'tcx>, ) -> InterpResult<'tcx, (bool, bool)> { assert_eq!(op.layout, mask.layout); - let (op, op_len) = this.project_to_simd(op)?; - let (mask, mask_len) = this.project_to_simd(mask)?; + let (op, op_len) = ecx.project_to_simd(op)?; + let (mask, mask_len) = ecx.project_to_simd(mask)?; assert_eq!(op_len, mask_len); let mut all_zero = true; let mut masked_set = true; for i in 0..op_len { - let op = this.project_index(&op, i)?; - let mask = this.project_index(&mask, i)?; + let op = ecx.project_index(&op, i)?; + let mask = ecx.project_index(&mask, i)?; - let op = this.read_scalar(&op)?.to_uint(op.layout.size)?; - let mask = this.read_scalar(&mask)?.to_uint(mask.layout.size)?; + let op = ecx.read_scalar(&op)?.to_uint(op.layout.size)?; + let mask = ecx.read_scalar(&mask)?.to_uint(mask.layout.size)?; all_zero &= (op & mask) == 0; masked_set &= (op & mask) == mask; } @@ -949,27 +949,27 @@ fn test_bits_masked<'tcx>( /// The first is true when the highest bit of each element of `op & mask` is zero. /// The second is true when the highest bit of each element of `!op & mask` is zero. fn test_high_bits_masked<'tcx>( - this: &crate::MiriInterpCx<'tcx>, + ecx: &crate::MiriInterpCx<'tcx>, op: &OpTy<'tcx>, mask: &OpTy<'tcx>, ) -> InterpResult<'tcx, (bool, bool)> { assert_eq!(op.layout, mask.layout); - let (op, op_len) = this.project_to_simd(op)?; - let (mask, mask_len) = this.project_to_simd(mask)?; + let (op, op_len) = ecx.project_to_simd(op)?; + let (mask, mask_len) = ecx.project_to_simd(mask)?; assert_eq!(op_len, mask_len); - let high_bit_offset = op.layout.field(this, 0).size.bits().strict_sub(1); + let high_bit_offset = op.layout.field(ecx, 0).size.bits().strict_sub(1); let mut direct = true; let mut negated = true; for i in 0..op_len { - let op = this.project_index(&op, i)?; - let mask = this.project_index(&mask, i)?; + let op = ecx.project_index(&op, i)?; + let mask = ecx.project_index(&mask, i)?; - let op = this.read_scalar(&op)?.to_uint(op.layout.size)?; - let mask = this.read_scalar(&mask)?.to_uint(mask.layout.size)?; + let op = ecx.read_scalar(&op)?.to_uint(op.layout.size)?; + let mask = ecx.read_scalar(&mask)?.to_uint(mask.layout.size)?; direct &= (op & mask) >> high_bit_offset == 0; negated &= (!op & mask) >> high_bit_offset == 0; } @@ -980,30 +980,30 @@ fn test_high_bits_masked<'tcx>( /// Conditionally loads from `ptr` according the high bit of each /// element of `mask`. `ptr` does not need to be aligned. fn mask_load<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, ptr: &OpTy<'tcx>, mask: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (mask, mask_len) = this.project_to_simd(mask)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (mask, mask_len) = ecx.project_to_simd(mask)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(dest_len, mask_len); - let mask_item_size = mask.layout.field(this, 0).size; + let mask_item_size = mask.layout.field(ecx, 0).size; let high_bit_offset = mask_item_size.bits().strict_sub(1); - let ptr = this.read_pointer(ptr)?; + let ptr = ecx.read_pointer(ptr)?; for i in 0..dest_len { - let mask = this.project_index(&mask, i)?; - let dest = this.project_index(&dest, i)?; + let mask = ecx.project_index(&mask, i)?; + let dest = ecx.project_index(&dest, i)?; - if this.read_scalar(&mask)?.to_uint(mask_item_size)? >> high_bit_offset != 0 { - let ptr = ptr.wrapping_offset(dest.layout.size * i, &this.tcx); + if ecx.read_scalar(&mask)?.to_uint(mask_item_size)? >> high_bit_offset != 0 { + let ptr = ptr.wrapping_offset(dest.layout.size * i, &ecx.tcx); // Unaligned copy, which is what we want. - this.mem_copy(ptr, dest.ptr(), dest.layout.size, /*nonoverlapping*/ true)?; + ecx.mem_copy(ptr, dest.ptr(), dest.layout.size, /*nonoverlapping*/ true)?; } else { - this.write_scalar(Scalar::from_int(0, dest.layout.size), &dest)?; + ecx.write_scalar(Scalar::from_int(0, dest.layout.size), &dest)?; } } @@ -1013,31 +1013,31 @@ fn mask_load<'tcx>( /// Conditionally stores into `ptr` according the high bit of each /// element of `mask`. `ptr` does not need to be aligned. fn mask_store<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, ptr: &OpTy<'tcx>, mask: &OpTy<'tcx>, value: &OpTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (mask, mask_len) = this.project_to_simd(mask)?; - let (value, value_len) = this.project_to_simd(value)?; + let (mask, mask_len) = ecx.project_to_simd(mask)?; + let (value, value_len) = ecx.project_to_simd(value)?; assert_eq!(value_len, mask_len); - let mask_item_size = mask.layout.field(this, 0).size; + let mask_item_size = mask.layout.field(ecx, 0).size; let high_bit_offset = mask_item_size.bits().strict_sub(1); - let ptr = this.read_pointer(ptr)?; + let ptr = ecx.read_pointer(ptr)?; for i in 0..value_len { - let mask = this.project_index(&mask, i)?; - let value = this.project_index(&value, i)?; + let mask = ecx.project_index(&mask, i)?; + let value = ecx.project_index(&value, i)?; - if this.read_scalar(&mask)?.to_uint(mask_item_size)? >> high_bit_offset != 0 { + if ecx.read_scalar(&mask)?.to_uint(mask_item_size)? >> high_bit_offset != 0 { // *Non-inbounds* pointer arithmetic to compute the destination. // (That's why we can't use a place projection.) - let ptr = ptr.wrapping_offset(value.layout.size * i, &this.tcx); + let ptr = ptr.wrapping_offset(value.layout.size * i, &ecx.tcx); // Deref the pointer *unaligned*, and do the copy. - let dest = this.ptr_to_mplace_unaligned(ptr, value.layout); - this.copy_op(&value, &dest)?; + let dest = ecx.ptr_to_mplace_unaligned(ptr, value.layout); + ecx.copy_op(&value, &dest)?; } } @@ -1056,7 +1056,7 @@ fn mask_store<'tcx>( /// the is i-th 128-bit chunk of `dest` is calculated with the i-th /// 128-bit chunks of `left` and `right`). fn mpsadbw<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, imm: &OpTy<'tcx>, @@ -1065,13 +1065,13 @@ fn mpsadbw<'tcx>( assert_eq!(left.layout, right.layout); assert_eq!(left.layout.size, dest.layout.size); - let (num_chunks, op_items_per_chunk, left) = split_simd_to_128bit_chunks(this, left)?; - let (_, _, right) = split_simd_to_128bit_chunks(this, right)?; - let (_, dest_items_per_chunk, dest) = split_simd_to_128bit_chunks(this, dest)?; + let (num_chunks, op_items_per_chunk, left) = split_simd_to_128bit_chunks(ecx, left)?; + let (_, _, right) = split_simd_to_128bit_chunks(ecx, right)?; + let (_, dest_items_per_chunk, dest) = split_simd_to_128bit_chunks(ecx, dest)?; assert_eq!(op_items_per_chunk, dest_items_per_chunk.strict_mul(2)); - let imm = this.read_scalar(imm)?.to_uint(imm.layout.size)?; + let imm = ecx.read_scalar(imm)?.to_uint(imm.layout.size)?; // Bit 2 of `imm` specifies the offset for indices of `left`. // The offset is 0 when the bit is 0 or 4 when the bit is 1. let left_offset = u64::try_from((imm >> 2) & 1).unwrap().strict_mul(4); @@ -1080,23 +1080,23 @@ fn mpsadbw<'tcx>( let right_offset = u64::try_from(imm & 0b11).unwrap().strict_mul(4); for i in 0..num_chunks { - let left = this.project_index(&left, i)?; - let right = this.project_index(&right, i)?; - let dest = this.project_index(&dest, i)?; + let left = ecx.project_index(&left, i)?; + let right = ecx.project_index(&right, i)?; + let dest = ecx.project_index(&dest, i)?; for j in 0..dest_items_per_chunk { let left_offset = left_offset.strict_add(j); let mut res: u16 = 0; for k in 0..4 { - let left = this - .read_scalar(&this.project_index(&left, left_offset.strict_add(k))?)? + let left = ecx + .read_scalar(&ecx.project_index(&left, left_offset.strict_add(k))?)? .to_u8()?; - let right = this - .read_scalar(&this.project_index(&right, right_offset.strict_add(k))?)? + let right = ecx + .read_scalar(&ecx.project_index(&right, right_offset.strict_add(k))?)? .to_u8()?; res = res.strict_add(left.abs_diff(right).into()); } - this.write_scalar(Scalar::from_u16(res), &this.project_index(&dest, j)?)?; + ecx.write_scalar(Scalar::from_u16(res), &ecx.project_index(&dest, j)?)?; } } @@ -1111,22 +1111,22 @@ fn mpsadbw<'tcx>( /// <https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhrs_epi16> /// <https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mulhrs_epi16> fn pmulhrsw<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (left, left_len) = this.project_to_simd(left)?; - let (right, right_len) = this.project_to_simd(right)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (left, left_len) = ecx.project_to_simd(left)?; + let (right, right_len) = ecx.project_to_simd(right)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(dest_len, left_len); assert_eq!(dest_len, right_len); for i in 0..dest_len { - let left = this.read_scalar(&this.project_index(&left, i)?)?.to_i16()?; - let right = this.read_scalar(&this.project_index(&right, i)?)?.to_i16()?; - let dest = this.project_index(&dest, i)?; + let left = ecx.read_scalar(&ecx.project_index(&left, i)?)?.to_i16()?; + let right = ecx.read_scalar(&ecx.project_index(&right, i)?)?.to_i16()?; + let dest = ecx.project_index(&dest, i)?; let res = (i32::from(left).strict_mul(right.into()) >> 14).strict_add(1) >> 1; @@ -1135,7 +1135,7 @@ fn pmulhrsw<'tcx>( #[expect(clippy::cast_possible_truncation)] let res = res as i16; - this.write_scalar(Scalar::from_i16(res), &dest)?; + ecx.write_scalar(Scalar::from_i16(res), &dest)?; } interp_ok(()) @@ -1152,7 +1152,7 @@ fn pmulhrsw<'tcx>( /// /// <https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_clmulepi64_si128> fn pclmulqdq<'tcx>( - this: &mut MiriInterpCx<'tcx>, + ecx: &mut MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, imm8: &OpTy<'tcx>, @@ -1166,14 +1166,14 @@ fn pclmulqdq<'tcx>( // Transmute the input into arrays of `[u64; len]`. // Transmute the output into an array of `[u128, len / 2]`. - let src_layout = this.layout_of(Ty::new_array(this.tcx.tcx, this.tcx.types.u64, len))?; - let dest_layout = this.layout_of(Ty::new_array(this.tcx.tcx, this.tcx.types.u128, len / 2))?; + let src_layout = ecx.layout_of(Ty::new_array(ecx.tcx.tcx, ecx.tcx.types.u64, len))?; + let dest_layout = ecx.layout_of(Ty::new_array(ecx.tcx.tcx, ecx.tcx.types.u128, len / 2))?; - let left = left.transmute(src_layout, this)?; - let right = right.transmute(src_layout, this)?; - let dest = dest.transmute(dest_layout, this)?; + let left = left.transmute(src_layout, ecx)?; + let right = right.transmute(src_layout, ecx)?; + let dest = dest.transmute(dest_layout, ecx)?; - let imm8 = this.read_scalar(imm8)?.to_u8()?; + let imm8 = ecx.read_scalar(imm8)?.to_u8()?; for i in 0..(len / 2) { let lo = i.strict_mul(2); @@ -1181,11 +1181,11 @@ fn pclmulqdq<'tcx>( // select the 64-bit integer from left that the user specified (low or high) let index = if (imm8 & 0x01) == 0 { lo } else { hi }; - let left = this.read_scalar(&this.project_index(&left, index)?)?.to_u64()?; + let left = ecx.read_scalar(&ecx.project_index(&left, index)?)?.to_u64()?; // select the 64-bit integer from right that the user specified (low or high) let index = if (imm8 & 0x10) == 0 { lo } else { hi }; - let right = this.read_scalar(&this.project_index(&right, index)?)?.to_u64()?; + let right = ecx.read_scalar(&ecx.project_index(&right, index)?)?.to_u64()?; // Perform carry-less multiplication. // @@ -1203,8 +1203,8 @@ fn pclmulqdq<'tcx>( } } - let dest = this.project_index(&dest, i)?; - this.write_scalar(Scalar::from_u128(result), &dest)?; + let dest = ecx.project_index(&dest, i)?; + ecx.write_scalar(Scalar::from_u128(result), &dest)?; } interp_ok(()) @@ -1218,7 +1218,7 @@ fn pclmulqdq<'tcx>( /// the is i-th 128-bit chunk of `dest` is calculated with the i-th /// 128-bit chunks of `left` and `right`). fn pack_generic<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, @@ -1227,28 +1227,28 @@ fn pack_generic<'tcx>( assert_eq!(left.layout, right.layout); assert_eq!(left.layout.size, dest.layout.size); - let (num_chunks, op_items_per_chunk, left) = split_simd_to_128bit_chunks(this, left)?; - let (_, _, right) = split_simd_to_128bit_chunks(this, right)?; - let (_, dest_items_per_chunk, dest) = split_simd_to_128bit_chunks(this, dest)?; + let (num_chunks, op_items_per_chunk, left) = split_simd_to_128bit_chunks(ecx, left)?; + let (_, _, right) = split_simd_to_128bit_chunks(ecx, right)?; + let (_, dest_items_per_chunk, dest) = split_simd_to_128bit_chunks(ecx, dest)?; assert_eq!(dest_items_per_chunk, op_items_per_chunk.strict_mul(2)); for i in 0..num_chunks { - let left = this.project_index(&left, i)?; - let right = this.project_index(&right, i)?; - let dest = this.project_index(&dest, i)?; + let left = ecx.project_index(&left, i)?; + let right = ecx.project_index(&right, i)?; + let dest = ecx.project_index(&dest, i)?; for j in 0..op_items_per_chunk { - let left = this.read_scalar(&this.project_index(&left, j)?)?; - let right = this.read_scalar(&this.project_index(&right, j)?)?; - let left_dest = this.project_index(&dest, j)?; - let right_dest = this.project_index(&dest, j.strict_add(op_items_per_chunk))?; + let left = ecx.read_scalar(&ecx.project_index(&left, j)?)?; + let right = ecx.read_scalar(&ecx.project_index(&right, j)?)?; + let left_dest = ecx.project_index(&dest, j)?; + let right_dest = ecx.project_index(&dest, j.strict_add(op_items_per_chunk))?; let left_res = f(left)?; let right_res = f(right)?; - this.write_scalar(left_res, &left_dest)?; - this.write_scalar(right_res, &right_dest)?; + ecx.write_scalar(left_res, &left_dest)?; + ecx.write_scalar(right_res, &right_dest)?; } } @@ -1262,12 +1262,12 @@ fn pack_generic<'tcx>( /// the is i-th 128-bit chunk of `dest` is calculated with the i-th /// 128-bit chunks of `left` and `right`). fn packsswb<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - pack_generic(this, left, right, dest, |op| { + pack_generic(ecx, left, right, dest, |op| { let op = op.to_i16()?; let res = i8::try_from(op).unwrap_or(if op < 0 { i8::MIN } else { i8::MAX }); interp_ok(Scalar::from_i8(res)) @@ -1281,12 +1281,12 @@ fn packsswb<'tcx>( /// the is i-th 128-bit chunk of `dest` is calculated with the i-th /// 128-bit chunks of `left` and `right`). fn packuswb<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - pack_generic(this, left, right, dest, |op| { + pack_generic(ecx, left, right, dest, |op| { let op = op.to_i16()?; let res = u8::try_from(op).unwrap_or(if op < 0 { 0 } else { u8::MAX }); interp_ok(Scalar::from_u8(res)) @@ -1300,12 +1300,12 @@ fn packuswb<'tcx>( /// the is i-th 128-bit chunk of `dest` is calculated with the i-th /// 128-bit chunks of `left` and `right`). fn packssdw<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - pack_generic(this, left, right, dest, |op| { + pack_generic(ecx, left, right, dest, |op| { let op = op.to_i32()?; let res = i16::try_from(op).unwrap_or(if op < 0 { i16::MIN } else { i16::MAX }); interp_ok(Scalar::from_i16(res)) @@ -1319,12 +1319,12 @@ fn packssdw<'tcx>( /// the is i-th 128-bit chunk of `dest` is calculated with the i-th /// 128-bit chunks of `left` and `right`). fn packusdw<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - pack_generic(this, left, right, dest, |op| { + pack_generic(ecx, left, right, dest, |op| { let op = op.to_i32()?; let res = u16::try_from(op).unwrap_or(if op < 0 { 0 } else { u16::MAX }); interp_ok(Scalar::from_u16(res)) @@ -1336,27 +1336,27 @@ fn packusdw<'tcx>( /// is written to the corresponding output element. /// In other words, multiplies `left` with `right.signum()`. fn psign<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, left: &OpTy<'tcx>, right: &OpTy<'tcx>, dest: &MPlaceTy<'tcx>, ) -> InterpResult<'tcx, ()> { - let (left, left_len) = this.project_to_simd(left)?; - let (right, right_len) = this.project_to_simd(right)?; - let (dest, dest_len) = this.project_to_simd(dest)?; + let (left, left_len) = ecx.project_to_simd(left)?; + let (right, right_len) = ecx.project_to_simd(right)?; + let (dest, dest_len) = ecx.project_to_simd(dest)?; assert_eq!(dest_len, left_len); assert_eq!(dest_len, right_len); for i in 0..dest_len { - let dest = this.project_index(&dest, i)?; - let left = this.read_immediate(&this.project_index(&left, i)?)?; - let right = this.read_scalar(&this.project_index(&right, i)?)?.to_int(dest.layout.size)?; + let dest = ecx.project_index(&dest, i)?; + let left = ecx.read_immediate(&ecx.project_index(&left, i)?)?; + let right = ecx.read_scalar(&ecx.project_index(&right, i)?)?.to_int(dest.layout.size)?; let res = - this.binary_op(mir::BinOp::Mul, &left, &ImmTy::from_int(right.signum(), dest.layout))?; + ecx.binary_op(mir::BinOp::Mul, &left, &ImmTy::from_int(right.signum(), dest.layout))?; - this.write_immediate(*res, &dest)?; + ecx.write_immediate(*res, &dest)?; } interp_ok(()) @@ -1366,7 +1366,7 @@ fn psign<'tcx>( /// of `op` and returns both the sum and the overflow bit. `op` is expected to be /// either one of `mir::BinOp::AddWithOverflow` and `mir::BinOp::SubWithOverflow`. fn carrying_add<'tcx>( - this: &mut crate::MiriInterpCx<'tcx>, + ecx: &mut crate::MiriInterpCx<'tcx>, cb_in: &OpTy<'tcx>, a: &OpTy<'tcx>, b: &OpTy<'tcx>, @@ -1374,13 +1374,13 @@ fn carrying_add<'tcx>( ) -> InterpResult<'tcx, (ImmTy<'tcx>, Scalar)> { assert!(op == mir::BinOp::AddWithOverflow || op == mir::BinOp::SubWithOverflow); - let cb_in = this.read_scalar(cb_in)?.to_u8()? != 0; - let a = this.read_immediate(a)?; - let b = this.read_immediate(b)?; + let cb_in = ecx.read_scalar(cb_in)?.to_u8()? != 0; + let a = ecx.read_immediate(a)?; + let b = ecx.read_immediate(b)?; - let (sum, overflow1) = this.binary_op(op, &a, &b)?.to_pair(this); + let (sum, overflow1) = ecx.binary_op(op, &a, &b)?.to_pair(ecx); let (sum, overflow2) = - this.binary_op(op, &sum, &ImmTy::from_uint(cb_in, a.layout))?.to_pair(this); + ecx.binary_op(op, &sum, &ImmTy::from_uint(cb_in, a.layout))?.to_pair(ecx); let cb_out = overflow1.to_scalar().to_bool()? | overflow2.to_scalar().to_bool()?; interp_ok((sum, Scalar::from_u8(cb_out.into()))) diff --git a/src/tools/miri/src/shims/x86/sha.rs b/src/tools/miri/src/shims/x86/sha.rs index 964204127d9..f18ff1ec253 100644 --- a/src/tools/miri/src/shims/x86/sha.rs +++ b/src/tools/miri/src/shims/x86/sha.rs @@ -23,27 +23,27 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // Prefix should have already been checked. let unprefixed_name = link_name.as_str().strip_prefix("llvm.x86.sha").unwrap(); - fn read<'c>(this: &mut MiriInterpCx<'c>, reg: &OpTy<'c>) -> InterpResult<'c, [u32; 4]> { + fn read<'c>(ecx: &mut MiriInterpCx<'c>, reg: &OpTy<'c>) -> InterpResult<'c, [u32; 4]> { let mut res = [0; 4]; // We reverse the order because x86 is little endian but the copied implementation uses // big endian. for (i, dst) in res.iter_mut().rev().enumerate() { - let projected = &this.project_index(reg, i.try_into().unwrap())?; - *dst = this.read_scalar(projected)?.to_u32()? + let projected = &ecx.project_index(reg, i.try_into().unwrap())?; + *dst = ecx.read_scalar(projected)?.to_u32()? } interp_ok(res) } fn write<'c>( - this: &mut MiriInterpCx<'c>, + ecx: &mut MiriInterpCx<'c>, dest: &MPlaceTy<'c>, val: [u32; 4], ) -> InterpResult<'c, ()> { // We reverse the order because x86 is little endian but the copied implementation uses // big endian. for (i, part) in val.into_iter().rev().enumerate() { - let projected = &this.project_index(dest, i.try_into().unwrap())?; - this.write_scalar(Scalar::from_u32(part), projected)?; + let projected = &ecx.project_index(dest, i.try_into().unwrap())?; + ecx.write_scalar(Scalar::from_u32(part), projected)?; } interp_ok(()) } diff --git a/src/tools/miri/src/shims/x86/sse42.rs b/src/tools/miri/src/shims/x86/sse42.rs index cc7cfab5041..0b058a9911e 100644 --- a/src/tools/miri/src/shims/x86/sse42.rs +++ b/src/tools/miri/src/shims/x86/sse42.rs @@ -70,7 +70,7 @@ const USE_SIGNED: u8 = 2; /// For more information, see the Intel Software Developer's Manual, Vol. 2b, Chapter 4.1. #[expect(clippy::arithmetic_side_effects)] fn compare_strings<'tcx>( - this: &mut MiriInterpCx<'tcx>, + ecx: &mut MiriInterpCx<'tcx>, str1: &OpTy<'tcx>, str2: &OpTy<'tcx>, len: Option<(u64, u64)>, @@ -80,8 +80,8 @@ fn compare_strings<'tcx>( let (len1, len2) = if let Some(t) = len { t } else { - let len1 = implicit_len(this, str1, imm)?.unwrap_or(default_len); - let len2 = implicit_len(this, str2, imm)?.unwrap_or(default_len); + let len1 = implicit_len(ecx, str1, imm)?.unwrap_or(default_len); + let len2 = implicit_len(ecx, str2, imm)?.unwrap_or(default_len); (len1, len2) }; @@ -90,12 +90,12 @@ fn compare_strings<'tcx>( 0 => { // Equal any: Checks which characters of `str2` are inside `str1`. for i in 0..len2 { - let ch2 = this.read_immediate(&this.project_index(str2, i)?)?; + let ch2 = ecx.read_immediate(&ecx.project_index(str2, i)?)?; for j in 0..len1 { - let ch1 = this.read_immediate(&this.project_index(str1, j)?)?; + let ch1 = ecx.read_immediate(&ecx.project_index(str1, j)?)?; - let eq = this.binary_op(mir::BinOp::Eq, &ch1, &ch2)?; + let eq = ecx.binary_op(mir::BinOp::Eq, &ch1, &ch2)?; if eq.to_scalar().to_bool()? { result |= 1 << i; break; @@ -119,9 +119,9 @@ fn compare_strings<'tcx>( for i in 0..len2 { for j in (0..len1).step_by(2) { - let ch2 = get_ch(this.read_scalar(&this.project_index(str2, i)?)?)?; - let ch1_1 = get_ch(this.read_scalar(&this.project_index(str1, j)?)?)?; - let ch1_2 = get_ch(this.read_scalar(&this.project_index(str1, j + 1)?)?)?; + let ch2 = get_ch(ecx.read_scalar(&ecx.project_index(str2, i)?)?)?; + let ch1_1 = get_ch(ecx.read_scalar(&ecx.project_index(str1, j)?)?)?; + let ch1_2 = get_ch(ecx.read_scalar(&ecx.project_index(str1, j + 1)?)?)?; if ch1_1 <= ch2 && ch2 <= ch1_2 { result |= 1 << i; @@ -135,9 +135,9 @@ fn compare_strings<'tcx>( result ^= (1 << len1.max(len2)) - 1; for i in 0..len1.min(len2) { - let ch1 = this.read_immediate(&this.project_index(str1, i)?)?; - let ch2 = this.read_immediate(&this.project_index(str2, i)?)?; - let eq = this.binary_op(mir::BinOp::Eq, &ch1, &ch2)?; + let ch1 = ecx.read_immediate(&ecx.project_index(str1, i)?)?; + let ch2 = ecx.read_immediate(&ecx.project_index(str2, i)?)?; + let eq = ecx.binary_op(mir::BinOp::Eq, &ch1, &ch2)?; result |= i32::from(eq.to_scalar().to_bool()?) << i; } } @@ -159,9 +159,9 @@ fn compare_strings<'tcx>( if k >= default_len { break; } else { - let ch1 = this.read_immediate(&this.project_index(str1, j)?)?; - let ch2 = this.read_immediate(&this.project_index(str2, k)?)?; - let ne = this.binary_op(mir::BinOp::Ne, &ch1, &ch2)?; + let ch1 = ecx.read_immediate(&ecx.project_index(str1, j)?)?; + let ch2 = ecx.read_immediate(&ecx.project_index(str2, k)?)?; + let ne = ecx.binary_op(mir::BinOp::Ne, &ch1, &ch2)?; if ne.to_scalar().to_bool()? { result &= !(1 << i); @@ -198,16 +198,16 @@ fn compare_strings<'tcx>( /// corresponding to the x86 128-bit integer SIMD type. fn deconstruct_args<'tcx>( unprefixed_name: &str, - this: &mut MiriInterpCx<'tcx>, + ecx: &mut MiriInterpCx<'tcx>, link_name: Symbol, abi: ExternAbi, args: &[OpTy<'tcx>], ) -> InterpResult<'tcx, (OpTy<'tcx>, OpTy<'tcx>, Option<(u64, u64)>, u8)> { - let array_layout_fn = |this: &mut MiriInterpCx<'tcx>, imm: u8| { + let array_layout_fn = |ecx: &mut MiriInterpCx<'tcx>, imm: u8| { if imm & USE_WORDS != 0 { - this.layout_of(Ty::new_array(this.tcx.tcx, this.tcx.types.u16, 8)) + ecx.layout_of(Ty::new_array(ecx.tcx.tcx, ecx.tcx.types.u16, 8)) } else { - this.layout_of(Ty::new_array(this.tcx.tcx, this.tcx.types.u8, 16)) + ecx.layout_of(Ty::new_array(ecx.tcx.tcx, ecx.tcx.types.u8, 16)) } }; @@ -223,26 +223,26 @@ fn deconstruct_args<'tcx>( if is_explicit { let [str1, len1, str2, len2, imm] = - this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?; - let imm = this.read_scalar(imm)?.to_u8()?; + ecx.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?; + let imm = ecx.read_scalar(imm)?.to_u8()?; let default_len = default_len::<u32>(imm); - let len1 = u64::from(this.read_scalar(len1)?.to_u32()?.min(default_len)); - let len2 = u64::from(this.read_scalar(len2)?.to_u32()?.min(default_len)); + let len1 = u64::from(ecx.read_scalar(len1)?.to_u32()?.min(default_len)); + let len2 = u64::from(ecx.read_scalar(len2)?.to_u32()?.min(default_len)); - let array_layout = array_layout_fn(this, imm)?; - let str1 = str1.transmute(array_layout, this)?; - let str2 = str2.transmute(array_layout, this)?; + let array_layout = array_layout_fn(ecx, imm)?; + let str1 = str1.transmute(array_layout, ecx)?; + let str2 = str2.transmute(array_layout, ecx)?; interp_ok((str1, str2, Some((len1, len2)), imm)) } else { let [str1, str2, imm] = - this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?; - let imm = this.read_scalar(imm)?.to_u8()?; + ecx.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?; + let imm = ecx.read_scalar(imm)?.to_u8()?; - let array_layout = array_layout_fn(this, imm)?; - let str1 = str1.transmute(array_layout, this)?; - let str2 = str2.transmute(array_layout, this)?; + let array_layout = array_layout_fn(ecx, imm)?; + let str1 = str1.transmute(array_layout, ecx)?; + let str2 = str2.transmute(array_layout, ecx)?; interp_ok((str1, str2, None, imm)) } @@ -251,16 +251,16 @@ fn deconstruct_args<'tcx>( /// Calculate the c-style string length for a given string `str`. /// The string is either a length 16 array of bytes a length 8 array of two-byte words. fn implicit_len<'tcx>( - this: &mut MiriInterpCx<'tcx>, + ecx: &mut MiriInterpCx<'tcx>, str: &OpTy<'tcx>, imm: u8, ) -> InterpResult<'tcx, Option<u64>> { let mut result = None; - let zero = ImmTy::from_int(0, str.layout.field(this, 0)); + let zero = ImmTy::from_int(0, str.layout.field(ecx, 0)); for i in 0..default_len::<u64>(imm) { - let ch = this.read_immediate(&this.project_index(str, i)?)?; - let is_zero = this.binary_op(mir::BinOp::Eq, &ch, &zero)?; + let ch = ecx.read_immediate(&ecx.project_index(str, i)?)?; + let is_zero = ecx.binary_op(mir::BinOp::Eq, &ch, &zero)?; if is_zero.to_scalar().to_bool()? { result = Some(i); break; |
