Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to resolve #852 #1377

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
43 changes: 42 additions & 1 deletion crates/core_arch/src/x86/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,20 @@ pub unsafe fn _mm_getcsr() -> u32 {
/// _MM_SET_ROUNDING_MODE(_MM_ROUND_DOWN)
/// ```
///
/// ## Denormals-are-zero/Flush-to-zero Mode
/// ## Denormals-are-Zero Mode
///
/// If this bit is set, denormal values used as input to floating-point instructions
/// wil be treated as zero.
///
/// You can read and enable/disable this mode via the helper functions
/// `_MM_GET_DENORMALS_ZERO_MODE()` and `_MM_SET_DENORMALS_ZERO_MODE()`.
///
/// ```rust,ignore
/// _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_OFF); // turn off (default)
/// _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); // turn on
/// ```
///
/// ## Flush-to-zero Mode
///
/// If this bit is set, values that would be denormalized will be set to zero
/// instead. This is turned off by default.
Expand Down Expand Up @@ -1584,6 +1597,25 @@ pub const _MM_FLUSH_ZERO_ON: u32 = 0x8000;
#[stable(feature = "simd_x86", since = "1.27.0")]
pub const _MM_FLUSH_ZERO_OFF: u32 = 0x0000;

/// See [`_MM_GET_DENORMALS_ZERO_MODE`](fn._MM_GET_DENORMALS_ZERO_MODE.html)
#[stable(feature = "simd_x86", since = "1.27.0")]
pub const _MM_DENORMALS_ZERO_MASK: u32 = 0x0040;
/// See [`_mm_setcsr`](fn._mm_setcsr.html)
#[stable(feature = "simd_x86", since = "1.27.0")]
pub const _MM_DENORMALS_ZERO_ON: u32 = 0x0040;
/// See [`_mm_setcsr`](fn._mm_setcsr.html)
#[stable(feature = "simd_x86", since = "1.27.0")]
pub const _MM_DENORMALS_ZERO_OFF: u32 = 0x0000;

/// See [`_mm_setcsr`](fn._mm_setcsr.html)
#[inline]
#[allow(non_snake_case)]
#[target_feature(enable = "sse")]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _MM_GET_DENORMALS_ZERO_MODE() -> u32 {
_mm_getcsr() & _MM_DENORMALS_ZERO_MASK
}

/// See [`_mm_setcsr`](fn._mm_setcsr.html)
///
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_MM_GET_EXCEPTION_MASK)
Expand Down Expand Up @@ -1628,6 +1660,15 @@ pub unsafe fn _MM_GET_ROUNDING_MODE() -> u32 {
_mm_getcsr() & _MM_ROUND_MASK
}

/// See [`_mm_setcsr`](fn._mm_setcsr.html)
#[inline]
#[allow(non_snake_case)]
#[target_feature(enable = "sse")]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _MM_SET_DENORMALS_ZERO_MODE(x: u32) {
_mm_setcsr((_mm_getcsr() & !_MM_DENORMALS_ZERO_MASK) | x);
}

/// See [`_mm_setcsr`](fn._mm_setcsr.html)
///
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_MM_SET_EXCEPTION_MASK)
Expand Down
4 changes: 4 additions & 0 deletions crates/stdarch-verify/tests/x86-intel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ fn verify_all_signatures() {
"_mm_store_ps1",
"_mm_getcsr",
"_mm_setcsr",
"_MM_GET_DENORMALS_ZERO_MODE",
"_MM_GET_EXCEPTION_MASK",
"_MM_GET_EXCEPTION_STATE",
"_MM_GET_FLUSH_ZERO_MODE",
"_MM_GET_ROUNDING_MODE",
"_MM_SET_DENORMALS_ZERO_MODE",
"_MM_SET_EXCEPTION_MASK",
"_MM_SET_EXCEPTION_STATE",
"_MM_SET_FLUSH_ZERO_MODE",
Expand Down Expand Up @@ -343,6 +345,8 @@ fn verify_all_signatures() {
// take a signed-integer. This breaks `_MM_SHUFFLE` for
// `_mm_shuffle_ps`:
"_mm_shuffle_ps" => continue,
// Not listed with intel, but manually verified
"_MM_GET_DENORMALS_ZERO_MODE" | "_MM_SET_DENORMALS_ZERO_MODE" => continue,
_ => {}
}

Expand Down