Skip to content

JIT: use v128.store for 16-byte wasm zero fills - #137517

Merged
lewing merged 1 commit into
mainfrom
lewing-wasm-v128-zero-fill
Nov 14, 2026
Merged

lewing merged 1 commit into
mainfrom
lewing-wasm-v128-zero-fill

Conversation

@lewing

@lewing lewing commented Nov 13, 2026

Copy link
Copy Markdown
Member

Follow-up to #137234. genWasmZeroInit now emits i32.const 0; i8x16.splat; v128.store for constant 16-byte zero fills instead of memory.fill. This covers frame zero-init, constant localloc, native initblk and GC-ref zeroing. CoreCLR browser-wasm already requires SIMD.

i8x16.splat is used rather than a zero v128.const because it is 14 bytes smaller per site (8 vs 22 bytes) and was never slower in the measurements below. It is 1 byte larger than the memory.fill sequence (7 bytes).

Size

In a composite R2R browser-wasm publish of a small test app (CoreLib + System.Console + app), 300 of 321 16-byte memory.fill sites (of 1,539 total memory.fills) became v128.store. The composite image grew from 2,449,568 to 2,449,856 bytes (+288 B).

Speed

Pure-wasm microbenchmark, 16-byte zero fill, net ns per fill, Apple M5 Max:

Engine / tier memory.fill i8x16.splat + v128.store v128.const 0 + v128.store
V8 Liftoff (node --liftoff-only) 2.74 0.149 0.359
V8 TurboFan (node --no-liftoff) 0.170 0.082 0.082
JSC BBQ (jsc --useOMGJIT=false) 1.86 0.130 0.130
JSC default 0.190 0.082 0.081

Both baseline tiers compile memory.fill as an out-of-line call, so code that has not tiered up gains the most. V8's --print-wasm-code shows both v128 forms as a single str q0 on arm64.

Composite R2R browser-wasm app on node (best of 7 per run, 5 interleaved runs, ns/op). These loops run long enough to tier up:

Kernel Base This PR Change
arr[i] = default for 16-byte structs (two longs, four refs, Guid, decimal, mixed) 0.386–0.392 0.308–0.310 about -20%
Prolog zeroing of a 16-byte struct local with refs 4.075 3.922 -3.8% (ranges overlap)
List<(string,string,string,string)> Add/RemoveAt, Dictionary<Guid,object> set/remove, decimal math within ±0.4%

The A/B used JITs built from the same commit, swapped into the same crossgen2 and runtime pack. Another build was running on the machine during part of the measurements.

Validation

  • ./build.sh clr.crossarchtools -os browser -arch wasm -c Release /p:RuntimeFlavor=CoreCLR passed at this commit.
  • ./build.sh clr.crossarchtools -os browser -arch wasm -c Checked /p:RuntimeFlavor=CoreCLR passed at this commit.
  • python3 src/coreclr/scripts/jitformat.py -a arm64 -o osx -r <repo> passed with no changes.
  • With the same patch applied at 62278fed5a1, the composite R2R publish (PublishReadyToRun=true, PublishReadyToRunComposite=true) compiled with no asserts under a Checked JIT. The resulting app ran with checksums matching the baseline.
  • SuperPMI, the runtime and library test suites, x64, and browsers other than node were not run.

Contributes to #135985.

Note

This PR description was generated with GitHub Copilot.

Extend genWasmZeroInit to emit i32.const 0; i8x16.splat; v128.store for
constant 16-byte zero fills instead of memory.fill. The splat form is 14
bytes smaller than a zero v128.const and no slower.

Co-authored-by: Copilot App <[email protected]>
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 13, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).
9 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@lewing
lewing requested a review from AndyAyersMS November 13, 2026 20:48
@lewing

lewing commented Nov 13, 2026 •

Copy link
Copy Markdown
Member Author

It is a microptimization but considerably faster in the cold case at the cost of a byte

@lewing lewing added the arch-wasm WebAssembly architecture label Nov 13, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@lewing

lewing commented Nov 14, 2026

Copy link
Copy Markdown
Member Author

/ba-g issues created for untracked and unrelated failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants