Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions crates/core_arch/src/x86/bt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ macro_rules! bt {
/// Returns the bit in position `b` of the memory addressed by `p`.
///
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_bittest)
///
/// # Safety
///
/// `p` must be valid for reads. `b` is a signed bit index: when it
/// falls outside the pointed-to integer, the instruction accesses
/// the word at `p + (b / bits) * (bits / 8)`, and that address must
/// be valid for reads as well.
#[inline]
#[cfg_attr(test, assert_instr(bt))]
#[stable(feature = "simd_x86_bittest", since = "1.55.0")]
Expand All @@ -40,6 +47,13 @@ pub unsafe fn _bittest(p: *const i32, b: i32) -> u8 {
/// Returns the bit in position `b` of the memory addressed by `p`, then sets the bit to `1`.
///
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_bittestandset)
///
/// # Safety
///
/// `p` must be valid for reads and writes. `b` is a signed bit
/// index: when it falls outside the pointed-to integer, the
/// instruction accesses the word at `p + (b / bits) * (bits / 8)`,
/// and that address must be valid for read-modify-write as well.
#[inline]
#[cfg_attr(test, assert_instr(bts))]
#[stable(feature = "simd_x86_bittest", since = "1.55.0")]
Expand All @@ -59,6 +73,13 @@ pub unsafe fn _bittestandset(p: *mut i32, b: i32) -> u8 {
/// Returns the bit in position `b` of the memory addressed by `p`, then resets that bit to `0`.
///
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_bittestandreset)
///
/// # Safety
///
/// `p` must be valid for reads and writes. `b` is a signed bit
/// index: when it falls outside the pointed-to integer, the
/// instruction accesses the word at `p + (b / bits) * (bits / 8)`,
/// and that address must be valid for read-modify-write as well.
#[inline]
#[cfg_attr(test, assert_instr(btr))]
#[stable(feature = "simd_x86_bittest", since = "1.55.0")]
Expand All @@ -78,6 +99,13 @@ pub unsafe fn _bittestandreset(p: *mut i32, b: i32) -> u8 {
/// Returns the bit in position `b` of the memory addressed by `p`, then inverts that bit.
///
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_bittestandcomplement)
///
/// # Safety
///
/// `p` must be valid for reads and writes. `b` is a signed bit
/// index: when it falls outside the pointed-to integer, the
/// instruction accesses the word at `p + (b / bits) * (bits / 8)`,
/// and that address must be valid for read-modify-write as well.
#[inline]
#[cfg_attr(test, assert_instr(btc))]
#[stable(feature = "simd_x86_bittest", since = "1.55.0")]
Expand Down
16 changes: 16 additions & 0 deletions crates/core_arch/src/x86/fxsr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ unsafe extern "llvm-intrinsic" {
/// [fxrstor]: http://www.felixcloutier.com/x86/FXRSTOR.html
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_fxsave)
///
/// # Safety
///
/// `mem_addr` must be valid for writes of 512 bytes and must be
/// 16-byte aligned; misaligned stores raise a general-protection
/// (#GP) exception.
#[inline]
#[target_feature(enable = "fxsr")]
#[cfg_attr(test, assert_instr(fxsave))]
Expand All @@ -47,6 +53,16 @@ pub unsafe fn _fxsave(mem_addr: *mut u8) {
/// [fxrstor]: http://www.felixcloutier.com/x86/FXRSTOR.html
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_fxrstor)
///
/// # Safety
///
/// `mem_addr` must be valid for reads of 512 bytes and must be
/// 16-byte aligned.
///
/// The 512 bytes at `mem_addr` must form a valid `FXSAVE`-format
/// image, e.g. one written by a prior `_fxsave`/`_fxsave64`. In
/// particular the `MXCSR` portion must hold a value legal for
/// `FXRSTOR`, otherwise the instruction raises a #GP.
#[inline]
#[target_feature(enable = "fxsr")]
#[cfg_attr(test, assert_instr(fxrstor))]
Expand Down
58 changes: 58 additions & 0 deletions crates/core_arch/src/x86/xsave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ unsafe extern "llvm-intrinsic" {
/// Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xsave)
///
/// # Safety
///
/// `mem_addr` must be valid for writes of the whole `XSAVE` area
/// required by `save_mask` and `XCR0` (at least 512 bytes plus the
/// enabled extended region, see the referenced Intel SDM section)
/// and must be 64-byte aligned.
#[inline]
#[target_feature(enable = "xsave")]
#[cfg_attr(test, assert_instr(xsave))]
Expand All @@ -50,6 +57,15 @@ pub unsafe fn _xsave(mem_addr: *mut u8, save_mask: u64) {
/// boundary.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xrstor)
///
/// # Safety
///
/// `mem_addr` must be valid for reads of the whole `XSAVE` area it
/// describes and must be 64-byte aligned.
///
/// The memory must contain a valid `XSAVE` area produced by a prior
/// save (or otherwise matching the format in the referenced Intel
/// SDM section); restoring reserved or malformed state raises a #GP.
#[inline]
#[target_feature(enable = "xsave")]
#[cfg_attr(test, assert_instr(xrstor))]
Expand All @@ -70,6 +86,12 @@ pub const _XCR_XFEATURE_ENABLED_MASK: u32 = 0;
/// Currently only `XFEATURE_ENABLED_MASK` `XCR` is supported.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xsetbv)
///
/// # Safety
///
/// `a` must identify a supported extended control register
/// (currently only `XCR0`), and `val` must be a legal value for
/// that register (setting reserved bits raises a #GP).
#[inline]
#[target_feature(enable = "xsave")]
#[cfg_attr(test, assert_instr(xsetbv))]
Expand All @@ -82,6 +104,12 @@ pub unsafe fn _xsetbv(a: u32, val: u64) {
/// specified in `xcr_no`.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xgetbv)
///
/// # Safety
///
/// `xcr_no` must identify a supported extended control register
/// (currently only `XCR0`); reading an unsupported register raises
/// a #GP.
#[inline]
#[target_feature(enable = "xsave")]
#[cfg_attr(test, assert_instr(xgetbv))]
Expand All @@ -99,6 +127,13 @@ pub unsafe fn _xgetbv(xcr_no: u32) -> u64 {
/// be equal to or better than using the `XSAVE` instruction.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xsaveopt)
///
/// # Safety
///
/// `mem_addr` must be valid for writes of the whole `XSAVE` area
/// required by `save_mask` and `XCR0` (at least 512 bytes plus the
/// enabled extended region, see the referenced Intel SDM section)
/// and must be 64-byte aligned.
#[inline]
#[target_feature(enable = "xsave,xsaveopt")]
#[cfg_attr(test, assert_instr(xsaveopt))]
Expand All @@ -115,6 +150,13 @@ pub unsafe fn _xsaveopt(mem_addr: *mut u8, save_mask: u64) {
/// and `XCR0`. `mem_addr` must be aligned on a 64-byte boundary.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xsavec)
///
/// # Safety
///
/// `mem_addr` must be valid for writes of the whole `XSAVE` area
/// required by `save_mask` and `XCR0` (at least 512 bytes plus the
/// enabled extended region, see the referenced Intel SDM section)
/// and must be 64-byte aligned.
#[inline]
#[target_feature(enable = "xsave,xsavec")]
#[cfg_attr(test, assert_instr(xsavec))]
Expand All @@ -132,6 +174,13 @@ pub unsafe fn _xsavec(mem_addr: *mut u8, save_mask: u64) {
/// and `XCR0`. `mem_addr` must be aligned on a 64-byte boundary.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xsaves)
///
/// # Safety
///
/// `mem_addr` must be valid for writes of the whole `XSAVE` area
/// required by `save_mask` and `XCR0` (at least 512 bytes plus the
/// enabled extended region, see the referenced Intel SDM section)
/// and must be 64-byte aligned.
#[inline]
#[target_feature(enable = "xsave,xsaves")]
#[cfg_attr(test, assert_instr(xsaves))]
Expand All @@ -151,6 +200,15 @@ pub unsafe fn _xsaves(mem_addr: *mut u8, save_mask: u64) {
/// boundary.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xrstors)
///
/// # Safety
///
/// `mem_addr` must be valid for reads of the whole `XSAVE` area it
/// describes and must be 64-byte aligned.
///
/// The memory must contain a valid `XSAVE` area produced by a prior
/// save (or otherwise matching the format in the referenced Intel
/// SDM section); restoring reserved or malformed state raises a #GP.
#[inline]
#[target_feature(enable = "xsave,xsaves")]
#[cfg_attr(test, assert_instr(xrstors))]
Expand Down
28 changes: 28 additions & 0 deletions crates/core_arch/src/x86_64/bt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ macro_rules! bt {
/// Returns the bit in position `b` of the memory addressed by `p`.
///
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_bittest64)
///
/// # Safety
///
/// `p` must be valid for reads. `b` is a signed bit index: when it
/// falls outside the pointed-to integer, the instruction accesses
/// the word at `p + (b / bits) * (bits / 8)`, and that address must
/// be valid for reads as well.
#[inline]
#[cfg_attr(test, assert_instr(bt))]
#[stable(feature = "simd_x86_bittest", since = "1.55.0")]
Expand All @@ -40,6 +47,13 @@ pub unsafe fn _bittest64(p: *const i64, b: i64) -> u8 {
/// Returns the bit in position `b` of the memory addressed by `p`, then sets the bit to `1`.
///
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_bittestandset64)
///
/// # Safety
///
/// `p` must be valid for reads and writes. `b` is a signed bit
/// index: when it falls outside the pointed-to integer, the
/// instruction accesses the word at `p + (b / bits) * (bits / 8)`,
/// and that address must be valid for read-modify-write as well.
#[inline]
#[cfg_attr(test, assert_instr(bts))]
#[stable(feature = "simd_x86_bittest", since = "1.55.0")]
Expand All @@ -59,6 +73,13 @@ pub unsafe fn _bittestandset64(p: *mut i64, b: i64) -> u8 {
/// Returns the bit in position `b` of the memory addressed by `p`, then resets that bit to `0`.
///
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_bittestandreset64)
///
/// # Safety
///
/// `p` must be valid for reads and writes. `b` is a signed bit
/// index: when it falls outside the pointed-to integer, the
/// instruction accesses the word at `p + (b / bits) * (bits / 8)`,
/// and that address must be valid for read-modify-write as well.
#[inline]
#[cfg_attr(test, assert_instr(btr))]
#[stable(feature = "simd_x86_bittest", since = "1.55.0")]
Expand All @@ -78,6 +99,13 @@ pub unsafe fn _bittestandreset64(p: *mut i64, b: i64) -> u8 {
/// Returns the bit in position `b` of the memory addressed by `p`, then inverts that bit.
///
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_bittestandcomplement64)
///
/// # Safety
///
/// `p` must be valid for reads and writes. `b` is a signed bit
/// index: when it falls outside the pointed-to integer, the
/// instruction accesses the word at `p + (b / bits) * (bits / 8)`,
/// and that address must be valid for read-modify-write as well.
#[inline]
#[cfg_attr(test, assert_instr(btc))]
#[stable(feature = "simd_x86_bittest", since = "1.55.0")]
Expand Down
16 changes: 16 additions & 0 deletions crates/core_arch/src/x86_64/fxsr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ unsafe extern "llvm-intrinsic" {
/// [fxrstor]: http://www.felixcloutier.com/x86/FXRSTOR.html
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_fxsave64)
///
/// # Safety
///
/// `mem_addr` must be valid for writes of 512 bytes and must be
/// 16-byte aligned; misaligned stores raise a general-protection
/// (#GP) exception.
#[inline]
#[target_feature(enable = "fxsr")]
#[cfg_attr(test, assert_instr(fxsave64))]
Expand All @@ -47,6 +53,16 @@ pub unsafe fn _fxsave64(mem_addr: *mut u8) {
/// [fxrstor]: http://www.felixcloutier.com/x86/FXRSTOR.html
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_fxrstor64)
///
/// # Safety
///
/// `mem_addr` must be valid for reads of 512 bytes and must be
/// 16-byte aligned.
///
/// The 512 bytes at `mem_addr` must form a valid `FXSAVE`-format
/// image, e.g. one written by a prior `_fxsave`/`_fxsave64`. In
/// particular the `MXCSR` portion must hold a value legal for
/// `FXRSTOR`, otherwise the instruction raises a #GP.
#[inline]
#[target_feature(enable = "fxsr")]
#[cfg_attr(test, assert_instr(fxrstor64))]
Expand Down
46 changes: 46 additions & 0 deletions crates/core_arch/src/x86_64/xsave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ unsafe extern "llvm-intrinsic" {
/// Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 1.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xsave64)
///
/// # Safety
///
/// `mem_addr` must be valid for writes of the whole `XSAVE` area
/// required by `save_mask` and `XCR0` (at least 512 bytes plus the
/// enabled extended region, see the referenced Intel SDM section)
/// and must be 64-byte aligned.
#[inline]
#[target_feature(enable = "xsave")]
#[cfg_attr(test, assert_instr(xsave64))]
Expand All @@ -47,6 +54,15 @@ pub unsafe fn _xsave64(mem_addr: *mut u8, save_mask: u64) {
/// boundary.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xrstor64)
///
/// # Safety
///
/// `mem_addr` must be valid for reads of the whole `XSAVE` area it
/// describes and must be 64-byte aligned.
///
/// The memory must contain a valid `XSAVE` area produced by a prior
/// save (or otherwise matching the format in the referenced Intel
/// SDM section); restoring reserved or malformed state raises a #GP.
#[inline]
#[target_feature(enable = "xsave")]
#[cfg_attr(test, assert_instr(xrstor64))]
Expand All @@ -64,6 +80,13 @@ pub unsafe fn _xrstor64(mem_addr: *const u8, rs_mask: u64) {
/// be equal to or better than using the `XSAVE64` instruction.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xsaveopt64)
///
/// # Safety
///
/// `mem_addr` must be valid for writes of the whole `XSAVE` area
/// required by `save_mask` and `XCR0` (at least 512 bytes plus the
/// enabled extended region, see the referenced Intel SDM section)
/// and must be 64-byte aligned.
#[inline]
#[target_feature(enable = "xsave,xsaveopt")]
#[cfg_attr(test, assert_instr(xsaveopt64))]
Expand All @@ -80,6 +103,13 @@ pub unsafe fn _xsaveopt64(mem_addr: *mut u8, save_mask: u64) {
/// and `XCR0`. `mem_addr` must be aligned on a 64-byte boundary.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xsavec64)
///
/// # Safety
///
/// `mem_addr` must be valid for writes of the whole `XSAVE` area
/// required by `save_mask` and `XCR0` (at least 512 bytes plus the
/// enabled extended region, see the referenced Intel SDM section)
/// and must be 64-byte aligned.
#[inline]
#[target_feature(enable = "xsave,xsavec")]
#[cfg_attr(test, assert_instr(xsavec64))]
Expand All @@ -97,6 +127,13 @@ pub unsafe fn _xsavec64(mem_addr: *mut u8, save_mask: u64) {
/// and `XCR0`. `mem_addr` must be aligned on a 64-byte boundary.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xsaves64)
///
/// # Safety
///
/// `mem_addr` must be valid for writes of the whole `XSAVE` area
/// required by `save_mask` and `XCR0` (at least 512 bytes plus the
/// enabled extended region, see the referenced Intel SDM section)
/// and must be 64-byte aligned.
#[inline]
#[target_feature(enable = "xsave,xsaves")]
#[cfg_attr(test, assert_instr(xsaves64))]
Expand All @@ -116,6 +153,15 @@ pub unsafe fn _xsaves64(mem_addr: *mut u8, save_mask: u64) {
/// boundary.
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_xrstors64)
///
/// # Safety
///
/// `mem_addr` must be valid for reads of the whole `XSAVE` area it
/// describes and must be 64-byte aligned.
///
/// The memory must contain a valid `XSAVE` area produced by a prior
/// save (or otherwise matching the format in the referenced Intel
/// SDM section); restoring reserved or malformed state raises a #GP.
#[inline]
#[target_feature(enable = "xsave,xsaves")]
#[cfg_attr(test, assert_instr(xrstors64))]
Expand Down
Loading