Skip to content

[wasm] Fix v128.load / v128.store opcodes in the R2R ObjectWriter - #130941

Merged
lewing merged 1 commit into
dotnet:mainfrom
lewing:wasm-fix-v128-load-store-opcodes
Jul 17, 2026
Merged

lewing merged 1 commit into
dotnet:mainfrom
lewing:wasm-fix-v128-load-store-opcodes

Conversation

@lewing

@lewing lewing commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

The WasmExprKind opcode constants for the two 128-bit memory instructions in the R2R wasm ObjectWriter were wrong:

V128Load  = unchecked((int)0xFD00000A),   // sub-opcode 0x0A is v128.load64_splat
V128Store = unchecked((int)0xFD000000),   // sub-opcode 0x00 is v128.load

The SIMD sub-opcodes are v128.load = 0x00 and v128.store = 0x0B (the encoder writes byte 0 = kind >> 24 = 0xFD prefix, then the low 24 bits as the ULEB sub-opcode). So V128.Store() emitted a v128.load and V128.Load() emitted a v128.load64_splat.

Any thunk that spills/reloads a v128 argument — e.g. the delay-load helper for a method call with Vector128<T> parameters — therefore produced an invalid module:

WebAssembly.Module(): Compiling function #N failed:
v128.load[0] expected type i32, found local.get of type v128

(the "store" was actually a load, consuming the v128 value as the address), or, on the reload side, a corrupted vector (load64_splat reads 8 bytes and splats them instead of loading the full 16).

Fix

V128Load  = unchecked((int)0xFD000000),   // v128.load  = 0xFD 0x00
V128Store = unchecked((int)0xFD00000B),   // v128.store = 0xFD 0x0B

I audited the rest of the WasmExprKind opcodes (base, 0xFC bulk-memory/table, SIMD) against the spec — these two were the only incorrect entries.

Why it was latent

Nothing emitted V128.Store/V128.Load until Vector128<T> began flowing through these thunks by value (the wasm v128 ABI work in #130866). Verified end-to-end on the R2R-on-wasm prototype: with this fix, a Vector128 method call whose delay-load thunk spills/reloads the vector produces a valid module that executes correctly as R2R (the emitted thunk now shows v128.store on spill and v128.load on reload). Helps unblock #130866.

Note

This pull request was authored with the assistance of GitHub Copilot.

The WasmExprKind opcode constants for the two 128-bit memory instructions
were wrong:

  V128Load  = 0xFD00000A   // sub-opcode 0x0A is v128.load64_splat
  V128Store = 0xFD000000   // sub-opcode 0x00 is v128.load

The SIMD sub-opcodes are v128.load = 0x00 and v128.store = 0x0B, so
V128.Store() emitted a v128.load and V128.Load() emitted a v128.load64_splat.
Any thunk that spills/reloads a v128 argument (e.g. the delay-load helper for
a method call with Vector128<T> parameters) therefore produced an invalid
module ("v128.load[0] expected type i32, found ... v128") or a corrupted
vector (load64_splat reads 8 bytes and splats instead of loading the full 16).

Correct both to v128.load = 0xFD 0x00 and v128.store = 0xFD 0x0B. Audited the
rest of the WasmExprKind opcodes (base, 0xFC bulk-memory/table, SIMD) against
the spec; these two were the only incorrect entries.

This was latent until Vector128<T> began flowing through these thunks by value.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 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: @agocke
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR corrects the WebAssembly SIMD opcode constants used by the R2R wasm ObjectWriter so that v128.load / v128.store are encoded with the proper 0xFD-prefixed sub-opcodes.

Changes:

  • Fix WasmExprKind.V128Load to use sub-opcode 0x00 (v128.load).
  • Fix WasmExprKind.V128Store to use sub-opcode 0x0B (v128.store).

@lewing
lewing requested a review from tannergooding July 17, 2026 01:30
@lewing
lewing enabled auto-merge (squash) July 17, 2026 01:46
@tannergooding

Copy link
Copy Markdown
Member

/ba-g unrelated windows x86 COMInterface/LibraryImport test, also failing on other PRs

@lewing
lewing merged commit 7f416ac into dotnet:main Jul 17, 2026
114 of 116 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 18, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants