-
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
Changes from 9 commits
3da992e
6eaae06
ba89711
d3df5ad
fe941dd
9c05cb5
aa6631b
447942b
12562fd
8122494
78b5e34
7531521
e479f4b
cfe122c
d01047f
1a66070
8657f17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15796,3 +15796,20 @@ def has_defined_function(file, func): | |
| self.assertIn('main.cpp', out) | ||
| 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_fast_math(self): | ||
| self.run_process([EMCC, test_file('other/test_fast_math.c'), '-O2', '-o', 'no_fast.wasm']) | ||
| no_fast_size = os.path.getsize('no_fast.wasm') | ||
| self.run_process([EMCC, test_file('other/test_fast_math.c'), '-O2', '-ffast-math', '-o', 'with_fast.wasm']) | ||
| with_fast_size = os.path.getsize('with_fast.wasm') | ||
| print(f'no_fast_size={no_fast_size} with_fast_size={with_fast_size}') | ||
|
|
||
| self.assertLessEqual(with_fast_size, no_fast_size) | ||
|
||
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.
Is this supposed to be part of this change?
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 tried to run tests locally and The errors were: W293 and PLC0415 so thats why i include that import.
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.
You are likely using a different version of ruff. You can use
pip install -f requireents-dev.txtto install the one we use. Or you can just revert this line an re-upload?