Skip to content

Commit 868ee73

Browse files
committed
Implement some missing maths-related intrinsics
1 parent b0982ef commit 868ee73

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

src/library.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,10 +1398,16 @@ LibraryManager.library = {
13981398
llvm_sqrt_f64: 'Math_sqrt',
13991399
llvm_pow_f32: 'Math_pow',
14001400
llvm_pow_f64: 'Math_pow',
1401+
llvm_powi_f32: 'Math_pow',
1402+
llvm_powi_f64: 'Math_pow',
14011403
llvm_log_f32: 'Math_log',
14021404
llvm_log_f64: 'Math_log',
14031405
llvm_exp_f32: 'Math_exp',
14041406
llvm_exp_f64: 'Math_exp',
1407+
llvm_trunc_f32: 'Math_trunc',
1408+
llvm_trunc_f64: 'Math_trunc',
1409+
llvm_floor_f32: 'Math_floor',
1410+
llvm_floor_f64: 'Math_floor',
14051411

14061412
round__asm: true,
14071413
round__sig: 'dd',

src/preamble.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,11 @@ if (!Math['clz32']) Math['clz32'] = function(x) {
17461746
};
17471747
Math.clz32 = Math['clz32']
17481748

1749+
if (!Math['trunc']) Math['trunc'] = function(x) {
1750+
return x < 0 ? Math.ceil(x) : Math.floor(x);
1751+
};
1752+
Math.trunc = Math['trunc'];
1753+
17491754
var Math_abs = Math.abs;
17501755
var Math_cos = Math.cos;
17511756
var Math_sin = Math.sin;
@@ -1764,6 +1769,7 @@ var Math_imul = Math.imul;
17641769
var Math_fround = Math.fround;
17651770
var Math_min = Math.min;
17661771
var Math_clz32 = Math.clz32;
1772+
var Math_trunc = Math.trunc;
17671773

17681774
// A counter of dependencies for calling run(). If we need to
17691775
// do asynchronous work before running, increment this and

tests/core/test_llvm_intrinsics.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ extern int64_t llvm_cttz_i64(int64_t x, int izZeroUndef);
1111
extern int32_t llvm_ctpop_i32(int32_t x);
1212
extern int64_t llvm_ctpop_i64(int64_t x);
1313
extern int llvm_expect_i32(int x, int y);
14+
extern float llvm_powi_f32(float x, int32_t y);
15+
extern double llvm_powi_f64(double x, int32_t y);
16+
extern float llvm_trunc_f32(float x);
17+
extern double llvm_trunc_f64(double x);
18+
extern float llvm_floor_f32(float x);
19+
extern double llvm_floor_f64(double x);
1420
}
1521

1622
int main(void) {
@@ -40,5 +46,12 @@ int main(void) {
4046
a = __builtin_bswap64(a);
4147
printf("%lld\n", a);
4248

49+
printf("%d\n", (int)llvm_powi_f32(5.0f, 3));
50+
printf("%d\n", (int)llvm_powi_f64(3.0, 5));
51+
printf("%d\n", (int)llvm_trunc_f32(18.0987f));
52+
printf("%d\n", (int)llvm_trunc_f64(-12.42));
53+
printf("%d\n", (int)llvm_floor_f32(27.665f));
54+
printf("%d\n", (int)llvm_floor_f64(-8.95));
55+
4356
return 0;
4457
}

tests/core/test_llvm_intrinsics.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ c5,de,15,8a
88
22
99
13
1010
72057594037927936
11+
125
12+
243
13+
18
14+
-12
15+
27
16+
-9

0 commit comments

Comments
 (0)