Skip to content

Add llvm.minnum.f(32|64) and llvm.maxnum.f(32|64) intrinsics #5978

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

Merged
merged 1 commit into from
Jan 5, 2018
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,5 @@ a license to everyone to use it as detailed in LICENSE.)
* Dannii Willis <[email protected]>
* Erik Dubbelboer <[email protected]>
* Sergey Tsatsulin <[email protected]>
* varkor <[email protected]>

6 changes: 4 additions & 2 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,10 @@ LibraryManager.library = {
llvm_floor_f64: 'Math_floor',
llvm_round_f32: 'Math_round',
llvm_round_f64: 'Math_round',
llvm_minnum_f32: 'Math_min',
llvm_minnum_f64: 'Math_min',
llvm_maxnum_f32: 'Math_max',
Copy link
Member

Choose a reason for hiding this comment

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

the maxnum ones seem to have already existed (line 4375). Your addition is in a better location, though, let's remove the old ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how I missed those! Updated, thanks.

llvm_maxnum_f64: 'Math_max',

llvm_exp2_f32: function(x) {
return Math.pow(2, x);
Expand Down Expand Up @@ -4372,8 +4376,6 @@ LibraryManager.library = {
llvm_dbg_value: true,
llvm_debugtrap: true,
llvm_ctlz_i32: true,
llvm_maxnum_f32: true,
llvm_maxnum_f64: true,
emscripten_asm_const: true,
emscripten_asm_const_int: true,
emscripten_asm_const_double: true,
Expand Down
1 change: 1 addition & 0 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,7 @@ var Math_imul = Math.imul;
var Math_fround = Math.fround;
var Math_round = Math.round;
var Math_min = Math.min;
var Math_max = Math.max;
var Math_clz32 = Math.clz32;
var Math_trunc = Math.trunc;

Expand Down
14 changes: 14 additions & 0 deletions tests/core/test_llvm_intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ extern double llvm_copysign_f64(double x, double y);

extern double llvm_round_f64(double x);
extern float llvm_round_f32(float x);
extern float llvm_minnum_f32(float x, float y);
extern double llvm_minnum_f64(double x, double y);
extern float llvm_maxnum_f32(float x, float y);
extern double llvm_maxnum_f64(double x, double y);
}

int main(void) {
Expand Down Expand Up @@ -136,6 +140,16 @@ int main(void) {
printf("llvm_round_f32 %.1f\n", llvm_round_f32(-20.5));
printf("llvm_round_f32 %.1f\n", llvm_round_f32(-20.51));

printf("llvm_minnum_f32 %.1f\n", llvm_minnum_f32(5.7, 10.2));
printf("llvm_minnum_f32 %.1f\n", llvm_minnum_f32(8.5, 2.3));
printf("llvm_minnum_f64 %.1f\n", llvm_minnum_f64(5.7, 10.2));
printf("llvm_minnum_f64 %.1f\n", llvm_minnum_f64(8.5, 2.3));

printf("llvm_maxnum_f32 %.1f\n", llvm_maxnum_f32(5.7, 10.2));
printf("llvm_maxnum_f32 %.1f\n", llvm_maxnum_f32(8.5, 2.3));
printf("llvm_maxnum_f64 %.1f\n", llvm_maxnum_f64(5.7, 10.2));
printf("llvm_maxnum_f64 %.1f\n", llvm_maxnum_f64(8.5, 2.3));

printf("llvm_copysign_f32 %.1f\n", llvm_copysign_f32(-1.2, 3.4));
printf("llvm_copysign_f32 %.1f\n", llvm_copysign_f32(5.6, -7.8));
printf("llvm_copysign_f32 %.1f\n", llvm_copysign_f32(-1.3, -2.4));
Expand Down
8 changes: 8 additions & 0 deletions tests/core/test_llvm_intrinsics.out
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ llvm_round_f32 21.0
llvm_round_f32 42.0
llvm_round_f32 -20.0
llvm_round_f32 -21.0
llvm_minnum_f32 5.7
llvm_minnum_f32 2.3
llvm_minnum_f64 5.7
llvm_minnum_f64 2.3
llvm_maxnum_f32 10.2
llvm_maxnum_f32 8.5
llvm_maxnum_f64 10.2
llvm_maxnum_f64 8.5
llvm_copysign_f32 1.2
llvm_copysign_f32 -5.6
llvm_copysign_f32 -1.3
Expand Down