diff options
author | Max Graey <maxgraey@gmail.com> | 2020-10-01 15:49:40 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-01 14:49:40 +0200 |
commit | e1a843b15d9939eaa258261f5fed67ea9c493a65 (patch) | |
tree | 20ee07241fd721a63bea8f23761ed2a86dcd8a7e | |
parent | 2a935b64dde22671644c4712d0f45e8df60f94eb (diff) | |
download | binaryen-e1a843b15d9939eaa258261f5fed67ea9c493a65.tar.gz binaryen-e1a843b15d9939eaa258261f5fed67ea9c493a65.tar.bz2 binaryen-e1a843b15d9939eaa258261f5fed67ea9c493a65.zip |
Add C and JS APIs for fast math (#3188)
Adds `BinaryenGetFastMath` and `BinaryenSetFastMath` to the C API, respectively `binaryen.getFastMath` and `binaryen.setFastMath` to the JS API.
-rw-r--r-- | src/binaryen-c.cpp | 4 | ||||
-rw-r--r-- | src/binaryen-c.h | 10 | ||||
-rw-r--r-- | src/js/binaryen.js-post.js | 12 | ||||
-rw-r--r-- | test/binaryen.js/fast-math.js | 3 | ||||
-rw-r--r-- | test/binaryen.js/fast-math.js.txt | 1 |
5 files changed, 30 insertions, 0 deletions
diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index f4515208f..bbacd517b 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -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; diff --git a/src/binaryen-c.h b/src/binaryen-c.h index 4ca76657d..10b52dbdd 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -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); diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 529474098..3cce22411 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -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(() => { diff --git a/test/binaryen.js/fast-math.js b/test/binaryen.js/fast-math.js new file mode 100644 index 000000000..48b575b41 --- /dev/null +++ b/test/binaryen.js/fast-math.js @@ -0,0 +1,3 @@ +console.log("// fastMath=" + binaryen.getFastMath()); +binaryen.setFastMath(true); +assert(binaryen.getFastMath() == true); diff --git a/test/binaryen.js/fast-math.js.txt b/test/binaryen.js/fast-math.js.txt new file mode 100644 index 000000000..0a0d43cb6 --- /dev/null +++ b/test/binaryen.js/fast-math.js.txt @@ -0,0 +1 @@ +// fastMath=false |