Skip to content

Commit

Permalink
Implement some missing maths-related intrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka committed Feb 20, 2016
1 parent b0982ef commit 868ee73
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions tests/core/test_llvm_intrinsics.in
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions tests/core/test_llvm_intrinsics.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ c5,de,15,8a
22
13
72057594037927936
125
243
18
-12
27
-9

0 comments on commit 868ee73

Please sign in to comment.