From 868ee737cf44bcc5ff68f4388bf1201227bc8a85 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sat, 13 Feb 2016 13:20:47 +0100 Subject: [PATCH] Implement some missing maths-related intrinsics --- src/library.js | 6 ++++++ src/preamble.js | 6 ++++++ tests/core/test_llvm_intrinsics.in | 13 +++++++++++++ tests/core/test_llvm_intrinsics.out | 6 ++++++ 4 files changed, 31 insertions(+) diff --git a/src/library.js b/src/library.js index 0734eacd0f43b..4d91d43024814 100644 --- a/src/library.js +++ b/src/library.js @@ -1398,10 +1398,16 @@ LibraryManager.library = { llvm_sqrt_f64: 'Math_sqrt', llvm_pow_f32: 'Math_pow', llvm_pow_f64: 'Math_pow', + llvm_powi_f32: 'Math_pow', + llvm_powi_f64: 'Math_pow', llvm_log_f32: 'Math_log', llvm_log_f64: 'Math_log', llvm_exp_f32: 'Math_exp', llvm_exp_f64: 'Math_exp', + llvm_trunc_f32: 'Math_trunc', + llvm_trunc_f64: 'Math_trunc', + llvm_floor_f32: 'Math_floor', + llvm_floor_f64: 'Math_floor', round__asm: true, round__sig: 'dd', diff --git a/src/preamble.js b/src/preamble.js index f8afdf5f0420d..bddd6f8ccd73e 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -1746,6 +1746,11 @@ if (!Math['clz32']) Math['clz32'] = function(x) { }; Math.clz32 = Math['clz32'] +if (!Math['trunc']) Math['trunc'] = function(x) { + return x < 0 ? Math.ceil(x) : Math.floor(x); +}; +Math.trunc = Math['trunc']; + var Math_abs = Math.abs; var Math_cos = Math.cos; var Math_sin = Math.sin; @@ -1764,6 +1769,7 @@ var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_min = Math.min; var Math_clz32 = Math.clz32; +var Math_trunc = Math.trunc; // A counter of dependencies for calling run(). If we need to // do asynchronous work before running, increment this and diff --git a/tests/core/test_llvm_intrinsics.in b/tests/core/test_llvm_intrinsics.in index 4b943f0e5270a..04f60ed6648eb 100644 --- a/tests/core/test_llvm_intrinsics.in +++ b/tests/core/test_llvm_intrinsics.in @@ -11,6 +11,12 @@ extern int64_t llvm_cttz_i64(int64_t x, int izZeroUndef); extern int32_t llvm_ctpop_i32(int32_t x); extern int64_t llvm_ctpop_i64(int64_t x); extern int llvm_expect_i32(int x, int y); +extern float llvm_powi_f32(float x, int32_t y); +extern double llvm_powi_f64(double x, int32_t y); +extern float llvm_trunc_f32(float x); +extern double llvm_trunc_f64(double x); +extern float llvm_floor_f32(float x); +extern double llvm_floor_f64(double x); } int main(void) { @@ -40,5 +46,12 @@ int main(void) { a = __builtin_bswap64(a); printf("%lld\n", a); + printf("%d\n", (int)llvm_powi_f32(5.0f, 3)); + printf("%d\n", (int)llvm_powi_f64(3.0, 5)); + printf("%d\n", (int)llvm_trunc_f32(18.0987f)); + printf("%d\n", (int)llvm_trunc_f64(-12.42)); + printf("%d\n", (int)llvm_floor_f32(27.665f)); + printf("%d\n", (int)llvm_floor_f64(-8.95)); + return 0; } diff --git a/tests/core/test_llvm_intrinsics.out b/tests/core/test_llvm_intrinsics.out index 659b3c21e72a9..5a137f8765ec4 100644 --- a/tests/core/test_llvm_intrinsics.out +++ b/tests/core/test_llvm_intrinsics.out @@ -8,3 +8,9 @@ c5,de,15,8a 22 13 72057594037927936 +125 +243 +18 +-12 +27 +-9 \ No newline at end of file