Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Replace calls to core::arch intrinsics with assembly #534

Merged
merged 2 commits into from
Apr 9, 2025
Merged
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
1 change: 1 addition & 0 deletions crates/libm-test/src/precision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{BaseName, CheckBasis, CheckCtx, Float, Identifier, Int, TestResult};
pub struct SpecialCase;

/// ULP allowed to differ from the results returned by a test basis.
#[allow(clippy::single_match)]
pub fn default_ulp(ctx: &CheckCtx) -> u32 {
// ULP compared to the infinite (MPFR) result.
let mut ulp = match ctx.base_name {
Expand Down
35 changes: 20 additions & 15 deletions src/math/arch/i686.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
//! Architecture-specific support for x86-32 and x86-64 with SSE2

#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;

pub fn sqrtf(x: f32) -> f32 {
pub fn sqrtf(mut x: f32) -> f32 {
// SAFETY: `sqrtss` is part of `sse2`, which this module is gated behind. It has no memory
// access or side effects.
unsafe {
let m = _mm_set_ss(x);
let m_sqrt = _mm_sqrt_ss(m);
_mm_cvtss_f32(m_sqrt)
}
core::arch::asm!(
"sqrtss {x}, {x}",
x = inout(xmm_reg) x,
options(nostack, nomem, pure),
)
};
x
}

pub fn sqrt(x: f64) -> f64 {
pub fn sqrt(mut x: f64) -> f64 {
// SAFETY: `sqrtsd` is part of `sse2`, which this module is gated behind. It has no memory
// access or side effects.
unsafe {
let m = _mm_set_sd(x);
let m_sqrt = _mm_sqrt_pd(m);
_mm_cvtsd_f64(m_sqrt)
}
core::arch::asm!(
"sqrtsd {x}, {x}",
x = inout(xmm_reg) x,
options(nostack, nomem, pure),
)
};
x
}
1 change: 0 additions & 1 deletion src/math/support/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ impl Status {
/// The default result for division is +/-inf based on operand sign. For `logB`, the default
/// result is -inf.
/// `x / y` when `x != 0.0` and `y == 0.0`,

#[cfg_attr(not(feature = "unstable-public-internals"), allow(dead_code))]
pub const DIVIDE_BY_ZERO: Self = Self(1 << 2);

Expand Down
Loading