-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add --fast-math to binaryen passes when linking with -ffast-math
#25513
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
sbc100
merged 17 commits into
emscripten-core:main
from
devalgupta404:clean-ffast-math-only
Oct 23, 2025
+19
−3
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3da992e
Implement -ffast-math → wasm-opt --fast-math; add focused tests
devalgupta404 6eaae06
rename to test_binaryen_fast_math
devalgupta404 ba89711
drop flaky size check
devalgupta404 d3df5ad
update test function
devalgupta404 fe941dd
make fast-math codesize check non-strict
devalgupta404 9c05cb5
Fix test_fast_math_codesize to actually test fast-math
devalgupta404 aa6631b
Move fast-math test to separate file per review
devalgupta404 447942b
Remove redundant fast-math flag verification
devalgupta404 12562fd
Fix ruff linting issues
devalgupta404 8122494
revert previous change
devalgupta404 78b5e34
remove size test
devalgupta404 7531521
remove trailing lines
devalgupta404 e479f4b
fix ruff check
devalgupta404 cfe122c
Fix trailing whitespace and newline issues
devalgupta404 d01047f
Merge branch 'main' into clean-ffast-math-only
devalgupta404 1a66070
Remove test_fast_math.c file
devalgupta404 8657f17
add new line
devalgupta404 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #include <math.h> | ||
| #include <stdio.h> | ||
|
|
||
| static double mandelbrot_iter(double cx, double cy, int max_iter) { | ||
| double x = 0.0, y = 0.0; | ||
| for (int i = 0; i < max_iter; i++) { | ||
| if (x*x + y*y > 4.0) return (double)i; | ||
| double tx = x*x - y*y + cx; | ||
| y = 2.0*x*y + cy; | ||
| x = tx; | ||
| } | ||
| return (double)max_iter; | ||
| } | ||
|
|
||
| static double newton_raphson(double x, int iterations) { | ||
| for (int i = 0; i < iterations; i++) { | ||
| double fx = x*x*x - x - 1.0; | ||
| double fpx = 3.0*x*x - 1.0; | ||
| if (fabs(fpx) < 1e-10) break; | ||
| x = x - fx / fpx; | ||
| } | ||
| return x; | ||
| } | ||
|
|
||
| int main() { | ||
| double result = 0.0; | ||
|
|
||
| for (int i = 0; i < 100; i++) { | ||
| double x = (i - 50) * 0.02; | ||
| for (int j = 0; j < 100; j++) { | ||
| double y = (j - 50) * 0.02; | ||
| result += mandelbrot_iter(x, y, 50); | ||
| } | ||
| } | ||
|
|
||
| for (int i = 0; i < 50; i++) { | ||
| result += newton_raphson(1.5 + i * 0.1, 20); | ||
| } | ||
|
|
||
| for (int i = 0; i < 1000; i++) { | ||
| double angle = i * 0.01; | ||
| result += sin(angle) * cos(angle) + tan(angle); | ||
| } | ||
|
|
||
| printf("Result: %f\n", result); | ||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15202,6 +15202,13 @@ def has_defined_function(file, func): | |
| self.assertIn('foo.cpp', out) | ||
| self.assertIn('/emsdk/emscripten/system/lib/libc/musl/src/string/strcmp.c', out) | ||
|
|
||
| def test_binaryen_fast_math(self): | ||
| # Use a simple input; contents don't matter for -v flag inspection | ||
| err = self.run_process([EMCC, test_file('hello_world.c'), '-v', '-O2', '-ffast-math'], stderr=PIPE).stderr | ||
| self.assertContained('--fast-math', err) | ||
|
|
||
| err_no_fast = self.run_process([EMCC, test_file('hello_world.c'), '-v', '-O2'], stderr=PIPE).stderr | ||
| self.assertNotContained('--fast-math', err_no_fast) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a missing newline here |
||
| def test_relocatable(self): | ||
| # This setting is due for removal: | ||
| # https://github.com/emscripten-core/emscripten/issues/25262 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can delete this file now.