Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement some missing maths-related intrinsics #4095

Merged
merged 1 commit into from
Mar 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there such things as llvm_trunc_f32 and llvm_floor_f32? If so, could add those as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since trunc is fairly new in ES6, we should have a pollyfill.

var Math_trunc = Math.trunc;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kripken: why do we do this kind of redirection btw?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually might not need this any more, since we do it in the asm scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add this line, otherwise I got an error because Math_trunc was not found.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, must be somewhere that depends on it, that we can probably remove. But not a problem for this pr anyhow.


// 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