-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement f64 method polyfills with intrinsics support (#21)
- Loading branch information
Showing
6 changed files
with
66 additions
and
12 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "caches" | ||
version = "0.2.8" | ||
version = "0.2.9" | ||
authors = ["Al Liu <[email protected]>"] | ||
description = "This is a Rust implementation for popular caches (support no_std)." | ||
homepage = "https://github.com/al8n/caches-rs" | ||
|
@@ -42,7 +42,9 @@ nightly = ["rand/nightly"] | |
|
||
[dependencies] | ||
bitvec = { version = "1", default-features = false } | ||
cfg-if = "1.0.0" | ||
hashbrown = { version = "0.14", optional = true } | ||
libm = {version = "0.2.8", optional = true} | ||
rand = {version = "0.8", optional = true} | ||
|
||
[dev-dependencies] | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/// Three level poliyfill dor the f64 `ceil`, `ln`, and `floor` functions. | ||
/// Using these functions in a no_std context falls back to libm's manual | ||
/// implementation from musl's libc. | ||
/// Using the nightly feature allows the upgrade to using LLVM hints, and | ||
/// allowing LLVM to provide a software fallback for target platforms | ||
/// witout hardware f64 instructions. | ||
|
||
cfg_if! { | ||
if #[cfg(feature = "std")] { | ||
#[inline(always)] | ||
pub(crate) fn ceil(val: f64) -> f64 { | ||
val.ceil() | ||
} | ||
#[inline(always)] | ||
pub(crate) fn ln(val: f64) -> f64 { | ||
val.ln() | ||
} | ||
#[inline(always)] | ||
pub(crate) fn floor(val: f64) -> f64 { | ||
val.floor() | ||
} | ||
} else { | ||
use libm; | ||
#[inline(always)] | ||
pub(crate) fn ceil(val: f64) -> f64 { | ||
libm::ceil(val) | ||
} | ||
#[inline(always)] | ||
pub(crate) fn ln(val: f64) -> f64 { | ||
libm::log(val) | ||
} | ||
#[inline(always)] | ||
pub(crate) fn floor(val: f64) -> f64 { | ||
libm::floor(val) | ||
} | ||
} | ||
} |