Introduce math::arch::intrinsics
This module provides implementations of basic functions that defer to LLVM for what to do, rather than either using a builtin operation or calling another function in this library. `math::arch` will become the home of anything architecture-specific in the future.
This commit is contained in:
parent
e8584d608e
commit
1b7346bf5f
3 changed files with 62 additions and 0 deletions
52
library/compiler-builtins/libm/src/math/arch/intrinsics.rs
Normal file
52
library/compiler-builtins/libm/src/math/arch/intrinsics.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
// Config is needed for times when this module is available but we don't call everything
|
||||
#![allow(dead_code)]
|
||||
|
||||
pub fn ceil(x: f64) -> f64 {
|
||||
// SAFETY: safe intrinsic with no preconditions
|
||||
unsafe { core::intrinsics::ceilf64(x) }
|
||||
}
|
||||
|
||||
pub fn ceilf(x: f32) -> f32 {
|
||||
// SAFETY: safe intrinsic with no preconditions
|
||||
unsafe { core::intrinsics::ceilf32(x) }
|
||||
}
|
||||
|
||||
pub fn fabs(x: f64) -> f64 {
|
||||
// SAFETY: safe intrinsic with no preconditions
|
||||
unsafe { core::intrinsics::fabsf64(x) }
|
||||
}
|
||||
|
||||
pub fn fabsf(x: f32) -> f32 {
|
||||
// SAFETY: safe intrinsic with no preconditions
|
||||
unsafe { core::intrinsics::fabsf32(x) }
|
||||
}
|
||||
|
||||
pub fn floor(x: f64) -> f64 {
|
||||
// SAFETY: safe intrinsic with no preconditions
|
||||
unsafe { core::intrinsics::floorf64(x) }
|
||||
}
|
||||
|
||||
pub fn floorf(x: f32) -> f32 {
|
||||
// SAFETY: safe intrinsic with no preconditions
|
||||
unsafe { core::intrinsics::floorf32(x) }
|
||||
}
|
||||
|
||||
pub fn sqrt(x: f64) -> f64 {
|
||||
// SAFETY: safe intrinsic with no preconditions
|
||||
unsafe { core::intrinsics::sqrtf64(x) }
|
||||
}
|
||||
|
||||
pub fn sqrtf(x: f32) -> f32 {
|
||||
// SAFETY: safe intrinsic with no preconditions
|
||||
unsafe { core::intrinsics::sqrtf32(x) }
|
||||
}
|
||||
|
||||
pub fn trunc(x: f64) -> f64 {
|
||||
// SAFETY: safe intrinsic with no preconditions
|
||||
unsafe { core::intrinsics::truncf64(x) }
|
||||
}
|
||||
|
||||
pub fn truncf(x: f32) -> f32 {
|
||||
// SAFETY: safe intrinsic with no preconditions
|
||||
unsafe { core::intrinsics::truncf32(x) }
|
||||
}
|
||||
9
library/compiler-builtins/libm/src/math/arch/mod.rs
Normal file
9
library/compiler-builtins/libm/src/math/arch/mod.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
//! Architecture-specific routines and operations.
|
||||
//!
|
||||
//! LLVM will already optimize calls to some of these in cases that there are hardware
|
||||
//! instructions. Providing an implementation here just ensures that the faster implementation
|
||||
//! is used when calling the function directly. This helps anyone who uses `libm` directly, as
|
||||
//! well as improving things when these routines are called as part of other implementations.
|
||||
|
||||
#[cfg(intrinsics_enabled)]
|
||||
pub mod intrinsics;
|
||||
|
|
@ -302,6 +302,7 @@ pub use self::trunc::trunc;
|
|||
pub use self::truncf::truncf;
|
||||
|
||||
// Private modules
|
||||
mod arch;
|
||||
mod expo2;
|
||||
mod fenv;
|
||||
mod k_cos;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue