From 405910799f19f2b83b73b62074dcc62c9c8c84ec Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 6 Nov 2026 14:54:25 -0600 Subject: [PATCH 01/18] [wasi][coreclr] Enable WasmEnableRelaxedSimd by default on CoreCLR WASI - WasiApp.CoreCLR.targets: default WasmEnableRelaxedSimd=true; when on, pass --instruction-set:relaxed-simd to crossgen2 and set the System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported runtime property. - wasihost and corerun (wasm): enable the RelaxedSimd instruction set when that property is true, as browserhost does. - src/tests: apply WasmEnableRelaxedSimd to crossgen2 and corerun for browser and WASI (default on for WASI), and forward it from build.proj to test projects. Previously /p:WasmEnableRelaxedSimd=true on the hardware-intrinsics-wasm lane reached neither, so RelaxedSimd.IsSupported stayed false. - Add a RelaxedSimd test asserting IsSupported matches the host property under R2R. - Add a wasi_wasm leg to hardware-intrinsics-wasm. - Document the WASI default and trade-offs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/workflow/building/coreclr/wasi-r2r.md | 10 ++++++++++ eng/pipelines/coreclr/hardware-intrinsics-wasm.yml | 10 ++++++++++ .../templates/jit-hardware-intrinsics-wasm.yml | 4 ++++ eng/testing/tests.wasi.targets | 6 ++++++ src/coreclr/hosts/corerun/corerun.cpp | 14 ++++++++++++++ src/mono/wasi/build/WasiApp.CoreCLR.targets | 10 ++++++++++ src/native/corehost/wasihost/wasihost.cpp | 14 ++++++++++++++ src/tests/Directory.Build.targets | 12 ++++++++++++ .../Wasm/RelaxedSimd/RelaxedSimdTests.cs | 11 +++++++++++ src/tests/build.proj | 1 + 10 files changed, 92 insertions(+) diff --git a/docs/workflow/building/coreclr/wasi-r2r.md b/docs/workflow/building/coreclr/wasi-r2r.md index d1dedfe6d4c178..e0ec6726fabb7d 100644 --- a/docs/workflow/building/coreclr/wasi-r2r.md +++ b/docs/workflow/building/coreclr/wasi-r2r.md @@ -40,6 +40,16 @@ of the number of function definitions; table slots may contain duplicate or non- references. Non-composite R2R and `WasmSingleFileBundle` are not supported by this path. +### Relaxed SIMD + +`WasmEnableRelaxedSimd` defaults to `true` for CoreCLR-WASI (browser defaults to `false`). It compiles +ReadyToRun code with Crossgen2's `--instruction-set:relaxed-simd` and sets the +`System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported` runtime property, which the host uses to enable +`RelaxedSimd.IsSupported`. WASI has no runtime feature detection, so a host without relaxed SIMD (for +example wasmtime with `-W relaxed-simd=n`) fails to compile the module; publish with +`-p:WasmEnableRelaxedSimd=false` for such hosts. Relaxed SIMD results may differ between hosts and CPUs. +Interpreted code always reports `RelaxedSimd.IsSupported` as `false`. + ## Runtime tests The WASI runtime-test pipeline keeps separate interpreter and `R2R_CG2` jobs. The R2R job uses diff --git a/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml b/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml index ef75d2e19f9bcb..34529c6a998b62 100644 --- a/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml +++ b/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml @@ -11,6 +11,9 @@ pr: - eng/pipelines/coreclr/hardware-intrinsics-wasm.yml - eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml - src/coreclr/jit/*wasm* + - src/coreclr/hosts/corerun/** + - src/tests/Directory.Build.targets + - src/tests/build.proj - src/tests/JIT/HardwareIntrinsics/Wasm/** variables: @@ -29,3 +32,10 @@ extends: platforms: - browser_wasm testBuildArgs: '/p:WasmEnableRelaxedSimd=true -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_r.csproj -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_ro.csproj' + # WASI loads ReadyToRun code from a single composite. Relaxed SIMD is on by default for CoreCLR WASI. + - template: /eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml + parameters: + platforms: + - wasi_wasm + compositeBuildMode: true + testBuildArgs: '-test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_r.csproj -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_ro.csproj' diff --git a/eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml b/eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml index 0fb12ab24e3fa0..a5759da9b09f8b 100644 --- a/eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml +++ b/eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml @@ -3,6 +3,9 @@ parameters: type: object - name: testBuildArgs type: string + - name: compositeBuildMode + type: boolean + default: false jobs: # Build CoreCLR + libraries for wasm, build the wasm HardwareIntrinsics tests, @@ -32,6 +35,7 @@ jobs: testRunNamePrefixSuffix: CoreCLR_R2R # The CoreCLR interpreter does not implement Wasm SIMD; ReadyToRun code does. readyToRun: true + compositeBuildMode: ${{ parameters.compositeBuildMode }} extraVariablesTemplates: - template: /eng/pipelines/common/templates/runtimes/test-variables.yml parameters: diff --git a/eng/testing/tests.wasi.targets b/eng/testing/tests.wasi.targets index bcc314bc7724ef..80bcaaaee0de80 100644 --- a/eng/testing/tests.wasi.targets +++ b/eng/testing/tests.wasi.targets @@ -1,4 +1,10 @@ + + + true + + diff --git a/src/coreclr/hosts/corerun/corerun.cpp b/src/coreclr/hosts/corerun/corerun.cpp index 0f3e7b1ede16da..1fe7535df98c03 100644 --- a/src/coreclr/hosts/corerun/corerun.cpp +++ b/src/coreclr/hosts/corerun/corerun.cpp @@ -11,6 +11,8 @@ #ifdef TARGET_WASM #include + +extern "C" void coreclr_wasm_set_relaxed_simd_supported(); #endif // TARGET_WASM #ifdef TARGET_BROWSER @@ -728,6 +730,18 @@ static int run(const configuration& config) #ifdef TARGET_WASM // install the pinvoke override callback to resolve p/invokes to statically linked libraries add_pinvoke_override(); + + // Wasm has no runtime feature detection; the test opts in through this property, as the app hosts do. + for (size_t i = 0; i < config.user_defined_keys.size(); ++i) + { + if (config.user_defined_keys[i] == W("System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported")) + { + if (config.user_defined_values[i] == W("true")) + coreclr_wasm_set_relaxed_simd_supported(); + + break; + } + } #endif // TARGET_WASM int result; diff --git a/src/mono/wasi/build/WasiApp.CoreCLR.targets b/src/mono/wasi/build/WasiApp.CoreCLR.targets index 9d54ea1733bb72..fadac26b1b1637 100644 --- a/src/mono/wasi/build/WasiApp.CoreCLR.targets +++ b/src/mono/wasi/build/WasiApp.CoreCLR.targets @@ -72,12 +72,22 @@ wasihost corehost (libWasiHost.a) per-app through its own targets below. --> false false + + true + + + + wasm true $(PublishReadyToRunCrossgen2ExtraArgs);--opt-cross-module:* + $(PublishReadyToRunCrossgen2ExtraArgs);--instruction-set:relaxed-simd true diff --git a/src/native/corehost/wasihost/wasihost.cpp b/src/native/corehost/wasihost/wasihost.cpp index 2129b1290babd3..8c7cae65b594a0 100644 --- a/src/native/corehost/wasihost/wasihost.cpp +++ b/src/native/corehost/wasihost/wasihost.cpp @@ -72,6 +72,8 @@ extern "C" int* latchedExitCode); int coreclr_set_error_writer(void (*errorWriter)(const char* line)); + + void coreclr_wasm_set_relaxed_simd_supported(); } // App-generated P/Invoke resolver (per-app, replaces libcoreclr_gen_static.a at the relink), passed @@ -380,6 +382,18 @@ int main(int argc, char* argv[]) if (!add_runtimeconfig_properties(runtimeconfig_path)) return -1; + // WASI has no runtime feature detection; the app opts in (WasmEnableRelaxedSimd) through this property. + for (size_t i = 0; i < s_property_keys.size(); ++i) + { + if (s_property_keys[i] == "System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported") + { + if (s_property_values[i] == "true") + coreclr_wasm_set_relaxed_simd_supported(); + + break; + } + } + std::vector property_keys; std::vector property_values; for (const std::string& key : s_property_keys) diff --git a/src/tests/Directory.Build.targets b/src/tests/Directory.Build.targets index e5c06c0c5928b4..3986cbbc05e2fa 100644 --- a/src/tests/Directory.Build.targets +++ b/src/tests/Directory.Build.targets @@ -293,6 +293,18 @@ native code need a corerun with that code linked in. --> + + + + true + + + $(CrossGen2TestExtraArguments) --instruction-set:relaxed-simd + + + + Environment.GetEnvironmentVariable("TEST_READY_TO_RUN_MODE") == "1"; + + // ReadyToRun code compiled for relaxed SIMD is rejected unless the host enables the instruction set, + // so a host that ignores the WasmEnableRelaxedSimd setting silently reports IsSupported == false. + [ConditionalFact(typeof(RelaxedSimdTests), nameof(IsReadyToRun))] + public static void IsSupportedMatchesHostConfiguration() + { + bool expected = AppContext.TryGetSwitch("System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported", out bool isEnabled) && isEnabled; + Assert.Equal(expected, RelaxedSimd.IsSupported); + } + [ConditionalFact(typeof(RelaxedSimdTests), nameof(IsNotSupported))] public static void UnsupportedMethodThrowsPlatformNotSupportedException() { diff --git a/src/tests/build.proj b/src/tests/build.proj index 73b8f080878a47..522d5a7202e4ae 100644 --- a/src/tests/build.proj +++ b/src/tests/build.proj @@ -258,6 +258,7 @@ $(GroupBuildCmd) /p:ContinuousIntegrationBuild=true $(GroupBuildCmd) "/p:BuildTestsOnHelix=true" $(GroupBuildCmd) "/p:MonoForceInterpreter=true" + $(GroupBuildCmd) "/p:WasmEnableRelaxedSimd=$(WasmEnableRelaxedSimd)" $(GroupBuildCmd) "/p:RunAOTCompilation=true" $(GroupBuildCmd) "/p:DevTeamProvisioning=$(DevTeamProvisioning)" From 0c785030944a5a04e129c05070ab7f6b4706b820 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 6 Nov 2026 14:57:41 -0600 Subject: [PATCH 02/18] Quarantine WASI R2R tests that depend on R2R CoreLib against #134949 PackedSimdIsSupported, RelaxedSimdIsSupportedReflects and LoadStoreNullCheckTest call into CoreLib at run time, which is interpreted in WASI ReadyToRun test composites. Skip them only when IsWasi && IsReadyToRunCompiled; they still run in the WASI interpreter lane and on browser. Use the shared IsWasmReadyToRun predicate for IsSupportedMatchesHostConfiguration. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../HardwareIntrinsics/Wasm/PackedSimd/PackedSimdTests.cs | 2 ++ .../HardwareIntrinsics/Wasm/RelaxedSimd/RelaxedSimdTests.cs | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tests/JIT/HardwareIntrinsics/Wasm/PackedSimd/PackedSimdTests.cs b/src/tests/JIT/HardwareIntrinsics/Wasm/PackedSimd/PackedSimdTests.cs index b87dff9fb29286..5eca0fd9584b63 100644 --- a/src/tests/JIT/HardwareIntrinsics/Wasm/PackedSimd/PackedSimdTests.cs +++ b/src/tests/JIT/HardwareIntrinsics/Wasm/PackedSimd/PackedSimdTests.cs @@ -13,6 +13,7 @@ public sealed class PackedSimdTests { [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/134949", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsWasi), nameof(TestLibrary.PlatformDetection.IsReadyToRunCompiled))] [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(PackedSimd))] public static unsafe void PackedSimdIsSupported() { @@ -1259,6 +1260,7 @@ public static unsafe void LoadScalarAndSplatTest() } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/134949", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsWasi), nameof(TestLibrary.PlatformDetection.IsReadyToRunCompiled))] public static unsafe void LoadStoreNullCheckTest() { if (!PackedSimd.IsSupported) diff --git a/src/tests/JIT/HardwareIntrinsics/Wasm/RelaxedSimd/RelaxedSimdTests.cs b/src/tests/JIT/HardwareIntrinsics/Wasm/RelaxedSimd/RelaxedSimdTests.cs index 6077d10e43ff1b..14c9421183e089 100644 --- a/src/tests/JIT/HardwareIntrinsics/Wasm/RelaxedSimd/RelaxedSimdTests.cs +++ b/src/tests/JIT/HardwareIntrinsics/Wasm/RelaxedSimd/RelaxedSimdTests.cs @@ -12,6 +12,7 @@ public sealed class RelaxedSimdTests public static bool IsNotSupported => !RelaxedSimd.IsSupported; [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/134949", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsWasi), nameof(TestLibrary.PlatformDetection.IsReadyToRunCompiled))] public static void RelaxedSimdIsSupportedReflects() { MethodInfo? methodInfo = typeof(RelaxedSimd).GetMethod("get_IsSupported"); @@ -19,11 +20,9 @@ public static void RelaxedSimdIsSupportedReflects() Assert.Equal(RelaxedSimd.IsSupported, methodInfo.Invoke(null, null)); } - public static bool IsReadyToRun => Environment.GetEnvironmentVariable("TEST_READY_TO_RUN_MODE") == "1"; - // ReadyToRun code compiled for relaxed SIMD is rejected unless the host enables the instruction set, // so a host that ignores the WasmEnableRelaxedSimd setting silently reports IsSupported == false. - [ConditionalFact(typeof(RelaxedSimdTests), nameof(IsReadyToRun))] + [ConditionalFact(typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsWasmReadyToRun))] public static void IsSupportedMatchesHostConfiguration() { bool expected = AppContext.TryGetSwitch("System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported", out bool isEnabled) && isEnabled; From 1190148bc9a067e3a2304c2e4d9044d1f7646b54 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 6 Nov 2026 15:12:49 -0600 Subject: [PATCH 03/18] Enable wasm relaxed SIMD from the crossgen2 instruction set alone Wasm has no runtime feature detection, so the runtime's CPU flags cannot confirm the instruction sets a ReadyToRun image requires. Previously hosts read a System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported runtime property and called an exported coreclr_wasm_set_relaxed_simd_supported() so the image-wide instruction set fixup would pass. The engine already validates the code when it compiles the module, so on wasm treat instruction sets an image requires as supported. Must-be-unsupported assertions are still checked against the runtime flags. This removes the exported setter, the browserhost/wasihost/corerun property handling, and the RuntimeHostConfigurationOption items; WasmEnableRelaxedSimd now only selects --instruction-set:relaxed-simd (and the browser emcc flags). PublishRelaxedSimdCoreClr now publishes ReadyToRun and checks RelaxedSimd.IsSupported instead of the removed runtime property. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/workflow/building/coreclr/wasi-r2r.md | 9 ++++----- .../coreclr/hardware-intrinsics-wasm.yml | 1 - src/coreclr/hosts/corerun/corerun.cpp | 14 -------------- src/coreclr/vm/codeman.cpp | 13 ------------- src/coreclr/vm/jitinterface.cpp | 8 ++++++++ .../build/BrowserWasmApp.CoreCLR.targets | 6 ------ ...ET.Sdk.WebAssembly.Browser.CoreCLR.targets | 6 ------ src/mono/wasi/build/WasiApp.CoreCLR.targets | 10 ++-------- .../wasm/Wasm.Build.Tests/WasmSIMDTests.cs | 19 ++++++++----------- .../corehost/browserhost/browserhost.cpp | 12 ------------ src/native/corehost/wasihost/wasihost.cpp | 14 -------------- src/tests/Directory.Build.targets | 7 ++----- .../Wasm/RelaxedSimd/RelaxedSimdTests.cs | 9 --------- 13 files changed, 24 insertions(+), 104 deletions(-) diff --git a/docs/workflow/building/coreclr/wasi-r2r.md b/docs/workflow/building/coreclr/wasi-r2r.md index e0ec6726fabb7d..7224b15e108942 100644 --- a/docs/workflow/building/coreclr/wasi-r2r.md +++ b/docs/workflow/building/coreclr/wasi-r2r.md @@ -43,11 +43,10 @@ Non-composite R2R and `WasmSingleFileBundle` are not supported by this path. ### Relaxed SIMD `WasmEnableRelaxedSimd` defaults to `true` for CoreCLR-WASI (browser defaults to `false`). It compiles -ReadyToRun code with Crossgen2's `--instruction-set:relaxed-simd` and sets the -`System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported` runtime property, which the host uses to enable -`RelaxedSimd.IsSupported`. WASI has no runtime feature detection, so a host without relaxed SIMD (for -example wasmtime with `-W relaxed-simd=n`) fails to compile the module; publish with -`-p:WasmEnableRelaxedSimd=false` for such hosts. Relaxed SIMD results may differ between hosts and CPUs. +ReadyToRun code with Crossgen2's `--instruction-set:relaxed-simd`, so `RelaxedSimd.IsSupported` is `true` in +that code. Wasm has no runtime feature detection; the runtime accepts the instruction sets an image requires +because the engine validated the module. A host without relaxed SIMD (for example wasmtime with +`-W relaxed-simd=n`) fails to compile the module; publish with `-p:WasmEnableRelaxedSimd=false` for such hosts. Relaxed SIMD results may differ between hosts and CPUs. Interpreted code always reports `RelaxedSimd.IsSupported` as `false`. ## Runtime tests diff --git a/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml b/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml index 34529c6a998b62..b330b8b54cb6eb 100644 --- a/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml +++ b/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml @@ -11,7 +11,6 @@ pr: - eng/pipelines/coreclr/hardware-intrinsics-wasm.yml - eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml - src/coreclr/jit/*wasm* - - src/coreclr/hosts/corerun/** - src/tests/Directory.Build.targets - src/tests/build.proj - src/tests/JIT/HardwareIntrinsics/Wasm/** diff --git a/src/coreclr/hosts/corerun/corerun.cpp b/src/coreclr/hosts/corerun/corerun.cpp index 1fe7535df98c03..0f3e7b1ede16da 100644 --- a/src/coreclr/hosts/corerun/corerun.cpp +++ b/src/coreclr/hosts/corerun/corerun.cpp @@ -11,8 +11,6 @@ #ifdef TARGET_WASM #include - -extern "C" void coreclr_wasm_set_relaxed_simd_supported(); #endif // TARGET_WASM #ifdef TARGET_BROWSER @@ -730,18 +728,6 @@ static int run(const configuration& config) #ifdef TARGET_WASM // install the pinvoke override callback to resolve p/invokes to statically linked libraries add_pinvoke_override(); - - // Wasm has no runtime feature detection; the test opts in through this property, as the app hosts do. - for (size_t i = 0; i < config.user_defined_keys.size(); ++i) - { - if (config.user_defined_keys[i] == W("System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported")) - { - if (config.user_defined_values[i] == W("true")) - coreclr_wasm_set_relaxed_simd_supported(); - - break; - } - } #endif // TARGET_WASM int result; diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index d39630b18edf0f..1fb272e66eab96 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -1457,15 +1457,6 @@ extern "C" DWORD64 __stdcall GetDataCacheZeroIDReg(); extern "C" uint64_t GetSveLengthFromOS(); #endif -#ifdef TARGET_WASM -static bool s_wasmRelaxedSimdSupported; - -extern "C" void coreclr_wasm_set_relaxed_simd_supported() -{ - s_wasmRelaxedSimdSupported = true; -} -#endif - void EEJitManager::SetCpuInfo() { LIMITED_METHOD_CONTRACT; @@ -1510,10 +1501,6 @@ void EEJitManager::SetCpuInfo() #if defined(TARGET_WASM) CPUCompileFlags.Set(InstructionSet_WasmBase); CPUCompileFlags.Set(InstructionSet_PackedSimd); - if (s_wasmRelaxedSimdSupported) - { - CPUCompileFlags.Set(InstructionSet_RelaxedSimd); - } #endif #if defined(TARGET_X86) || defined(TARGET_AMD64) diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index c4b8c0418e0ba8..ce573203237ec4 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -14638,6 +14638,14 @@ BOOL LoadDynamicInfoEntry(Module *currentModule, DWORD instructionSetEncoded = CorSigUncompressData(pBlob); bool mustInstructionSetBeSupported = !!(instructionSetEncoded & 1); ReadyToRunInstructionSet instructionSet = (ReadyToRunInstructionSet)(instructionSetEncoded >> 1); +#ifdef TARGET_WASM + // Wasm has no runtime feature detection. The engine validated this code when it compiled the + // module, so an instruction set the code requires is supported by construction. + if (mustInstructionSetBeSupported) + { + continue; + } +#endif // TARGET_WASM if (IsInstructionSetSupported(corjitFlags, instructionSet) != mustInstructionSetBeSupported) { return FALSE; diff --git a/src/mono/browser/build/BrowserWasmApp.CoreCLR.targets b/src/mono/browser/build/BrowserWasmApp.CoreCLR.targets index 8e7637785e9f8e..7ea2f43c2a90c3 100644 --- a/src/mono/browser/build/BrowserWasmApp.CoreCLR.targets +++ b/src/mono/browser/build/BrowserWasmApp.CoreCLR.targets @@ -74,12 +74,6 @@ <_ExeExt Condition="$([MSBuild]::IsOSPlatform('windows'))">.exe - - - - false false - + true - - - - wasm true diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs index ca7adc8662d386..495fc9f15d3f58 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs @@ -74,7 +74,8 @@ public async Task PublishRelaxedSimdCoreClr(bool relaxedSimd) { Configuration config = Configuration.Debug; string relaxedSimdValue = relaxedSimd.ToString().ToLowerInvariant(); - string extraProperties = $"{relaxedSimdValue}"; + // ReadyToRun code is what uses relaxed SIMD; the interpreter always reports it unsupported. + string extraProperties = $"{relaxedSimdValue}true"; ProjectInfo info = CopyTestAsset( config, aot: false, @@ -83,7 +84,7 @@ public async Task PublishRelaxedSimdCoreClr(bool relaxedSimd) extraProperties: extraProperties); UpdateFile( Path.Combine("Common", "Program.cs"), - GetCoreClrRelaxedSimdProgramText(relaxedSimdValue)); + s_coreClrRelaxedSimdProgramText); ReplaceMainJsWithMinimalRunMain(); PublishProject(info, config, isNativeBuild: relaxedSimd); @@ -92,24 +93,20 @@ public async Task PublishRelaxedSimdCoreClr(bool relaxedSimd) config, TestScenario: "DotnetRun", ExpectedExitCode: 42)); - string expectedOutput = $"RelaxedSimd config: {(relaxedSimd ? "true" : "")}"; + string expectedOutput = $"RelaxedSimd.IsSupported: {relaxedSimd}"; Assert.Contains(result.TestOutput, message => message.Contains(expectedOutput)); } - private static string GetCoreClrRelaxedSimdProgramText(string expectedConfigValue) => $$""" + private static string s_coreClrRelaxedSimdProgramText = """ using System; + using System.Runtime.Intrinsics.Wasm; public class TestClass { public static int Main() { - string configuredValue = AppContext.GetData( - "System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported") as string; - Console.WriteLine($"TestOutput -> RelaxedSimd config: {configuredValue ?? ""}"); - - return configuredValue == {{(expectedConfigValue == "true" ? "\"true\"" : "null")}} - ? 42 - : 1; + Console.WriteLine($"TestOutput -> RelaxedSimd.IsSupported: {RelaxedSimd.IsSupported}"); + return 42; } } """; diff --git a/src/native/corehost/browserhost/browserhost.cpp b/src/native/corehost/browserhost/browserhost.cpp index b3aefce8d6e2ed..e687913cce4913 100644 --- a/src/native/corehost/browserhost/browserhost.cpp +++ b/src/native/corehost/browserhost/browserhost.cpp @@ -44,8 +44,6 @@ extern "C" pal::hresult_t coreclr_set_error_writer( coreclr_error_writer_callback_fn error_writer); - void coreclr_wasm_set_relaxed_simd_supported(); - #if !GEN_PINVOKE const void* SystemResolveDllImport(const char* name); const void* SystemJSResolveDllImport(const char* name); @@ -112,16 +110,6 @@ extern "C" void* BrowserHost_CreateHostContract(void) extern "C" int BrowserHost_InitializeDotnet(int propertiesCount, const char** propertyKeys, const char** propertyValues) { - for (int i = 0; i < propertiesCount; i++) - { - if ((strcmp(propertyKeys[i], "System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported") == 0) && - (strcmp(propertyValues[i], "true") == 0)) - { - coreclr_wasm_set_relaxed_simd_supported(); - break; - } - } - coreclr_set_error_writer(log_error_info); int retval = coreclr_initialize("/managed", "corehost", propertiesCount, propertyKeys, propertyValues, &CurrentClrInstance, &CurrentAppDomainId); diff --git a/src/native/corehost/wasihost/wasihost.cpp b/src/native/corehost/wasihost/wasihost.cpp index 8c7cae65b594a0..2129b1290babd3 100644 --- a/src/native/corehost/wasihost/wasihost.cpp +++ b/src/native/corehost/wasihost/wasihost.cpp @@ -72,8 +72,6 @@ extern "C" int* latchedExitCode); int coreclr_set_error_writer(void (*errorWriter)(const char* line)); - - void coreclr_wasm_set_relaxed_simd_supported(); } // App-generated P/Invoke resolver (per-app, replaces libcoreclr_gen_static.a at the relink), passed @@ -382,18 +380,6 @@ int main(int argc, char* argv[]) if (!add_runtimeconfig_properties(runtimeconfig_path)) return -1; - // WASI has no runtime feature detection; the app opts in (WasmEnableRelaxedSimd) through this property. - for (size_t i = 0; i < s_property_keys.size(); ++i) - { - if (s_property_keys[i] == "System.Runtime.Intrinsics.Wasm.RelaxedSimd.IsSupported") - { - if (s_property_values[i] == "true") - coreclr_wasm_set_relaxed_simd_supported(); - - break; - } - } - std::vector property_keys; std::vector property_values; for (const std::string& key : s_property_keys) diff --git a/src/tests/Directory.Build.targets b/src/tests/Directory.Build.targets index 3986cbbc05e2fa..b658bb69f74388 100644 --- a/src/tests/Directory.Build.targets +++ b/src/tests/Directory.Build.targets @@ -294,17 +294,14 @@ - + true $(CrossGen2TestExtraArguments) --instruction-set:relaxed-simd - - - Date: Fri, 6 Nov 2026 15:20:17 -0600 Subject: [PATCH 04/18] Clarify the WASI relaxed SIMD default comment Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- src/mono/wasi/build/WasiApp.CoreCLR.targets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/wasi/build/WasiApp.CoreCLR.targets b/src/mono/wasi/build/WasiApp.CoreCLR.targets index e4933f57952a4f..f9c8e6544733f6 100644 --- a/src/mono/wasi/build/WasiApp.CoreCLR.targets +++ b/src/mono/wasi/build/WasiApp.CoreCLR.targets @@ -72,8 +72,8 @@ wasihost corehost (libWasiHost.a) per-app through its own targets below. --> false false - + true From 8bffd8d5196f16d62352f596c2dddda748de8184 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 6 Nov 2026 16:18:04 -0600 Subject: [PATCH 05/18] Make PublishRelaxedSimdCoreClr exercise relaxed SIMD Run ConvertToInt32Native and MultiplyAddEstimate through NoInlining methods and check their results when relaxed SIMD is enabled, and check that the opt-out throws PlatformNotSupportedException, instead of only printing IsSupported. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../wasm/Wasm.Build.Tests/WasmSIMDTests.cs | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs index 495fc9f15d3f58..c1b41a64f7fcf3 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs @@ -93,12 +93,22 @@ public async Task PublishRelaxedSimdCoreClr(bool relaxedSimd) config, TestScenario: "DotnetRun", ExpectedExitCode: 42)); - string expectedOutput = $"RelaxedSimd.IsSupported: {relaxedSimd}"; - Assert.Contains(result.TestOutput, message => message.Contains(expectedOutput)); + Assert.Contains(result.TestOutput, m => m.Contains($"RelaxedSimd.IsSupported: {relaxedSimd}")); + if (relaxedSimd) + { + Assert.Contains(result.TestOutput, m => m.Contains("ConvertToInt32Native: <1, -2, 3, -4>")); + Assert.Contains(result.TestOutput, m => m.Contains("MultiplyAddEstimate: <7, 7, 7, 7>")); + } + else + { + Assert.Contains(result.TestOutput, m => m.Contains("ConvertToInt32Native: PlatformNotSupportedException")); + } } private static string s_coreClrRelaxedSimdProgramText = """ using System; + using System.Runtime.CompilerServices; + using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.Wasm; public class TestClass @@ -106,8 +116,29 @@ public class TestClass public static int Main() { Console.WriteLine($"TestOutput -> RelaxedSimd.IsSupported: {RelaxedSimd.IsSupported}"); + try + { + Console.WriteLine($"TestOutput -> ConvertToInt32Native: {ConvertToInt32Native(Vector128.Create(1.75f, -2.25f, 3.0f, -4.99f))}"); + } + catch (PlatformNotSupportedException) + { + Console.WriteLine("TestOutput -> ConvertToInt32Native: PlatformNotSupportedException"); + } + + if (RelaxedSimd.IsSupported) + { + Console.WriteLine($"TestOutput -> MultiplyAddEstimate: {MultiplyAddEstimate(Vector128.Create(2f), Vector128.Create(3f), Vector128.Create(1f))}"); + } + return 42; } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static Vector128 ConvertToInt32Native(Vector128 value) => RelaxedSimd.ConvertToInt32Native(value); + + [MethodImpl(MethodImplOptions.NoInlining)] + private static Vector128 MultiplyAddEstimate(Vector128 left, Vector128 right, Vector128 addend) => + RelaxedSimd.MultiplyAddEstimate(left, right, addend); } """; From 9fa237a60dd7c532c76c1cd21420f1161e108ff3 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 6 Nov 2026 16:29:03 -0600 Subject: [PATCH 06/18] Don't document interpreted RelaxedSimd.IsSupported as intended behavior IsSupported should be consistent across interpreted and compiled code; the mismatch is tracked by #134949. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/workflow/building/coreclr/wasi-r2r.md | 1 - src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/workflow/building/coreclr/wasi-r2r.md b/docs/workflow/building/coreclr/wasi-r2r.md index 7224b15e108942..6b1a64fbc990b7 100644 --- a/docs/workflow/building/coreclr/wasi-r2r.md +++ b/docs/workflow/building/coreclr/wasi-r2r.md @@ -47,7 +47,6 @@ ReadyToRun code with Crossgen2's `--instruction-set:relaxed-simd`, so `RelaxedSi that code. Wasm has no runtime feature detection; the runtime accepts the instruction sets an image requires because the engine validated the module. A host without relaxed SIMD (for example wasmtime with `-W relaxed-simd=n`) fails to compile the module; publish with `-p:WasmEnableRelaxedSimd=false` for such hosts. Relaxed SIMD results may differ between hosts and CPUs. -Interpreted code always reports `RelaxedSimd.IsSupported` as `false`. ## Runtime tests diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs index c1b41a64f7fcf3..43508b1dace7db 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs @@ -74,7 +74,7 @@ public async Task PublishRelaxedSimdCoreClr(bool relaxedSimd) { Configuration config = Configuration.Debug; string relaxedSimdValue = relaxedSimd.ToString().ToLowerInvariant(); - // ReadyToRun code is what uses relaxed SIMD; the interpreter always reports it unsupported. + // Relaxed SIMD is selected by the ReadyToRun compiler's instruction set. string extraProperties = $"{relaxedSimdValue}true"; ProjectInfo info = CopyTestAsset( config, From 20cf33080431ebadf5f9a1d3b116a95ceae23651 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 6 Nov 2026 16:34:40 -0600 Subject: [PATCH 07/18] Trim relaxed SIMD docs and comments Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/workflow/building/coreclr/wasi-r2r.md | 9 ++------- eng/pipelines/coreclr/hardware-intrinsics-wasm.yml | 1 - eng/testing/tests.wasi.targets | 3 +-- src/coreclr/vm/jitinterface.cpp | 3 +-- src/mono/wasi/build/WasiApp.CoreCLR.targets | 3 +-- src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs | 1 - src/tests/Directory.Build.targets | 3 +-- 7 files changed, 6 insertions(+), 17 deletions(-) diff --git a/docs/workflow/building/coreclr/wasi-r2r.md b/docs/workflow/building/coreclr/wasi-r2r.md index 6b1a64fbc990b7..0823a9c428dfb5 100644 --- a/docs/workflow/building/coreclr/wasi-r2r.md +++ b/docs/workflow/building/coreclr/wasi-r2r.md @@ -40,13 +40,8 @@ of the number of function definitions; table slots may contain duplicate or non- references. Non-composite R2R and `WasmSingleFileBundle` are not supported by this path. -### Relaxed SIMD - -`WasmEnableRelaxedSimd` defaults to `true` for CoreCLR-WASI (browser defaults to `false`). It compiles -ReadyToRun code with Crossgen2's `--instruction-set:relaxed-simd`, so `RelaxedSimd.IsSupported` is `true` in -that code. Wasm has no runtime feature detection; the runtime accepts the instruction sets an image requires -because the engine validated the module. A host without relaxed SIMD (for example wasmtime with -`-W relaxed-simd=n`) fails to compile the module; publish with `-p:WasmEnableRelaxedSimd=false` for such hosts. Relaxed SIMD results may differ between hosts and CPUs. +`WasmEnableRelaxedSimd` (default `true`) compiles the composite with relaxed SIMD. Hosts without relaxed SIMD +fail to load it; publish with `-p:WasmEnableRelaxedSimd=false` for them. ## Runtime tests diff --git a/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml b/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml index b330b8b54cb6eb..51061b8671af43 100644 --- a/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml +++ b/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml @@ -31,7 +31,6 @@ extends: platforms: - browser_wasm testBuildArgs: '/p:WasmEnableRelaxedSimd=true -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_r.csproj -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_ro.csproj' - # WASI loads ReadyToRun code from a single composite. Relaxed SIMD is on by default for CoreCLR WASI. - template: /eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml parameters: platforms: diff --git a/eng/testing/tests.wasi.targets b/eng/testing/tests.wasi.targets index 80bcaaaee0de80..c99ee5e274a0d9 100644 --- a/eng/testing/tests.wasi.targets +++ b/eng/testing/tests.wasi.targets @@ -1,6 +1,5 @@ - + true diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index ce573203237ec4..b2b3d817900196 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -14639,8 +14639,7 @@ BOOL LoadDynamicInfoEntry(Module *currentModule, bool mustInstructionSetBeSupported = !!(instructionSetEncoded & 1); ReadyToRunInstructionSet instructionSet = (ReadyToRunInstructionSet)(instructionSetEncoded >> 1); #ifdef TARGET_WASM - // Wasm has no runtime feature detection. The engine validated this code when it compiled the - // module, so an instruction set the code requires is supported by construction. + // The wasm engine validated the instructions when it compiled the module. if (mustInstructionSetBeSupported) { continue; diff --git a/src/mono/wasi/build/WasiApp.CoreCLR.targets b/src/mono/wasi/build/WasiApp.CoreCLR.targets index f9c8e6544733f6..b26735617f5806 100644 --- a/src/mono/wasi/build/WasiApp.CoreCLR.targets +++ b/src/mono/wasi/build/WasiApp.CoreCLR.targets @@ -72,8 +72,7 @@ wasihost corehost (libWasiHost.a) per-app through its own targets below. --> false false - + true diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs index 43508b1dace7db..c35f0f9a345923 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmSIMDTests.cs @@ -74,7 +74,6 @@ public async Task PublishRelaxedSimdCoreClr(bool relaxedSimd) { Configuration config = Configuration.Debug; string relaxedSimdValue = relaxedSimd.ToString().ToLowerInvariant(); - // Relaxed SIMD is selected by the ReadyToRun compiler's instruction set. string extraProperties = $"{relaxedSimdValue}true"; ProjectInfo info = CopyTestAsset( config, diff --git a/src/tests/Directory.Build.targets b/src/tests/Directory.Build.targets index b658bb69f74388..d4c6040f3af8bf 100644 --- a/src/tests/Directory.Build.targets +++ b/src/tests/Directory.Build.targets @@ -294,8 +294,7 @@ - + true From 03aa29da272d1046bd545dd685776f3f72e17937 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 6 Nov 2026 17:24:01 -0600 Subject: [PATCH 08/18] Compile CoreLib with relaxed SIMD in the browser HW-intrinsics leg The browser leg runs non-composite: CoreLib's R2R image is precompiled at build time while the tests are crossgen'd with --instruction-set:relaxed-simd, so the two images disagreed on RelaxedSimd.IsSupported. Let crossgen-corelib.proj add the instruction set when WasmEnableRelaxedSimd=true and pass it to the leg's runtime build. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- eng/pipelines/coreclr/hardware-intrinsics-wasm.yml | 2 ++ .../coreclr/templates/jit-hardware-intrinsics-wasm.yml | 5 ++++- src/coreclr/crossgen-corelib.proj | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml b/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml index 51061b8671af43..10f5ef8f5e300b 100644 --- a/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml +++ b/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml @@ -10,6 +10,7 @@ pr: include: - eng/pipelines/coreclr/hardware-intrinsics-wasm.yml - eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml + - src/coreclr/crossgen-corelib.proj - src/coreclr/jit/*wasm* - src/tests/Directory.Build.targets - src/tests/build.proj @@ -30,6 +31,7 @@ extends: parameters: platforms: - browser_wasm + extraBuildArgs: /p:WasmEnableRelaxedSimd=true testBuildArgs: '/p:WasmEnableRelaxedSimd=true -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_r.csproj -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_ro.csproj' - template: /eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml parameters: diff --git a/eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml b/eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml index a5759da9b09f8b..1e39547d2c672e 100644 --- a/eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml +++ b/eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml @@ -6,6 +6,9 @@ parameters: - name: compositeBuildMode type: boolean default: false + - name: extraBuildArgs + type: string + default: '' jobs: # Build CoreCLR + libraries for wasm, build the wasm HardwareIntrinsics tests, @@ -25,7 +28,7 @@ jobs: jobParameters: testGroup: outerloop nameSuffix: CoreCLR - buildArgs: -s clr+libs+packs -c $(_BuildConfig) /p:TestAssemblies=false + buildArgs: -s clr+libs+packs -c $(_BuildConfig) /p:TestAssemblies=false ${{ parameters.extraBuildArgs }} timeoutInMinutes: 180 postBuildSteps: - template: /eng/pipelines/common/templates/runtimes/build-runtime-tests-and-send-to-helix.yml diff --git a/src/coreclr/crossgen-corelib.proj b/src/coreclr/crossgen-corelib.proj index 9847370d584963..88263f8bb404a0 100644 --- a/src/coreclr/crossgen-corelib.proj +++ b/src/coreclr/crossgen-corelib.proj @@ -202,6 +202,9 @@ <_CoreLibCrossgen2ExtraArgs Include="--opt-cross-module:*" Condition="'$(PublishReadyToRunContainerFormat)' == 'wasm'" /> + + <_CoreLibCrossgen2ExtraArgs Include="--instruction-set:relaxed-simd" + Condition="'$(PublishReadyToRunContainerFormat)' == 'wasm' and '$(WasmEnableRelaxedSimd)' == 'true'" /> <_CoreLibCrossgen2ExtraArgs Include="@(WasmCoreClrFrameworkPInvokeModule->WithMetadataValue('Browser', 'true')->WithMetadataValue('PrebuiltR2RDirect', 'true')->'--directpinvoke:%(Identity)')" Condition="'$(PublishReadyToRunContainerFormat)' == 'wasm' and '$(TargetOS)' == 'browser'" /> <_CoreLibCrossgen2ExtraArgs Include="@(WasmCoreClrFrameworkPInvokeModule->WithMetadataValue('Wasi', 'true')->WithMetadataValue('PrebuiltR2RDirect', 'true')->'--directpinvoke:%(Identity)')" From 246d787e445105bd108fe378b922048d34c83406 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Sun, 8 Nov 2026 15:28:44 -0600 Subject: [PATCH 09/18] Make relaxed SIMD a WASI compiler default and validate images against CoreLib - InstructionSetHelpers adds relaxed-simd to the default WASI instruction sets, so crossgen2 and ILC callers no longer pass it. - Add PublishReadyToRunInstructionSet, the ReadyToRun counterpart of IlcInstructionSet, and drop the WASI WasmEnableRelaxedSimd plumbing. Opt out with PublishReadyToRunInstructionSet=-relaxed-simd. - On wasm the runtime takes its instruction sets from CoreLib's ReadyToRun image and validates other images against them, instead of skipping the check. - WASI src/tests ReadyToRun run with an interpreted CoreLib (#134949), so they default to -relaxed-simd. - Remove WasiEnableCompositeR2R; PublishReadyToRunComposite is already required, so the host's composite link flags follow PublishReadyToRun. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/workflow/building/coreclr/wasi-r2r.md | 4 ++-- .../coreclr/hardware-intrinsics-wasm.yml | 4 ++-- eng/testing/tests.wasi.targets | 4 ++-- src/coreclr/crossgen-corelib.proj | 6 +++--- src/coreclr/hosts/corerun/wasi_r2r_probe.hpp | 2 +- .../tools/Common/InstructionSetHelpers.cs | 5 +++++ src/coreclr/vm/codeman.h | 9 +++++++++ src/coreclr/vm/jitinterface.cpp | 6 ++++-- src/mono/wasi/build/WasiApp.CoreCLR.targets | 18 ++++-------------- .../Microsoft.NET.CrossGen.targets | 3 +++ src/tests/Directory.Build.targets | 9 +++++---- .../Wasm/RelaxedSimd/RelaxedSimdTests.cs | 1 - src/tests/build.proj | 2 +- 13 files changed, 41 insertions(+), 32 deletions(-) diff --git a/docs/workflow/building/coreclr/wasi-r2r.md b/docs/workflow/building/coreclr/wasi-r2r.md index 0823a9c428dfb5..491a3b4812e6dc 100644 --- a/docs/workflow/building/coreclr/wasi-r2r.md +++ b/docs/workflow/building/coreclr/wasi-r2r.md @@ -40,8 +40,8 @@ of the number of function definitions; table slots may contain duplicate or non- references. Non-composite R2R and `WasmSingleFileBundle` are not supported by this path. -`WasmEnableRelaxedSimd` (default `true`) compiles the composite with relaxed SIMD. Hosts without relaxed SIMD -fail to load it; publish with `-p:WasmEnableRelaxedSimd=false` for them. +Relaxed SIMD is a default WASI instruction set. Hosts without relaxed SIMD fail to load the composite; publish with +`-p:PublishReadyToRunInstructionSet=-relaxed-simd` for them. ## Runtime tests diff --git a/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml b/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml index 10f5ef8f5e300b..56f01ba152bdab 100644 --- a/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml +++ b/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml @@ -31,8 +31,8 @@ extends: parameters: platforms: - browser_wasm - extraBuildArgs: /p:WasmEnableRelaxedSimd=true - testBuildArgs: '/p:WasmEnableRelaxedSimd=true -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_r.csproj -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_ro.csproj' + extraBuildArgs: /p:PublishReadyToRunInstructionSet=relaxed-simd + testBuildArgs: '/p:PublishReadyToRunInstructionSet=relaxed-simd -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_r.csproj -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_ro.csproj' - template: /eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml parameters: platforms: diff --git a/eng/testing/tests.wasi.targets b/eng/testing/tests.wasi.targets index c99ee5e274a0d9..1880b3be3ad947 100644 --- a/eng/testing/tests.wasi.targets +++ b/eng/testing/tests.wasi.targets @@ -1,7 +1,7 @@ - + - true + true diff --git a/src/coreclr/crossgen-corelib.proj b/src/coreclr/crossgen-corelib.proj index 88263f8bb404a0..6cbe4f272f4a8a 100644 --- a/src/coreclr/crossgen-corelib.proj +++ b/src/coreclr/crossgen-corelib.proj @@ -202,9 +202,9 @@ <_CoreLibCrossgen2ExtraArgs Include="--opt-cross-module:*" Condition="'$(PublishReadyToRunContainerFormat)' == 'wasm'" /> - - <_CoreLibCrossgen2ExtraArgs Include="--instruction-set:relaxed-simd" - Condition="'$(PublishReadyToRunContainerFormat)' == 'wasm' and '$(WasmEnableRelaxedSimd)' == 'true'" /> + + <_CoreLibCrossgen2ExtraArgs Include="--instruction-set:$(PublishReadyToRunInstructionSet)" + Condition="'$(PublishReadyToRunInstructionSet)' != ''" /> <_CoreLibCrossgen2ExtraArgs Include="@(WasmCoreClrFrameworkPInvokeModule->WithMetadataValue('Browser', 'true')->WithMetadataValue('PrebuiltR2RDirect', 'true')->'--directpinvoke:%(Identity)')" Condition="'$(PublishReadyToRunContainerFormat)' == 'wasm' and '$(TargetOS)' == 'browser'" /> <_CoreLibCrossgen2ExtraArgs Include="@(WasmCoreClrFrameworkPInvokeModule->WithMetadataValue('Wasi', 'true')->WithMetadataValue('PrebuiltR2RDirect', 'true')->'--directpinvoke:%(Identity)')" diff --git a/src/coreclr/hosts/corerun/wasi_r2r_probe.hpp b/src/coreclr/hosts/corerun/wasi_r2r_probe.hpp index 234400c741e29a..15d1236a86e29a 100644 --- a/src/coreclr/hosts/corerun/wasi_r2r_probe.hpp +++ b/src/coreclr/hosts/corerun/wasi_r2r_probe.hpp @@ -6,7 +6,7 @@ // calls out to it to obtain the composite R2R webcil image and the per-assembly stubs. // // The in-tree WASI R2R composer populates the image when publishing. The host must be linked with the -// flags that supply a composite's imports -- see WasiEnableCompositeR2R in WasiApp.CoreCLR.targets. +// flags that supply a composite's imports (see WasiApp.CoreCLR.targets). // Without them this probe compiles but can never be satisfied. // // Requires corerun.hpp to be included first (for pal::try_map_file_readonly). Include exactly once per diff --git a/src/coreclr/tools/Common/InstructionSetHelpers.cs b/src/coreclr/tools/Common/InstructionSetHelpers.cs index 9933e6a3b53e63..ad2a7e0a3a7db4 100644 --- a/src/coreclr/tools/Common/InstructionSetHelpers.cs +++ b/src/coreclr/tools/Common/InstructionSetHelpers.cs @@ -93,6 +93,11 @@ public static InstructionSetSupport ConfigureInstructionSetSupport(string instru { instructionSetSupportBuilder.AddSupportedInstructionSet("base"); instructionSetSupportBuilder.AddSupportedInstructionSet("simd128"); + + if (targetOS == TargetOS.Wasi) + { + instructionSetSupportBuilder.AddSupportedInstructionSet("relaxed-simd"); + } } bool throttleAvx512 = false; diff --git a/src/coreclr/vm/codeman.h b/src/coreclr/vm/codeman.h index 4a4d294f12fa7a..23520f0e22636f 100644 --- a/src/coreclr/vm/codeman.h +++ b/src/coreclr/vm/codeman.h @@ -2341,6 +2341,15 @@ class EEJitManager final : public EECodeGenManager return m_CPUCompileFlags; } +#if defined(TARGET_WASM) && !defined(DACCESS_COMPILE) + // Wasm cannot detect instruction sets at run time; CoreLib's ReadyToRun image defines them. + void SetInstructionSetFromCoreLib(CORINFO_InstructionSet instructionSet) + { + LIMITED_METHOD_CONTRACT; + m_CPUCompileFlags.Set(instructionSet); + } +#endif + #if defined(TARGET_ARM64) inline bool UseScalableVectorT() { diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index b2b3d817900196..97f148eb7595c2 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -14639,9 +14639,11 @@ BOOL LoadDynamicInfoEntry(Module *currentModule, bool mustInstructionSetBeSupported = !!(instructionSetEncoded & 1); ReadyToRunInstructionSet instructionSet = (ReadyToRunInstructionSet)(instructionSetEncoded >> 1); #ifdef TARGET_WASM - // The wasm engine validated the instructions when it compiled the module. - if (mustInstructionSetBeSupported) + // Other images must match the instruction sets CoreLib was compiled for. + if (mustInstructionSetBeSupported && currentModule->IsSystem()) { + ExecutionManager::GetEEJitManager()->SetInstructionSetFromCoreLib(InstructionSetFromR2RInstructionSet(instructionSet)); + corjitFlags = ExecutionManager::GetEEJitManager()->GetCPUCompileFlags(); continue; } #endif // TARGET_WASM diff --git a/src/mono/wasi/build/WasiApp.CoreCLR.targets b/src/mono/wasi/build/WasiApp.CoreCLR.targets index b26735617f5806..f72bbda657bf99 100644 --- a/src/mono/wasi/build/WasiApp.CoreCLR.targets +++ b/src/mono/wasi/build/WasiApp.CoreCLR.targets @@ -72,16 +72,12 @@ wasihost corehost (libWasiHost.a) per-app through its own targets below. --> false false - - true wasm true $(PublishReadyToRunCrossgen2ExtraArgs);--opt-cross-module:* - $(PublishReadyToRunCrossgen2ExtraArgs);--instruction-set:relaxed-simd - true false @@ -96,8 +92,6 @@ Text="PublishReadyToRunContainerFormat '$(PublishReadyToRunContainerFormat)' is not supported for CoreCLR wasi-wasm; only 'wasm' is supported." /> - <_WasiRelinkOutput>$(_WasiRelinkObjDir)corerun <_WasiPublishedHost>$(WasmAppDir)managed\corerun - - false @@ -453,10 +443,10 @@ - <_WasiRelinkLinkFlags Include="-Wl,--table-base=$(WasiCompositeR2RTableBase)" Condition="'$(WasiEnableCompositeR2R)' == 'true'" /> - <_WasiRelinkLinkFlags Include="-Wl,--export-table" Condition="'$(WasiEnableCompositeR2R)' == 'true'" /> - <_WasiRelinkLinkFlags Include="-Wl,--export=__stack_pointer" Condition="'$(WasiEnableCompositeR2R)' == 'true'" /> - <_WasiRelinkLinkFlags Include="-Wl,--export=__coreclr_wasm_rtlrestorecontext_tag" Condition="'$(WasiEnableCompositeR2R)' == 'true'" /> + <_WasiRelinkLinkFlags Include="-Wl,--table-base=$(WasiCompositeR2RTableBase)" Condition="'$(PublishReadyToRun)' == 'true'" /> + <_WasiRelinkLinkFlags Include="-Wl,--export-table" Condition="'$(PublishReadyToRun)' == 'true'" /> + <_WasiRelinkLinkFlags Include="-Wl,--export=__stack_pointer" Condition="'$(PublishReadyToRun)' == 'true'" /> + <_WasiRelinkLinkFlags Include="-Wl,--export=__coreclr_wasm_rtlrestorecontext_tag" Condition="'$(PublishReadyToRun)' == 'true'" /> <_WasiRelinkLinkFlags Include="-fwasm-exceptions" /> <_WasiRelinkLinkFlags Include="-mllvm" /> <_WasiRelinkLinkFlags Include="-wasm-use-legacy-eh=false" /> diff --git a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets index be51a722fc14ae..47500b8fe4d2c7 100644 --- a/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets +++ b/src/tasks/Crossgen2Tasks/Microsoft.NET.CrossGen.targets @@ -50,6 +50,9 @@ Copyright (c) .NET Foundation. All rights reserved. $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info $(PublishReadyToRunCrossgen2ExtraArgs);--strip-debug-info + + + $(PublishReadyToRunCrossgen2ExtraArgs);--instruction-set:$(PublishReadyToRunInstructionSet) + - true + -relaxed-simd - - $(CrossGen2TestExtraArguments) --instruction-set:relaxed-simd + + $(CrossGen2TestExtraArguments) --instruction-set:$(PublishReadyToRunInstructionSet) !RelaxedSimd.IsSupported; [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/134949", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsWasi), nameof(TestLibrary.PlatformDetection.IsReadyToRunCompiled))] public static void RelaxedSimdIsSupportedReflects() { MethodInfo? methodInfo = typeof(RelaxedSimd).GetMethod("get_IsSupported"); diff --git a/src/tests/build.proj b/src/tests/build.proj index 522d5a7202e4ae..fedf0235f0fa8e 100644 --- a/src/tests/build.proj +++ b/src/tests/build.proj @@ -258,7 +258,7 @@ $(GroupBuildCmd) /p:ContinuousIntegrationBuild=true $(GroupBuildCmd) "/p:BuildTestsOnHelix=true" $(GroupBuildCmd) "/p:MonoForceInterpreter=true" - $(GroupBuildCmd) "/p:WasmEnableRelaxedSimd=$(WasmEnableRelaxedSimd)" + $(GroupBuildCmd) "/p:PublishReadyToRunInstructionSet=$(PublishReadyToRunInstructionSet)" $(GroupBuildCmd) "/p:RunAOTCompilation=true" $(GroupBuildCmd) "/p:DevTeamProvisioning=$(DevTeamProvisioning)" From 27c08856d4991202621ea6bd3c55e02c779df45a Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Sun, 8 Nov 2026 15:53:16 -0600 Subject: [PATCH 10/18] Run the wasm intrinsics library tests on WASI Add the WASI target framework to System.Runtime.Intrinsics.Tests and run PackedSimdTests and RelaxedSimdTests on WASI as well as browser, so the WASI library ReadyToRun lane exercises relaxed SIMD with CoreLib in the composite. Drop the tests.wasi.targets default; the substitutions it fed are not used on WASI. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- eng/testing/tests.wasi.targets | 5 ----- .../tests/System.Runtime.Intrinsics.Tests.csproj | 2 +- .../System.Runtime.Intrinsics/tests/Wasm/PackedSimdTests.cs | 2 +- .../System.Runtime.Intrinsics/tests/Wasm/RelaxedSimdTests.cs | 2 +- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/eng/testing/tests.wasi.targets b/eng/testing/tests.wasi.targets index 1880b3be3ad947..bcc314bc7724ef 100644 --- a/eng/testing/tests.wasi.targets +++ b/eng/testing/tests.wasi.targets @@ -1,9 +1,4 @@ - - - true - - diff --git a/src/libraries/System.Runtime.Intrinsics/tests/System.Runtime.Intrinsics.Tests.csproj b/src/libraries/System.Runtime.Intrinsics/tests/System.Runtime.Intrinsics.Tests.csproj index 264b8039125d7a..d788d52bdc9bba 100644 --- a/src/libraries/System.Runtime.Intrinsics/tests/System.Runtime.Intrinsics.Tests.csproj +++ b/src/libraries/System.Runtime.Intrinsics/tests/System.Runtime.Intrinsics.Tests.csproj @@ -4,7 +4,7 @@ $(NoWarn),1718,SYSLIB0013 true true - $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser;$(NetCoreAppCurrent)-wasi true false diff --git a/src/libraries/System.Runtime.Intrinsics/tests/Wasm/PackedSimdTests.cs b/src/libraries/System.Runtime.Intrinsics/tests/Wasm/PackedSimdTests.cs index 1d8030ff35ab77..ac74ffffeb0891 100644 --- a/src/libraries/System.Runtime.Intrinsics/tests/Wasm/PackedSimdTests.cs +++ b/src/libraries/System.Runtime.Intrinsics/tests/Wasm/PackedSimdTests.cs @@ -13,7 +13,7 @@ namespace System.Runtime.Intrinsics.Wasm.Tests { - [PlatformSpecific(TestPlatforms.Browser)] + [PlatformSpecific(TestPlatforms.Browser | TestPlatforms.Wasi)] [ConditionalClass(typeof(PackedSimdTests), nameof(IsSupported))] public sealed class PackedSimdTests { diff --git a/src/libraries/System.Runtime.Intrinsics/tests/Wasm/RelaxedSimdTests.cs b/src/libraries/System.Runtime.Intrinsics/tests/Wasm/RelaxedSimdTests.cs index 39468eaa7452ea..533aad2bc7e986 100644 --- a/src/libraries/System.Runtime.Intrinsics/tests/Wasm/RelaxedSimdTests.cs +++ b/src/libraries/System.Runtime.Intrinsics/tests/Wasm/RelaxedSimdTests.cs @@ -8,7 +8,7 @@ namespace System.Runtime.Intrinsics.Wasm.Tests { - [PlatformSpecific(TestPlatforms.Browser)] + [PlatformSpecific(TestPlatforms.Browser | TestPlatforms.Wasi)] public sealed class RelaxedSimdTests { public static bool IsNotSupported => !RelaxedSimd.IsSupported; From 907eec7e1a4bff7e9c972ab431ede602276713e2 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Wed, 11 Nov 2026 18:14:51 -0600 Subject: [PATCH 11/18] Run the WASI wasm intrinsics tests in whole-program composite mode The WASI hardware-intrinsics leg sets WholeProgramCompositeBuildMode, which compiles CoreLib into each test composite, so the tests are built with relaxed SIMD and the #134949 quarantines no longer apply there. Other WASI R2R runs keep the -relaxed-simd default and the quarantines. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- eng/pipelines/coreclr/hardware-intrinsics-wasm.yml | 5 +++-- .../coreclr/templates/jit-hardware-intrinsics-wasm.yml | 8 ++++---- src/tests/Common/CLRTest.Execute.Bash.targets | 3 +++ src/tests/Common/CoreCLRTestLibrary/PlatformDetection.cs | 3 +++ src/tests/Common/helixpublishwitharcade.proj | 2 ++ src/tests/Directory.Build.targets | 3 ++- .../HardwareIntrinsics/Wasm/PackedSimd/PackedSimdTests.cs | 4 ++-- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml b/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml index 56f01ba152bdab..21042c818c3fd9 100644 --- a/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml +++ b/eng/pipelines/coreclr/hardware-intrinsics-wasm.yml @@ -37,5 +37,6 @@ extends: parameters: platforms: - wasi_wasm - compositeBuildMode: true - testBuildArgs: '-test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_r.csproj -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_ro.csproj' + # Compiles CoreLib into each test composite, so the tests can use relaxed SIMD. + extraHelixArguments: /p:WholeProgramCompositeBuildMode=true + testBuildArgs: '/p:PublishReadyToRunInstructionSet=relaxed-simd -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_r.csproj -test:JIT/HardwareIntrinsics/HardwareIntrinsics_Wasm_ro.csproj' diff --git a/eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml b/eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml index 1e39547d2c672e..5ff4d8fdca3b2d 100644 --- a/eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml +++ b/eng/pipelines/coreclr/templates/jit-hardware-intrinsics-wasm.yml @@ -3,9 +3,9 @@ parameters: type: object - name: testBuildArgs type: string - - name: compositeBuildMode - type: boolean - default: false + - name: extraHelixArguments + type: string + default: '' - name: extraBuildArgs type: string default: '' @@ -38,7 +38,7 @@ jobs: testRunNamePrefixSuffix: CoreCLR_R2R # The CoreCLR interpreter does not implement Wasm SIMD; ReadyToRun code does. readyToRun: true - compositeBuildMode: ${{ parameters.compositeBuildMode }} + extraHelixArguments: ${{ parameters.extraHelixArguments }} extraVariablesTemplates: - template: /eng/pipelines/common/templates/runtimes/test-variables.yml parameters: diff --git a/src/tests/Common/CLRTest.Execute.Bash.targets b/src/tests/Common/CLRTest.Execute.Bash.targets index 194ec9d95e56c3..913eaf2d2e12cb 100644 --- a/src/tests/Common/CLRTest.Execute.Bash.targets +++ b/src/tests/Common/CLRTest.Execute.Bash.targets @@ -517,6 +517,9 @@ if [ ! -z ${RunCrossGen2+x} ] && [ "$(CrossGenTest)" != "false" ]; then # Keep the probe's stubs private to this host, so a subsequent interpreter run # cannot discover a composite that is not spliced into its own corerun. __WasiR2RArgs="--env TEST_READY_TO_RUN_MODE=1 --env APP_ASSEMBLIES=EXTERNAL --env CORE_LIBRARIES=/$__WasiCrossgen2OutputDirectory/wasi-r2r" + if [ ! -z ${WholeProgramCompositeBuildMode+x} ]; then + __WasiR2RArgs="$__WasiR2RArgs --env WholeProgramCompositeBuildMode" + fi fi ]]> diff --git a/src/tests/Common/CoreCLRTestLibrary/PlatformDetection.cs b/src/tests/Common/CoreCLRTestLibrary/PlatformDetection.cs index 88090f1a556415..76eb0feb28be78 100644 --- a/src/tests/Common/CoreCLRTestLibrary/PlatformDetection.cs +++ b/src/tests/Common/CoreCLRTestLibrary/PlatformDetection.cs @@ -113,6 +113,9 @@ public static bool IsMonoInterpreter public static bool IsWasm => IsBrowser || IsWasi; public static bool IsReadyToRunCompiled => Environment.GetEnvironmentVariable("TEST_READY_TO_RUN_MODE") == "1"; public static bool IsWasmReadyToRun => IsWasm && IsReadyToRunCompiled; + // The test assemblies and CoreLib were compiled into one composite image. + public static bool IsWholeProgramComposite => IsReadyToRunCompiled && Environment.GetEnvironmentVariable("WholeProgramCompositeBuildMode") is not null; + public static bool IsNotWholeProgramComposite => !IsWholeProgramComposite; // CoreCLR on WebAssembly (FEATURE_PORTABLE_ENTRYPOINTS) cannot create native-callable entrypoints at run time, // e.g. for Marshal.GetFunctionPointerForDelegate or a delegate passed to a P/Invoke. diff --git a/src/tests/Common/helixpublishwitharcade.proj b/src/tests/Common/helixpublishwitharcade.proj index 29950f2bf0f866..2d0ac96d344d6f 100644 --- a/src/tests/Common/helixpublishwitharcade.proj +++ b/src/tests/Common/helixpublishwitharcade.proj @@ -672,6 +672,7 @@ + @@ -728,6 +729,7 @@ + diff --git a/src/tests/Directory.Build.targets b/src/tests/Directory.Build.targets index f6a4bf3c9d8890..55afceabb74865 100644 --- a/src/tests/Directory.Build.targets +++ b/src/tests/Directory.Build.targets @@ -297,7 +297,8 @@ Condition="('$(TargetOS)' == 'browser' or '$(TargetOS)' == 'wasi') and '$(RuntimeFlavor)' == 'coreclr' and '$(TestBuildMode)' != 'nativeaot'" /> + only use the runtime's baseline instruction sets. Runs with WholeProgramCompositeBuildMode compile CoreLib into the + composite and can set PublishReadyToRunInstructionSet=relaxed-simd. --> -relaxed-simd diff --git a/src/tests/JIT/HardwareIntrinsics/Wasm/PackedSimd/PackedSimdTests.cs b/src/tests/JIT/HardwareIntrinsics/Wasm/PackedSimd/PackedSimdTests.cs index 5eca0fd9584b63..c4db4448e86235 100644 --- a/src/tests/JIT/HardwareIntrinsics/Wasm/PackedSimd/PackedSimdTests.cs +++ b/src/tests/JIT/HardwareIntrinsics/Wasm/PackedSimd/PackedSimdTests.cs @@ -13,7 +13,7 @@ public sealed class PackedSimdTests { [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/134949", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsWasi), nameof(TestLibrary.PlatformDetection.IsReadyToRunCompiled))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/134949", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsWasi), nameof(TestLibrary.PlatformDetection.IsReadyToRunCompiled), nameof(TestLibrary.PlatformDetection.IsNotWholeProgramComposite))] [DynamicDependency(DynamicallyAccessedMemberTypes.PublicProperties, typeof(PackedSimd))] public static unsafe void PackedSimdIsSupported() { @@ -1260,7 +1260,7 @@ public static unsafe void LoadScalarAndSplatTest() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/134949", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsWasi), nameof(TestLibrary.PlatformDetection.IsReadyToRunCompiled))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/134949", typeof(TestLibrary.PlatformDetection), nameof(TestLibrary.PlatformDetection.IsWasi), nameof(TestLibrary.PlatformDetection.IsReadyToRunCompiled), nameof(TestLibrary.PlatformDetection.IsNotWholeProgramComposite))] public static unsafe void LoadStoreNullCheckTest() { if (!PackedSimd.IsSupported) From 34951da2411ab35e25ec7bb3983517db30899ade Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 6 Nov 2026 16:31:08 -0600 Subject: [PATCH 12/18] [wasm][nativeaot] Enable PackedSimd for NativeAOT NativeAOT's CoreLib compiled the PlatformNotSupported PackedSimd and WasmBase implementations on wasm because SupportsWasmIntrinsics only covered CoreCLR and Mono. Enable it for FeatureNativeAot too. That needs two compiler fixes: - InstructionSetSupport.GetHardwareIntrinsicId returned "" for Wasm32, so ILC's HardwareIntrinsicILProvider never supplied IsSupported bodies and compiling the self-recursive get_IsSupported failed. Map System.Runtime.Intrinsics.Wasm types to their instruction sets. - For the NativeAOT ABI the JIT only folds IsSupported/IsHardwareAccelerated to true when compExactlyDependsOn succeeds, which always returns false on wasm. Wasm has no runtime ISA detection, so compile-time support is exact; treat it as such. Vector128.IsHardwareAccelerated was false under NativeAOT otherwise. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- src/coreclr/jit/hwintrinsic.cpp | 8 +++++++- .../tools/Common/Compiler/InstructionSetSupport.cs | 4 ++-- .../src/System.Private.CoreLib.Shared.projitems | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/hwintrinsic.cpp b/src/coreclr/jit/hwintrinsic.cpp index 431b642f582406..cb9e0bbc0ecb59 100644 --- a/src/coreclr/jit/hwintrinsic.cpp +++ b/src/coreclr/jit/hwintrinsic.cpp @@ -1287,7 +1287,13 @@ NamedIntrinsic HWIntrinsicInfo::resolveId(Compiler* comp, if (isIsaSupported && comp->compSupportsHWIntrinsic(isa) && (vectorByteLength <= comp->getPreferredVectorByteLength())) { - if (!comp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) || comp->compExactlyDependsOn(isa)) +#ifdef TARGET_WASM + // Wasm has no runtime ISA detection, so the compile-time ISA support is exact. + constexpr bool isaSupportIsExact = true; +#else + constexpr bool isaSupportIsExact = false; +#endif + if (!comp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) || isaSupportIsExact || comp->compExactlyDependsOn(isa)) { return NI_IsSupported_True; } diff --git a/src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs b/src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs index 6f366a3fbe5fb1..d163a0853079a9 100644 --- a/src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs +++ b/src/coreclr/tools/Common/Compiler/InstructionSetSupport.cs @@ -100,8 +100,8 @@ public static string GetHardwareIntrinsicId(TargetArchitecture architecture, Typ } else if (architecture is TargetArchitecture.Wasm32) { - // TODO-WASM: return the correct intrinsic id once xplat intrinsics are implemented. - return ""; + if (potentialType.Namespace != "System.Runtime.Intrinsics.Wasm"u8) + return ""; } else { diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index a6bb0b2caaf614..d53ea05e8ec6a1 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -16,7 +16,7 @@ true true true - true + true false true From ed71d5c17bf5be3b6e62ac2216690d387c530214 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Fri, 6 Nov 2026 16:31:10 -0600 Subject: [PATCH 13/18] [wasm][nativeaot] Enable RelaxedSimd for NativeAOT from WasmEnableRelaxedSimd Compile the real RelaxedSimd implementation into NativeAOT's CoreLib on wasm. Microsoft.NETCore.Native.Wasm.targets now defaults WasmEnableRelaxedSimd to true, matching CoreCLR WASI, and adds relaxed-simd to IlcInstructionSet (merged with a user-specified value, since ILC takes a single --instruction-set). As with ReadyToRun, wasm has no runtime feature detection: the module only compiles on an engine with relaxed SIMD, so set WasmEnableRelaxedSimd=false for engines without it. src/tests NativeAOT builds import these targets, so they pick this up from the existing WasmEnableRelaxedSimd default for WASI. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../BuildIntegration/Microsoft.NETCore.Native.Wasm.targets | 4 ++++ src/coreclr/nativeaot/docs/optimizing.md | 2 +- .../src/System.Private.CoreLib.Shared.projitems | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Wasm.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Wasm.targets index 2e576de118e9cb..8ec51d97a73a0e 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Wasm.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Wasm.targets @@ -17,6 +17,10 @@ libeventpipe-disabled libeventpipe-enabled true + + true + relaxed-simd + $(IlcInstructionSet),relaxed-simd diff --git a/src/coreclr/nativeaot/docs/optimizing.md b/src/coreclr/nativeaot/docs/optimizing.md index 755fcc2710ca65..94e5279684091c 100644 --- a/src/coreclr/nativeaot/docs/optimizing.md +++ b/src/coreclr/nativeaot/docs/optimizing.md @@ -5,5 +5,5 @@ See the official documentation at https://learn.microsoft.com/dotnet/core/deploy The rest of the document talks about options that exist, but their names and purpose are subject to change without a breaking change notice. ## Options related to code generation -* ``: By default, the compiler targets the minimum instruction set supported by the target OS and architecture. This option allows targeting newer instruction sets for better performance. The native binary will require the instruction sets to be supported by the hardware in order to run. For example, `avx2,bmi2,fma,pclmul,popcnt,aes` will produce binary that takes advantage of instruction sets that are typically present on current Intel and AMD processors. `native` will produce a binary that uses instructions that currently running CPU supports (no cross-compilation support). Run `ilc --help` for the full list of available instruction sets. `ilc` can be executed from the NativeAOT package in your local nuget cache e.g. `%USERPROFILE%\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\8.0.0-...\tools\ilc.exe` on Windows or `~/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/8.0.0-.../tools/ilc` on Linux. +* ``: By default, the compiler targets the minimum instruction set supported by the target OS and architecture. This option allows targeting newer instruction sets for better performance. The native binary will require the instruction sets to be supported by the hardware in order to run. For example, `avx2,bmi2,fma,pclmul,popcnt,aes` will produce binary that takes advantage of instruction sets that are typically present on current Intel and AMD processors. `native` will produce a binary that uses instructions that currently running CPU supports (no cross-compilation support). Run `ilc --help` for the full list of available instruction sets. `ilc` can be executed from the NativeAOT package in your local nuget cache e.g. `%USERPROFILE%\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\8.0.0-...\tools\ilc.exe` on Windows or `~/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/8.0.0-.../tools/ilc` on Linux. For WASI, `` (default `true`) adds `relaxed-simd` to the instruction set; set it to `false` for WebAssembly engines without relaxed SIMD. * ``: By default, the compiler targets a `Vector` size of `16` or `32` bytes, depending on the underlying instruction sets supported. This option allows specifying a different maximum bit width. For example, by default on x64 hardware `Vector` will be 16-bytes, however, if `AVX2` is targeted then `Vector` will automatically grow to be 32-bytes instead. Setting `128` would keep the size as 16-bytes. Alternatively, even if `AVX512F` is targeted then by default `Vector` will not grow larger than 32-bytes, setting `512` would allow it to grow to 64-bytes. diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index d53ea05e8ec6a1..46098aa4f1d29e 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -19,7 +19,7 @@ true false - true + true false true false From 6f87a738630ddde2c293ba40a31c808eacfc23b5 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Sun, 8 Nov 2026 15:18:16 -0600 Subject: [PATCH 14/18] Revert the WASI note in the NativeAOT optimizing doc Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- src/coreclr/nativeaot/docs/optimizing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/nativeaot/docs/optimizing.md b/src/coreclr/nativeaot/docs/optimizing.md index 94e5279684091c..755fcc2710ca65 100644 --- a/src/coreclr/nativeaot/docs/optimizing.md +++ b/src/coreclr/nativeaot/docs/optimizing.md @@ -5,5 +5,5 @@ See the official documentation at https://learn.microsoft.com/dotnet/core/deploy The rest of the document talks about options that exist, but their names and purpose are subject to change without a breaking change notice. ## Options related to code generation -* ``: By default, the compiler targets the minimum instruction set supported by the target OS and architecture. This option allows targeting newer instruction sets for better performance. The native binary will require the instruction sets to be supported by the hardware in order to run. For example, `avx2,bmi2,fma,pclmul,popcnt,aes` will produce binary that takes advantage of instruction sets that are typically present on current Intel and AMD processors. `native` will produce a binary that uses instructions that currently running CPU supports (no cross-compilation support). Run `ilc --help` for the full list of available instruction sets. `ilc` can be executed from the NativeAOT package in your local nuget cache e.g. `%USERPROFILE%\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\8.0.0-...\tools\ilc.exe` on Windows or `~/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/8.0.0-.../tools/ilc` on Linux. For WASI, `` (default `true`) adds `relaxed-simd` to the instruction set; set it to `false` for WebAssembly engines without relaxed SIMD. +* ``: By default, the compiler targets the minimum instruction set supported by the target OS and architecture. This option allows targeting newer instruction sets for better performance. The native binary will require the instruction sets to be supported by the hardware in order to run. For example, `avx2,bmi2,fma,pclmul,popcnt,aes` will produce binary that takes advantage of instruction sets that are typically present on current Intel and AMD processors. `native` will produce a binary that uses instructions that currently running CPU supports (no cross-compilation support). Run `ilc --help` for the full list of available instruction sets. `ilc` can be executed from the NativeAOT package in your local nuget cache e.g. `%USERPROFILE%\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\8.0.0-...\tools\ilc.exe` on Windows or `~/.nuget/packages/runtime.linux-arm64.microsoft.dotnet.ilcompiler/8.0.0-.../tools/ilc` on Linux. * ``: By default, the compiler targets a `Vector` size of `16` or `32` bytes, depending on the underlying instruction sets supported. This option allows specifying a different maximum bit width. For example, by default on x64 hardware `Vector` will be 16-bytes, however, if `AVX2` is targeted then `Vector` will automatically grow to be 32-bytes instead. Setting `128` would keep the size as 16-bytes. Alternatively, even if `AVX512F` is targeted then by default `Vector` will not grow larger than 32-bytes, setting `512` would allow it to grow to 64-bytes. From ec2b87bfb2d43617c462d545b5178b2cd1cd43b1 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Sun, 8 Nov 2026 15:54:34 -0600 Subject: [PATCH 15/18] Rely on the compiler's WASI relaxed SIMD default for NativeAOT Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../BuildIntegration/Microsoft.NETCore.Native.Wasm.targets | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Wasm.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Wasm.targets index 8ec51d97a73a0e..2e576de118e9cb 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Wasm.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Wasm.targets @@ -17,10 +17,6 @@ libeventpipe-disabled libeventpipe-enabled true - - true - relaxed-simd - $(IlcInstructionSet),relaxed-simd From 50e1d30b08186e5a090c54153f6b17335fbdbe39 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Sun, 8 Nov 2026 15:56:42 -0600 Subject: [PATCH 16/18] Forward IlcInstructionSet to the src/tests inner build Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- src/tests/build.proj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/build.proj b/src/tests/build.proj index fedf0235f0fa8e..888f0ef329e4b0 100644 --- a/src/tests/build.proj +++ b/src/tests/build.proj @@ -259,6 +259,7 @@ $(GroupBuildCmd) "/p:BuildTestsOnHelix=true" $(GroupBuildCmd) "/p:MonoForceInterpreter=true" $(GroupBuildCmd) "/p:PublishReadyToRunInstructionSet=$(PublishReadyToRunInstructionSet)" + $(GroupBuildCmd) "/p:IlcInstructionSet=$(IlcInstructionSet)" $(GroupBuildCmd) "/p:RunAOTCompilation=true" $(GroupBuildCmd) "/p:DevTeamProvisioning=$(DevTeamProvisioning)" From 3fc5ae11fcbf7a17b0c476dd64976623555b7ba8 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Sun, 8 Nov 2026 16:04:53 -0600 Subject: [PATCH 17/18] Simplify the wasm IsSupported fold in resolveId Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- src/coreclr/jit/hwintrinsic.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/hwintrinsic.cpp b/src/coreclr/jit/hwintrinsic.cpp index cb9e0bbc0ecb59..73d25fea40248b 100644 --- a/src/coreclr/jit/hwintrinsic.cpp +++ b/src/coreclr/jit/hwintrinsic.cpp @@ -1289,11 +1289,9 @@ NamedIntrinsic HWIntrinsicInfo::resolveId(Compiler* comp, { #ifdef TARGET_WASM // Wasm has no runtime ISA detection, so the compile-time ISA support is exact. - constexpr bool isaSupportIsExact = true; + return NI_IsSupported_True; #else - constexpr bool isaSupportIsExact = false; -#endif - if (!comp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) || isaSupportIsExact || comp->compExactlyDependsOn(isa)) + if (!comp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) || comp->compExactlyDependsOn(isa)) { return NI_IsSupported_True; } @@ -1302,6 +1300,7 @@ NamedIntrinsic HWIntrinsicInfo::resolveId(Compiler* comp, assert(comp->IsTargetAbi(CORINFO_NATIVEAOT_ABI)); return NI_IsSupported_Dynamic; } +#endif } return NI_IsSupported_False; From 361d116afb4672b8049074518bdf6320ceda5457 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Wed, 11 Nov 2026 19:03:08 -0600 Subject: [PATCH 18/18] Enable wasm intrinsics for every wasm CoreLib Co-authored-by: jkotas Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../src/System.Private.CoreLib.Shared.projitems | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 46098aa4f1d29e..ec51341b42de3b 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -15,11 +15,10 @@ true true true - true - true + true false - true + true false true false