Skip to content

Commit 19c1c81

Browse files
Make wasm +sign-ext and +nontrapping-fptoint the default (#7995)
* Make wasm +sign-ext and +nontrapping-fptoint the default These have been supported in ~all wasm runtimes for a while now, and +nontrapping-fptoint in particular can make a big performance difference. We should enable these by default, and add a new backdoor (wasm_mvponly) for code paths that need to use the original wasm Minimum Viable Product spec only. * Update simd_op_check_wasm.cpp
1 parent 5aa891a commit 19c1c81

File tree

8 files changed

+20
-30
lines changed

8 files changed

+20
-30
lines changed

README_webassembly.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ backend.
66
As WebAssembly itself is still under active development, Halide's support has
77
some limitations. Some of the most important:
88

9+
- Sign-extension operations are enabled by default (but can be avoided via
10+
Target::WasmMvpOnly).
11+
- Non-trapping float-to-int conversions are enabled by default (but can be
12+
avoided via Target::WasmMvpOnly).
913
- Fixed-width SIMD (128 bit) can be enabled via Target::WasmSimd128.
10-
- Sign-extension operations can be enabled via Target::WasmSignExt.
11-
- Non-trapping float-to-int conversions can be enabled via
12-
Target::WasmSatFloatToInt.
1314
- Threads have very limited support via Target::WasmThreads; see
1415
[below](#using-threads) for more details.
1516
- Halide's JIT for Wasm is extremely limited and really useful only for
@@ -152,9 +153,8 @@ cmake -DLLVM_ENABLE_PROJECTS="clang;lld" ...
152153
```
153154
154155
- To run the JIT tests, set `HL_JIT_TARGET=wasm-32-wasmrt` (possibly adding
155-
`wasm_simd128`, `wasm_signext`, and/or `wasm_sat_float_to_int`) and run
156-
CMake/CTest normally. Note that wasm testing is only support under CMake
157-
(not via Make).
156+
`wasm_simd128`) and run CMake/CTest normally. Note that wasm testing is
157+
only supported under CMake (not via Make).
158158
159159
## Enabling wasm AOT
160160
@@ -165,9 +165,8 @@ will), you need to install Emscripten locally.
165165
(https://emscripten.org/docs/getting_started/downloads.html).
166166
167167
- To run the AOT tests, set `HL_TARGET=wasm-32-wasmrt` (possibly adding
168-
`wasm_simd128`, `wasm_signext`, and/or `wasm_sat_float_to_int`) and run
169-
CMake/CTest normally. Note that wasm testing is only support under CMake
170-
(not via Make).
168+
`wasm_simd128`) and run CMake/CTest normally. Note that wasm testing is
169+
only supported under CMake (not via Make).
171170
172171
# Running benchmarks
173172

python_bindings/src/halide/halide_/PyEnums.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,8 @@ void define_enums(py::module &m) {
165165
.value("HexagonDma", Target::Feature::HexagonDma)
166166
.value("EmbedBitcode", Target::Feature::EmbedBitcode)
167167
.value("EnableLLVMLoopOpt", Target::Feature::EnableLLVMLoopOpt)
168+
.value("WasmMvpOnly", Target::Feature::WasmMvpOnly)
168169
.value("WasmSimd128", Target::Feature::WasmSimd128)
169-
.value("WasmSignExt", Target::Feature::WasmSignExt)
170-
.value("WasmSatFloatToInt", Target::Feature::WasmSatFloatToInt)
171170
.value("WasmThreads", Target::Feature::WasmThreads)
172171
.value("WasmBulkMemory", Target::Feature::WasmBulkMemory)
173172
.value("SVE", Target::Feature::SVE)

src/CodeGen_WebAssembly.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,21 +333,17 @@ string CodeGen_WebAssembly::mattrs() const {
333333
std::ostringstream s;
334334
string sep;
335335

336-
if (target.has_feature(Target::WasmSignExt)) {
336+
if (!target.has_feature(Target::WasmMvpOnly)) {
337337
s << sep << "+sign-ext";
338338
sep = ",";
339+
s << sep << "+nontrapping-fptoint";
339340
}
340341

341342
if (target.has_feature(Target::WasmSimd128)) {
342343
s << sep << "+simd128";
343344
sep = ",";
344345
}
345346

346-
if (target.has_feature(Target::WasmSatFloatToInt)) {
347-
s << sep << "+nontrapping-fptoint";
348-
sep = ",";
349-
}
350-
351347
if (target.has_feature(Target::WasmThreads)) {
352348
// "WasmThreads" doesn't directly affect LLVM codegen,
353349
// but it does end up requiring atomics, so be sure to enable them.

src/Target.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,7 @@ const std::map<std::string, Target::Feature> feature_name_map = {
533533
{"embed_bitcode", Target::EmbedBitcode},
534534
{"enable_llvm_loop_opt", Target::EnableLLVMLoopOpt},
535535
{"wasm_simd128", Target::WasmSimd128},
536-
{"wasm_signext", Target::WasmSignExt},
537-
{"wasm_sat_float_to_int", Target::WasmSatFloatToInt},
536+
{"wasm_mvponly", Target::WasmMvpOnly},
538537
{"wasm_threads", Target::WasmThreads},
539538
{"wasm_bulk_memory", Target::WasmBulkMemory},
540539
{"webgpu", Target::WebGPU},

src/Target.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ struct Target {
143143
CheckUnsafePromises = halide_target_feature_check_unsafe_promises,
144144
EmbedBitcode = halide_target_feature_embed_bitcode,
145145
EnableLLVMLoopOpt = halide_target_feature_enable_llvm_loop_opt,
146+
WasmMvpOnly = halide_target_feature_wasm_mvponly,
146147
WasmSimd128 = halide_target_feature_wasm_simd128,
147-
WasmSignExt = halide_target_feature_wasm_signext,
148-
WasmSatFloatToInt = halide_target_feature_wasm_sat_float_to_int,
149148
WasmThreads = halide_target_feature_wasm_threads,
150149
WasmBulkMemory = halide_target_feature_wasm_bulk_memory,
151150
WebGPU = halide_target_feature_webgpu,

src/WasmExecutor.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,15 +1308,13 @@ wabt::interp::HostFunc::Ptr make_extern_callback(wabt::interp::Store &store,
13081308

13091309
wabt::Features calc_features(const Target &target) {
13101310
wabt::Features f;
1311-
if (target.has_feature(Target::WasmSignExt)) {
1311+
if (!target.has_feature(Target::WasmMvpOnly)) {
13121312
f.enable_sign_extension();
1313+
f.enable_sat_float_to_int();
13131314
}
13141315
if (target.has_feature(Target::WasmSimd128)) {
13151316
f.enable_simd();
13161317
}
1317-
if (target.has_feature(Target::WasmSatFloatToInt)) {
1318-
f.enable_sat_float_to_int();
1319-
}
13201318
return f;
13211319
}
13221320
#endif // WITH_WABT

src/runtime/HalideRuntime.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,9 +1386,8 @@ typedef enum halide_target_feature_t {
13861386
halide_target_feature_hexagon_dma, ///< Enable Hexagon DMA buffers.
13871387
halide_target_feature_embed_bitcode, ///< Emulate clang -fembed-bitcode flag.
13881388
halide_target_feature_enable_llvm_loop_opt, ///< Enable loop vectorization + unrolling in LLVM. Overrides halide_target_feature_disable_llvm_loop_opt. (Ignored for non-LLVM targets.)
1389+
halide_target_feature_wasm_mvponly, ///< Disable all extensions to WebAssembly codegen (including +sign-ext and +nontrapping-fptoint, which are on by default).
13891390
halide_target_feature_wasm_simd128, ///< Enable +simd128 instructions for WebAssembly codegen.
1390-
halide_target_feature_wasm_signext, ///< Enable +sign-ext instructions for WebAssembly codegen.
1391-
halide_target_feature_wasm_sat_float_to_int, ///< Enable saturating (nontrapping) float-to-int instructions for WebAssembly codegen.
13921391
halide_target_feature_wasm_threads, ///< Enable use of threads in WebAssembly codegen. Requires the use of a wasm runtime that provides pthread-compatible wrappers (typically, Emscripten with the -pthreads flag). Unsupported under WASI.
13931392
halide_target_feature_wasm_bulk_memory, ///< Enable +bulk-memory instructions for WebAssembly codegen.
13941393
halide_target_feature_webgpu, ///< Enable the WebGPU runtime.

test/correctness/simd_op_check_wasm.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class SimdOpCheckWASM : public SimdOpCheckTest {
1616
SimdOpCheckWASM(Target t, int w = 768, int h = 128)
1717
: SimdOpCheckTest(t, w, h) {
1818
use_wasm_simd128 = target.has_feature(Target::WasmSimd128);
19-
use_wasm_sat_float_to_int = target.has_feature(Target::WasmSatFloatToInt);
20-
use_wasm_sign_ext = target.has_feature(Target::WasmSignExt);
19+
use_wasm_sign_ext = !target.has_feature(Target::WasmMvpOnly);
20+
use_wasm_sat_float_to_int = !target.has_feature(Target::WasmMvpOnly);
2121
}
2222

2323
void add_tests() override {
@@ -544,6 +544,7 @@ int main(int argc, char **argv) {
544544
argc, argv,
545545
{
546546
Target("wasm-32-wasmrt"),
547-
Target("wasm-32-wasmrt-wasm_simd128-wasm_sat_float_to_int"),
547+
Target("wasm-32-wasmrt-wasm_simd128"),
548+
Target("wasm-32-wasmrt-wasm_mvponly"),
548549
});
549550
}

0 commit comments

Comments
 (0)