From 36f93dbd791338f85cd7b9e7af69dbffadeff858 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 12 Jul 2018 20:40:30 -0500 Subject: [PATCH 1/3] expose math symbol on wasm32-unknown-unknown --- .gitmodules | 3 +++ .travis.yml | 3 +++ libm | 1 + src/lib.rs | 3 +++ src/math.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+) create mode 160000 libm create mode 100644 src/math.rs diff --git a/.gitmodules b/.gitmodules index 3ff1154f..7162b2c4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "compiler-rt"] path = compiler-rt url = https://github.com/rust-lang/compiler-rt +[submodule "libm"] + path = libm + url = https://github.com/japaric/libm diff --git a/.travis.yml b/.travis.yml index efd0b173..7b7ed7e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,9 @@ matrix: - env: TARGET=thumbv7em-linux-eabi - env: TARGET=thumbv7em-linux-eabihf - env: TARGET=thumbv7m-linux-eabi + - env: TARGET=wasm32-unknown-unknown + install: rustup target add $TARGET + script: cargo build --target $TARGET - env: TARGET=x86_64-apple-darwin os: osx - env: TARGET=x86_64-unknown-linux-gnu diff --git a/libm b/libm new file mode 160000 index 00000000..d65f60f2 --- /dev/null +++ b/libm @@ -0,0 +1 @@ +Subproject commit d65f60f24289ba212f5d47792f7236857efb2339 diff --git a/src/lib.rs b/src/lib.rs index 619b6ac7..3e665a88 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,6 +48,9 @@ pub mod int; pub mod float; pub mod mem; +// only for the wasm32-unknown-unknown target +#[cfg(all(target_arch = "wasm32", target_os = "unknown"))] +pub mod math; #[cfg(target_arch = "arm")] pub mod arm; diff --git a/src/math.rs b/src/math.rs new file mode 100644 index 00000000..f9ee36f0 --- /dev/null +++ b/src/math.rs @@ -0,0 +1,51 @@ +#[allow(dead_code)] +#[path = "../../libm/src/math/mod.rs"] +mod libm; + +macro_rules! no_mangle { + ($(fn $fun:ident($($iid:ident : $ity:ty),+) -> $oty:ty;)+) => { + $( + #[no_mangle] + pub fn $fun($($iid: $ity),+) -> $oty { + self::libm::$fun($($iid),+) + } + )+ + } +} + +no_mangle! { + fn acos(x: f64) -> f64; + fn asin(x: f64) -> f64; + fn atan(x: f64) -> f64; + fn atan2(x: f64, y: f64) -> f64; + fn cbrt(x: f64) -> f64; + fn cosh(x: f64) -> f64; + fn expm1(x: f64) -> f64; + fn hypot(x: f64, y: f64) -> f64; + fn log1p(x: f64) -> f64; + fn sinh(x: f64) -> f64; + fn tan(x: f64) -> f64; + fn tanh(x: f64) -> f64; + fn cos(x: f64) -> f64; + fn cosf(x: f32) -> f32; + fn exp(x: f64) -> f64; + fn expf(x: f32) -> f32; + fn log2(x: f64) -> f64; + fn log2f(x: f32) -> f32; + fn log10(x: f64) -> f64; + fn log10f(x: f32) -> f32; + fn log(x: f64) -> f64; + fn logf(x: f32) -> f32; + fn round(x: f64) -> f64; + fn roundf(x: f32) -> f32; + fn sin(x: f64) -> f64; + fn sinf(x: f32) -> f32; + fn pow(x: f64, y: f64) -> f64; + fn powf(x: f32, y: f32) -> f32; + fn exp2(x: f64) -> f64; + fn exp2f(x: f32) -> f32; + fn fmod(x: f64, y: f64) -> f64; + fn fmodf(x: f32, y: f32) -> f32; + fn fma(x: f64, y: f64, z: f64) -> f64; + fn fmaf(x: f32, y: f32, z: f32) -> f32; +} From cc78ff665ddb2ed23472e7ac336c3fe29c9097b7 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 18 Jul 2018 11:36:24 -0500 Subject: [PATCH 2/3] fix path --- src/math.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math.rs b/src/math.rs index f9ee36f0..76bb7267 100644 --- a/src/math.rs +++ b/src/math.rs @@ -1,5 +1,5 @@ #[allow(dead_code)] -#[path = "../../libm/src/math/mod.rs"] +#[path = "../libm/src/math/mod.rs"] mod libm; macro_rules! no_mangle { From d73ccba9886acc132a1d7e9565509c98fdd7c39b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 18 Jul 2018 10:04:33 -0700 Subject: [PATCH 3/3] Use `intrinsics!` macro for math intrinsics Make sure they respect the `mangled-names` feature as well as have the `"C"` ABI. --- src/math.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/math.rs b/src/math.rs index 76bb7267..f1eaaa5f 100644 --- a/src/math.rs +++ b/src/math.rs @@ -4,12 +4,13 @@ mod libm; macro_rules! no_mangle { ($(fn $fun:ident($($iid:ident : $ity:ty),+) -> $oty:ty;)+) => { - $( - #[no_mangle] - pub fn $fun($($iid: $ity),+) -> $oty { - self::libm::$fun($($iid),+) - } - )+ + intrinsics! { + $( + pub extern "C" fn $fun($($iid: $ity),+) -> $oty { + self::libm::$fun($($iid),+) + } + )+ + } } }