From abbc1096fbcdd108e809f620743673e74f84b188 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 1 Oct 2020 13:31:41 +0300 Subject: [PATCH 1/9] init --- src/binaryen-c.cpp | 8 ++++++++ src/js/binaryen.js-post.js | 10 ++++++++++ test/binaryen.js/fast-math.js | 3 +++ test/binaryen.js/fast-math.txt | 1 + 4 files changed, 22 insertions(+) create mode 100644 test/binaryen.js/fast-math.js create mode 100644 test/binaryen.js/fast-math.txt diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index f4515208fc3..b367649a6d1 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -3570,6 +3570,14 @@ 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/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index 529474098cb..f20ae10da67 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3046,6 +3046,16 @@ Module['setLowMemoryUnused'] = function(on) { Module['_BinaryenSetLowMemoryUnused'](on); }; +// Gets optimize floats without handling corner cases of NaNs. +Module['getFastMath'] = function() { + return Boolean(Module['_BinaryenGetFastMath']()); +}; + +// Enables or disables float optimization without handling corner cases of NaNs. +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 00000000000..f1953d5e10b --- /dev/null +++ b/test/binaryen.js/fast-math.js @@ -0,0 +1,3 @@ +console.log("// fastMath=" + Boolean(binaryen.getFastMath())); +binaryen.setFastMath(true); +assert(binaryen.getFastMath() == true); diff --git a/test/binaryen.js/fast-math.txt b/test/binaryen.js/fast-math.txt new file mode 100644 index 00000000000..3db7141bb9a --- /dev/null +++ b/test/binaryen.js/fast-math.txt @@ -0,0 +1 @@ +// fastMath=true From 02b5336961b76b5e060136cc366b563e48fa640e Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 1 Oct 2020 13:33:51 +0300 Subject: [PATCH 2/9] remove unnecessary cast in test --- test/binaryen.js/fast-math.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/binaryen.js/fast-math.js b/test/binaryen.js/fast-math.js index f1953d5e10b..48b575b4155 100644 --- a/test/binaryen.js/fast-math.js +++ b/test/binaryen.js/fast-math.js @@ -1,3 +1,3 @@ -console.log("// fastMath=" + Boolean(binaryen.getFastMath())); +console.log("// fastMath=" + binaryen.getFastMath()); binaryen.setFastMath(true); assert(binaryen.getFastMath() == true); From b4ab0c816e945c4e7adc05c9e1c445987a9cbbd7 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 1 Oct 2020 13:35:22 +0300 Subject: [PATCH 3/9] lint --- src/binaryen-c.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index b367649a6d1..bbacd517b1d 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -3570,13 +3570,9 @@ void BinaryenSetLowMemoryUnused(int on) { globalPassOptions.lowMemoryUnused = on != 0; } -int BinaryenGetFastMath(void) { - return globalPassOptions.fastMath; -} +int BinaryenGetFastMath(void) { return globalPassOptions.fastMath; } -void BinaryenSetFastMath(int value) { - globalPassOptions.fastMath = value != 0; -} +void BinaryenSetFastMath(int value) { globalPassOptions.fastMath = value != 0; } const char* BinaryenGetPassArgument(const char* key) { assert(key); From a9e8ad21588b1e5dca95636914457382f5b1aa17 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 1 Oct 2020 13:47:42 +0300 Subject: [PATCH 4/9] add api to binaryen-c.h --- src/binaryen-c.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/binaryen-c.h b/src/binaryen-c.h index 4ca76657d97..8d3767de1d3 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -2134,6 +2134,12 @@ BINARYEN_API int BinaryenGetLowMemoryUnused(void); // when optimizing. Applies to all modules, globally. BINARYEN_API void BinaryenSetLowMemoryUnused(int on); +// Gets optimize floats without handling corner cases of NaNs. +BINARYEN_API int BinaryenGetFastMath(void); + +// Enables or disables float optimization without handling corner cases of NaNs. +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); From ac0c16f511816046a494d60c8046a6bb06608bc4 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 1 Oct 2020 13:48:15 +0300 Subject: [PATCH 5/9] fix fixture --- test/binaryen.js/fast-math.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/binaryen.js/fast-math.txt b/test/binaryen.js/fast-math.txt index 3db7141bb9a..e403908b441 100644 --- a/test/binaryen.js/fast-math.txt +++ b/test/binaryen.js/fast-math.txt @@ -1 +1 @@ -// fastMath=true +// fastMath=false From 78086fb74c6822a7c713988cc5c56b5ee2771507 Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 1 Oct 2020 14:03:09 +0300 Subject: [PATCH 6/9] fix name of artifact --- test/binaryen.js/{fast-math.txt => fast-math.js.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/binaryen.js/{fast-math.txt => fast-math.js.txt} (100%) diff --git a/test/binaryen.js/fast-math.txt b/test/binaryen.js/fast-math.js.txt similarity index 100% rename from test/binaryen.js/fast-math.txt rename to test/binaryen.js/fast-math.js.txt From 0643710e9d977a4e39f68fabd139e47d714fc94a Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 1 Oct 2020 14:13:38 +0300 Subject: [PATCH 7/9] fix? --- test/binaryen.js/fast-math.js.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/binaryen.js/fast-math.js.txt b/test/binaryen.js/fast-math.js.txt index e403908b441..0a0d43cb6f9 100644 --- a/test/binaryen.js/fast-math.js.txt +++ b/test/binaryen.js/fast-math.js.txt @@ -1 +1 @@ -// fastMath=false +// fastMath=false From 808d493f659d8f147013e67b7871dd9a9b63ba0c Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 1 Oct 2020 15:06:35 +0300 Subject: [PATCH 8/9] improve comments for binaryen-c.h --- src/binaryen-c.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/binaryen-c.h b/src/binaryen-c.h index 8d3767de1d3..10b52dbdd73 100644 --- a/src/binaryen-c.h +++ b/src/binaryen-c.h @@ -2134,10 +2134,14 @@ BINARYEN_API int BinaryenGetLowMemoryUnused(void); // when optimizing. Applies to all modules, globally. BINARYEN_API void BinaryenSetLowMemoryUnused(int on); -// Gets optimize floats without handling corner cases of NaNs. +// 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 float optimization without handling corner cases of NaNs. +// 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. From 55a52fb6165d824abb3f14dfc26997fc69d6a9eb Mon Sep 17 00:00:00 2001 From: MaxGraey Date: Thu, 1 Oct 2020 15:18:00 +0300 Subject: [PATCH 9/9] more --- src/js/binaryen.js-post.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index f20ae10da67..3cce22411a0 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -3046,12 +3046,14 @@ Module['setLowMemoryUnused'] = function(on) { Module['_BinaryenSetLowMemoryUnused'](on); }; -// Gets optimize floats without handling corner cases of NaNs. +// 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 float optimization without handling corner cases of NaNs. +// 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); };