Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions site/source/docs/tools_reference/settings_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ defaults 1, absent any other settings:

Default value: 0

.. _fast_math:

FAST_MATH
=========

Enable fast math optimizations in wasm-opt when -ffast-math is passed.
This enables aggressive floating-point optimizations that may violate
IEEE 754 semantics but can improve performance.

Default value: 0

.. _check_null_writes:

CHECK_NULL_WRITES
Expand Down
6 changes: 6 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ var ASSERTIONS = 1;
// [link]
var STACK_OVERFLOW_CHECK = 0;

// Enable fast math optimizations in wasm-opt when -ffast-math is passed.
// This enables aggressive floating-point optimizations that may violate
// IEEE 754 semantics but can improve performance.
// [link]
var FAST_MATH = 0;
Copy link
Member

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.


// When STACK_OVERFLOW_CHECK is enabled we also check writes to address zero.
// This can help detect NULL pointer usage. If you want to skip this extra
// check (for example, if you want reads from the address zero to always return
Expand Down
5 changes: 4 additions & 1 deletion tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,12 @@ def minify_wasm_js(js_file, wasm_file, expensive_optimizations, debug_info):
# get the flags to pass into the very last binaryen tool invocation, that runs
# the final set of optimizations
def get_last_binaryen_opts():
return [f'--optimize-level={settings.OPT_LEVEL}',
opts = [f'--optimize-level={settings.OPT_LEVEL}',
f'--shrink-level={settings.SHRINK_LEVEL}',
'--optimize-stack-ir']
if settings.FAST_MATH:
opts.append('--fast-math')
return opts


# run binaryen's wasm-metadce to dce both js and wasm
Expand Down
7 changes: 4 additions & 3 deletions tools/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,8 @@ def consume_arg_file():
settings.SHRINK_LEVEL = 0
settings.DEBUG_LEVEL = max(settings.DEBUG_LEVEL, 1)
elif requested_level == 'fast':
# TODO(https://github.com/emscripten-core/emscripten/issues/21497):
# If we ever map `-ffast-math` to `wasm-opt --fast-math` then
# then we should enable that too here.
# -Ofast typically includes -ffast-math semantics, so enable fast math optimizations
settings.FAST_MATH = 1
requested_level = 3
settings.SHRINK_LEVEL = 0
else:
Expand Down Expand Up @@ -547,6 +546,8 @@ def consume_arg_file():
settings.WASM_EXCEPTIONS = 1
elif arg == '-fignore-exceptions':
settings.DISABLE_EXCEPTION_CATCHING = 1
elif arg == '-ffast-math':
settings.FAST_MATH = 1
elif check_arg('--default-obj-ext'):
exit_with_error('--default-obj-ext is no longer supported by emcc')
elif arg.startswith('-fsanitize=cfi'):
Expand Down