Skip to content

Add javascript api for fast-math option #3188

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 9 commits into from
Oct 1, 2020
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
4 changes: 4 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3570,6 +3570,10 @@ void BinaryenSetLowMemoryUnused(int on) {
globalPassOptions.lowMemoryUnused = on != 0;
}

int BinaryenGetFastMath(void) { return globalPassOptions.fastMath; }

void BinaryenSetFastMath(int value) { globalPassOptions.fastMath = value != 0; }

const char* BinaryenGetPassArgument(const char* key) {
assert(key);
const auto& args = globalPassOptions.arguments;
Expand Down
10 changes: 10 additions & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,16 @@ BINARYEN_API int BinaryenGetLowMemoryUnused(void);
// when optimizing. Applies to all modules, globally.
BINARYEN_API void BinaryenSetLowMemoryUnused(int on);

// Gets whether fast math optimizations are enabled, ignoring for example
// corner cases of floating-point math like NaN changes.
// Applies to all modules, globally.
BINARYEN_API int BinaryenGetFastMath(void);

// Enables or disables fast math optimizations, ignoring for example
// corner cases of floating-point math like NaN changes.
// Applies to all modules, globally.
BINARYEN_API void BinaryenSetFastMath(int value);

// Gets the value of the specified arbitrary pass argument.
// Applies to all modules, globally.
BINARYEN_API const char* BinaryenGetPassArgument(const char* name);
Expand Down
12 changes: 12 additions & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -3046,6 +3046,18 @@ Module['setLowMemoryUnused'] = function(on) {
Module['_BinaryenSetLowMemoryUnused'](on);
};

// Gets whether fast math optimizations are enabled, ignoring for example
// corner cases of floating-point math like NaN changes.
Module['getFastMath'] = function() {
return Boolean(Module['_BinaryenGetFastMath']());
};

// Enables or disables fast math optimizations, ignoring for example
// corner cases of floating-point math like NaN changes.
Module['setFastMath'] = function(value) {
Module['_BinaryenSetFastMath'](value);
};

// Gets the value of the specified arbitrary pass argument.
Module['getPassArgument'] = function(key) {
return preserveStack(() => {
Expand Down
3 changes: 3 additions & 0 deletions test/binaryen.js/fast-math.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
console.log("// fastMath=" + binaryen.getFastMath());
binaryen.setFastMath(true);
assert(binaryen.getFastMath() == true);
1 change: 1 addition & 0 deletions test/binaryen.js/fast-math.js.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// fastMath=false