Repository navigation
Add CompExactlyDependsOn to some methods so that they are compiled on wasm - #135869
Merged
Merged
Conversation
… wasm A method having multiple `CompExactlyDependsOn` attributes with various instruction sets is compiled only if at least one of these instruction sets is supported (in addition to the requirement of all ISAs to be deterministically supported or unsupported at run time). `CompHasFallback` serves the purpose of still compiling the method even if none of the ISAs is supported. In our case here, all these methods are already used in the context of other methods depending on PackedSimd so we just need to add this missing attribute to enable their compilation. For example, this makes `System.Text.RegularExpressions.Tests.Perf_Regex_Common.ReplaceWords` 100x faster.
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-buffers |
Contributor
|
Tagging subscribers to this area: @dotnet/crossgen-contrib |
lewing
approved these changes
Oct 15, 2026
This was referenced Oct 15, 2026
Closed
Member
Author
|
/ba-g failure unrelated |
lewing
added a commit
that referenced
this pull request
Nov 17, 2026
`PackedSpanHelpers` narrows two `Vector128<ushort>` into one `Vector128<byte>` to search 16 chars per compare, but was gated on `Sse2` only, so WebAssembly always took the non-packed path. `PackedSimd.ConvertNarrowingSaturateUnsigned` (`i8x16.narrow_i16x8_u`) has the same saturation semantics as `Sse2.PackUnsignedSaturate`, so the existing `CanUsePackedIndexOf` rules apply unchanged. - `PackedIndexOfIsSupported` becomes `Sse2 || PackedSimd`; `PackSources`/`LoadPacked128` narrow with `PackedSimd`, using explicit `IsSupported` chains so ILLink removes dead branches. - `string.Split` and `SingleStringSearchValuesPackedThreeChars` use the packed path on wasm. - `[CompExactlyDependsOn(typeof(PackedSimd))]` lets CoreCLR wasm R2R precompile these methods. This applies to Mono (interpreter and AOT) and CoreCLR R2R; the CoreCLR interpreter reports `PackedSimd.IsSupported == false`. | CoreCLR browser-wasm R2R, new/base | len=16 | len=1024 | |---|--:|--:| | `span.IndexOf(char)` | 1.07 | 0.60 | | `span.IndexOfAny(c0, c1, c2)` | 1.17 | 0.71 | | `SearchValues<string>` | 1.05 | 0.61 | Short inputs cost about 1–2 ns per call on Arm hosts, where V8 and Cranelift lower the narrow and bitmask to multi-instruction sequences; on x64 they map to `packuswb`/`pmovmskb` (not measured). <details><summary>Full benchmark table and Arm details</summary> Apple M-series host under Node/V8, five interleaved rounds per build, medians; ratio = new / baseline. | Benchmark | len=16 | len=64 | len=1024 | |---|---:|---:|---:| | `span.IndexOf(char)` | 1.07 | 1.01 | 0.60 | | `span.IndexOfAny(c0, c1)` | 1.10 | 1.02 | 0.70 | | `span.IndexOfAny(c0, c1, c2)` | 1.17 | 1.01 | 0.71 | | `span.IndexOfAnyExcept(char)` | 1.11 | 1.00 | 0.60 | | `span.Contains(char)` | 1.04 | 1.11 | 0.63 | | `string.IndexOf(char, OrdinalIgnoreCase)` | 1.05 | 0.96 | 0.64 | | `SearchValues<char>` (3 values) | 1.13 | 1.05 | 0.73 | | `SearchValues<string>` (1 value) | 1.05 | 1.04 | 0.61 | | `string.Split` (3 separators, dense) | 1.07 | 1.06 | 1.03 | | `string.Replace(string, string)` (1-char old value, dense) | 1.04 | 1.07 | 1.15 | Mono browser-wasm shows the same shape: AOT 0.66–0.80 at len=1024 and 1.09–1.27 at len=16; the interpreter 0.65–0.85 at most sizes. Results break even around 64–96 chars. On aarch64, V8 (`d8 --print-wasm-code`) and Cranelift lower `i8x16.narrow_i16x8_u` to a dependent `sqxtun`/`sqxtun2` pair and `i8x16.bitmask` to a two-`pmull` + `trn2` sequence; `i16x8.bitmask` needs one `pmull`. A possible follow-up keeps the packed `any_true` loop but computes the match index from the unpacked 16-bit vectors, as `MakeSeparatorListVectorized` does. Related: #135869 (other `CompExactlyDependsOn(PackedSimd)` gaps), #135892 (crossgen2 doesn't fold `box T; isinst X`). </details> > [!NOTE] > This PR description was drafted with GitHub Copilot assistance. --------- Co-authored-by: Copilot App <[email protected]> Copilot-Session: a42c1090-4687-4af7-92e0-1aa50cdd1826
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
A method having multiple
CompExactlyDependsOnattributes with various instruction sets is compiled only if at least one of these instruction sets is supported (in addition to the requirement of all ISAs to be deterministically supported or unsupported at run time).CompHasFallbackserves the purpose of still compiling the method even if none of the ISAs is supported. In our case here, all these methods are already used in the context of other methods depending on PackedSimd so we just need to add this missing attribute to enable their compilation.For example, this makes
System.Text.RegularExpressions.Tests.Perf_Regex_Common.ReplaceWords100x faster.