Skip to content

Commit

Permalink
Auto merge of rust-lang#3726 - TDecking:vzero, r=RalfJung
Browse files Browse the repository at this point in the history
Implement the `_mm256_zeroupper` and `_mm256_zeroall` intrinsics

These two intrinsics were missing from the original implementation of the AVX intrinsics.
Fortunately their implementation is trivial.
  • Loading branch information
bors committed Jul 3, 2024
2 parents ad1d8a8 + d982844 commit b0d791d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/tools/miri/src/shims/x86/avx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,17 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {

this.write_scalar(Scalar::from_i32(res.into()), dest)?;
}
// Used to implement the `_mm256_zeroupper` and `_mm256_zeroall` functions.
// These function clear out the upper 128 bits of all avx registers or
// zero out all avx registers respectively.
"vzeroupper" | "vzeroall" => {
// These functions are purely a performance hint for the CPU.
// Any registers currently in use will be saved beforehand by the
// compiler, making these functions no-ops.

// The only thing that needs to be ensured is the correct calling convention.
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
}
_ => return Ok(EmulateItemResult::NotSupported),
}
Ok(EmulateItemResult::NeedsReturn)
Expand Down
5 changes: 5 additions & 0 deletions src/tools/miri/tests/pass/shims/x86/intrinsics-x86-avx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,11 @@ unsafe fn test_avx() {
assert_eq!(r, 1);
}
test_mm_testnzc_ps();

// These intrinsics are functionally no-ops. The only thing
// that needs to be tested is that they can be executed.
_mm256_zeroupper();
_mm256_zeroall();
}

#[target_feature(enable = "sse2")]
Expand Down

0 comments on commit b0d791d

Please sign in to comment.