-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Implement -ffast-math flag mapping to wasm-opt --fast-math #25498
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
base: main
Are you sure you want to change the base?
Implement -ffast-math flag mapping to wasm-opt --fast-math #25498
Conversation
Auto-generated documentation update for the new FAST_MATH setting added in the previous commit.
src/settings.js
Outdated
// This enables aggressive floating-point optimizations that may violate | ||
// IEEE 754 semantics but can improve performance. | ||
// [link] | ||
var FAST_MATH = 0; |
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.
This can be a private setting, that is, there is no need for a new public setting here. To do that, add to src/settings_internal.js
rather than this file.
Can we test this somehow? |
if you want i can push the tests also |
We normally like to do black box test of emcc, so maybe here we could have a test that using |
Did anyone actually request this? Can you say more about your use case? |
Many applications use floating point math extensively so -ffast-math flag enables aggressive optimizations that can significantly improve performance around 10-30% improvement without code changes and the issue #21497 requesting this feature specifically. |
sir i just sync my fork so there are lot of changes please either consider the commits or if you want i will close this PR and open new PR. |
Hmm, such changes shouldn't appear when merging in latest upstream. How did you merge? Perhaps something went wrong there. |
My point is that issue #21497 actually does not request this feature specifically. It's entirely speculative. That's why I'm curious about the use case here. 10-30% sounds pretty good! Is that specifically for Binaryen fast math or for fast-math overall? what kind of application is this? |
@dschuff there is TODO present in tools/cmdline.py (line 297-299). It is clearly mentioned to use this method |
Implement -ffast-math flag mapping to wasm-opt --fast-math
Description
This PR implements the mapping from the
-ffast-math
compiler flag to thewasm-opt --fast-math
optimization flag, as requested in issue #21497.Changes Made
1. Added FAST_MATH Setting (
src/settings.js
)FAST_MATH
setting in the Tuning section with default value 0[link]
flag as it affects wasm-opt during linking2. Command Line Flag Handling (
tools/cmdline.py
)-ffast-math
flag to setFAST_MATH = 1
-Ofast
optimization level to also enable fast math (since-Ofast
typically includes-ffast-math
semantics)3. wasm-opt Integration (
tools/building.py
)get_last_binaryen_opts()
function to include--fast-math
flag whenFAST_MATH
setting is enabled--fast-math
flag whenFAST_MATH = 0
How It Works
-ffast-math
: Normal behavior, no--fast-math
flag passed to wasm-opt-ffast-math
: SetsFAST_MATH = 1
, causing wasm-opt to receive--fast-math
flag-Ofast
: Automatically enables fast math optimizations (standard behavior)