[wasi] Enable PackedSimd intrinsics and ILLink substitutions#129051
Closed
lewing wants to merge 1 commit into
Closed
[wasi] Enable PackedSimd intrinsics and ILLink substitutions#129051lewing wants to merge 1 commit into
lewing wants to merge 1 commit into
Conversation
The mono interpreter only emitted wasm packed-simd intrinsic opcodes when HOST_BROWSER was defined. On WASI the interpreter returned FALSE for every PackedSimd method, so calls fell through to the C# method body which recursively calls itself, producing a stack overflow (observed with ConvertNarrowingSaturateUnsigned and other PackedSimd intrinsics). Additionally, WasiApp.targets did not inject the ILLink substitutions that fold PackedSimd.IsSupported to a constant, so even with WasmEnableSIMD=false the simd code paths survived trimming and the call sites still recursed. Changes: * src/mono/mono/mini/interp/interp-simd.h, interp-simd.c, interp-nosimd.c, transform-simd.c: extend the HOST_BROWSER gates around the wasm packed-simd intrinsic tables and emission to also cover HOST_WASI. The mono-wasm-simd static library is already built with -msimd128 for both hosts in cmake. * src/mono/wasi/build/WasiApp.targets: add _ExtraTrimmerArgs for the WasmIntrinsics.xml / NoWasmIntrinsics.xml substitutions, mirroring BrowserWasmApp.targets, and uncomment the -msimd128 clang flag when WasmEnableSIMD=true. * src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/ Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk.pkgproj: package the two ILLink.Substitutions.*.xml files next to WasiApp.targets in the WASI SDK so $(MSBuildThisFileDirectory) resolves at app build time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @vitek-karas, @BrzVlad, @kotlarmilos |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Mono WASI toolchain and interpreter so System.Runtime.Intrinsics.Wasm.PackedSimd intrinsics can be substituted/trimmed correctly on WASI (matching existing browser-WASM behavior), avoiding falling back to the managed recursive implementations.
Changes:
- Enable interpreter-side PackedSimd intrinsic emission on WASI by extending existing
HOST_BROWSERgates to also includeHOST_WASI. - Add ILLink substitution XMLs to the WASI SDK pack and pass the appropriate
--substitutionsfile based onWasmEnableSIMD. - Enable
-msimd128for the WASI clang toolchain whenWasmEnableSIMD=true.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/mono/wasi/build/WasiApp.targets | Adds ILLink substitutions for Wasm intrinsics and enables -msimd128 for WASI builds when SIMD is on. |
| src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk/Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk.pkgproj | Packs the ILLink substitution XMLs into the WASI SDK so they can be consumed at app build time. |
| src/mono/mono/mini/interp/transform-simd.c | Extends PackedSimd emission gates from browser-only to browser-or-WASI. |
| src/mono/mono/mini/interp/interp-simd.h | Exposes wasm opcode tables for WASI builds alongside browser builds. |
| src/mono/mono/mini/interp/interp-simd.c | Enables wasm SIMD header inclusion and opcode table generation for WASI builds. |
| src/mono/mono/mini/interp/interp-nosimd.c | Provides empty fallback wasm opcode tables for WASI (parity with browser). |
This was referenced Jun 5, 2026
Open
lewing
added a commit
to lewing/runtime
that referenced
this pull request
Jun 6, 2026
…n XMLs The XML files only sit next to WasiApp.targets in the packaged WASI SDK. For in-tree builds they live under $(BrowserProjectRoot)build\, so detect the local file with Exists() and fall back to the browser build dir when absent. Addresses review feedback on PR dotnet#129051. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Note
This PR description was AI-generated with GitHub Copilot.
Problem
Calling
System.Runtime.Intrinsics.Wasm.PackedSimd.ConvertNarrowingSaturateUnsigned(and other PackedSimd intrinsics) in a WASI app crashes with a stack overflow, because the C# fallback for each intrinsic recursively calls itself when the runtime fails to substitute it.Two separate things contribute:
Changes
Interpreter (b): Extend the `HOST_BROWSER` gates to also cover `HOST_WASI` so the interpreter substitutes PackedSimd intrinsics on WASI. The `mono-wasm-simd` static library is already built with `-msimd128` for both hosts (`src/mono/mono/mini/CMakeLists.txt` line 484).
MSBuild / SDK (a, c):
Verification
Draft
Marked draft for review and to confirm there are no other WASI-only PackedSimd test gaps before un-drafting.