-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move architecture-specific code to
src/math/arch
Move the code and call into its new location with `select_implementation`.
- Loading branch information
Showing
7 changed files
with
261 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! Architecture-specific support for x86-32 without SSE2 | ||
use super::super::fabs; | ||
|
||
/// Use an alternative implementation on x86, because the | ||
/// main implementation fails with the x87 FPU used by | ||
/// debian i386, probably due to excess precision issues. | ||
/// Basic implementation taken from https://github.com/rust-lang/libm/issues/219. | ||
pub fn ceil(x: f64) -> f64 { | ||
if fabs(x).to_bits() < 4503599627370496.0_f64.to_bits() { | ||
let truncated = x as i64 as f64; | ||
if truncated < x { | ||
return truncated + 1.0; | ||
} else { | ||
return truncated; | ||
} | ||
} else { | ||
return x; | ||
} | ||
} | ||
|
||
/// Use an alternative implementation on x86, because the | ||
/// main implementation fails with the x87 FPU used by | ||
/// debian i386, probably due to excess precision issues. | ||
/// Basic implementation taken from https://github.com/rust-lang/libm/issues/219. | ||
pub fn floor(x: f64) -> f64 { | ||
if fabs(x).to_bits() < 4503599627370496.0_f64.to_bits() { | ||
let truncated = x as i64 as f64; | ||
if truncated > x { | ||
return truncated - 1.0; | ||
} else { | ||
return truncated; | ||
} | ||
} else { | ||
return x; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//! Architecture-specific support for x86-32 and x86-64 with SSE2 | ||
#![cfg(not(feature = "force-soft-floats"))] | ||
|
||
#[cfg(target_arch = "x86")] | ||
use core::arch::x86::*; | ||
#[cfg(target_arch = "x86_64")] | ||
use core::arch::x86_64::*; | ||
|
||
pub fn sqrtf(x: f32) -> f32 { | ||
unsafe { | ||
let m = _mm_set_ss(x); | ||
let m_sqrt = _mm_sqrt_ss(m); | ||
_mm_cvtss_f32(m_sqrt) | ||
} | ||
} | ||
|
||
pub fn sqrt(x: f64) -> f64 { | ||
unsafe { | ||
let m = _mm_set_sd(x); | ||
let m_sqrt = _mm_sqrt_pd(m); | ||
_mm_cvtsd_f64(m_sqrt) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.