From c63f4d68c8ffd5f94e933cec14eccdb986d20a1d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 7 Nov 2021 20:06:05 +0000 Subject: [PATCH] Add math_js.odin specific calls (that just wrap the `f64` procedures) --- core/math/math_basic.odin | 1 + core/math/math_js.odin | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 core/math/math_js.odin diff --git a/core/math/math_basic.odin b/core/math/math_basic.odin index 3e32ab781..26bf4691d 100644 --- a/core/math/math_basic.odin +++ b/core/math/math_basic.odin @@ -1,3 +1,4 @@ +//+build !js package math @(default_calling_convention="none") diff --git a/core/math/math_js.odin b/core/math/math_js.odin new file mode 100644 index 000000000..c2ac1bedf --- /dev/null +++ b/core/math/math_js.odin @@ -0,0 +1,43 @@ +//+build js +package math + +foreign import "odin_env" + +@(default_calling_convention="c") +foreign odin_env { + @(link_name="sqrt") + sqrt_f64 :: proc(x: f64) -> f64 --- + @(link_name="sin") + sin_f64 :: proc(θ: f64) -> f64 --- + @(link_name="cos") + cos_f64 :: proc(θ: f64) -> f64 --- + @(link_name="pow") + pow_f64 :: proc(x, power: f64) -> f64 --- + @(link_name="fmuladd") + fmuladd_f64 :: proc(a, b, c: f64) -> f64 --- + @(link_name="ln") + ln_f64 :: proc(x: f64) -> f64 --- + @(link_name="exp") + exp_f64 :: proc(x: f64) -> f64 --- + @(link_name="ldexp") + ldexp_f64 :: proc(val: f64, exp: i32) -> f64 --- +} + + +sqrt_f16 :: proc "c" (x: f16) -> f16 { return f16(sqrt_f64(f64(x))) } +sin_f16 :: proc "c" (θ: f16) -> f16 { return f16(sin_f64(f64(θ))) } +cos_f16 :: proc "c" (θ: f16) -> f16 { return f16(cos_f64(f64(θ))) } +pow_f16 :: proc "c" (x, power: f16) -> f16 { return f16(pow_f64(f64(x), f64(power))) } +fmuladd_f16 :: proc "c" (a, b, c: f16) -> f16 { return f16(fmuladd_f64(f64(a), f64(a), f64(c))) } +ln_f16 :: proc "c" (x: f16) -> f16 { return f16(ln_f64(f64(x))) } +exp_f16 :: proc "c" (x: f16) -> f16 { return f16(exp_f64(f64(x))) } +ldexp_f16 :: proc "c" (val: f16, exp: i32) -> f16 { return f16(ldexp_f64(f64(val), exp) ) } + +sqrt_f32 :: proc "c" (x: f32) -> f32 { return f32(sqrt_f64(f64(x))) } +sin_f32 :: proc "c" (θ: f32) -> f32 { return f32(sin_f64(f64(θ))) } +cos_f32 :: proc "c" (θ: f32) -> f32 { return f32(cos_f64(f64(θ))) } +pow_f32 :: proc "c" (x, power: f32) -> f32 { return f32(pow_f64(f64(x), f64(power))) } +fmuladd_f32 :: proc "c" (a, b, c: f32) -> f32 { return f32(fmuladd_f64(f64(a), f64(a), f64(c))) } +ln_f32 :: proc "c" (x: f32) -> f32 { return f32(ln_f64(f64(x))) } +exp_f32 :: proc "c" (x: f32) -> f32 { return f32(exp_f64(f64(x))) } +ldexp_f32 :: proc "c" (val: f32, exp: i32) -> f32 { return f32(ldexp_f64(f64(val), exp) ) } \ No newline at end of file