Skip to content

Add support for generalized variable length wasm instructions to the emitter - #125862

Merged
davidwrighton merged 2 commits into
dotnet:mainfrom
davidwrighton:generalized_variable_length_wasm_instructions
Mar 23, 2026
Merged

davidwrighton merged 2 commits into
dotnet:mainfrom
davidwrighton:generalized_variable_length_wasm_instructions

Conversation

@davidwrighton

Copy link
Copy Markdown
Member

My previous fix only made 2 byte instructions work, but in theory wasm can have larger variable sized instructions. This change allows us to define the instructions in the same format that the spec defines them, and supports emitting any of them (as long as the variable sized opcode fits in a uint16_t which should be good enough for now.

Copilot AI review requested due to automatic review settings March 20, 2026 20:31
@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 Mar 20, 2026
@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.

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 updates the WASM JIT instruction encoding to support spec-style prefixed opcodes with variable-length (ULEB128) sub-opcodes, enabling instruction definitions to match the WebAssembly opcode format rather than a packed 2-byte representation.

Changes:

  • Introduce an INST2(prefix, opcode) instruction-table form for WASM prefixed instructions.
  • Update the WASM emitter to output prefixed opcodes as prefix-byte + ULEB128(subopcode) and size them accordingly.
  • Wire INST2 through existing instruction enum/name/info/format/opcode tables.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/coreclr/jit/instrswasm.h Adds INST2 usage for prefixed WASM instructions (e.g., 0xFC-prefixed ops) and enforces INST2 definition.
src/coreclr/jit/instr.h Extends WASM instruction enum generation to accept INST2.
src/coreclr/jit/instr.cpp Extends WASM instruction name table generation to accept INST2.
src/coreclr/jit/emitwasm.cpp Adds prefix/subopcode tables and emits prefixed opcodes as prefix + ULEB128; updates sizing and an emission site to use the new opcode output helper.

Comment thread src/coreclr/jit/emitwasm.cpp Resolved
Comment thread src/coreclr/jit/emitwasm.cpp Resolved
Comment thread src/coreclr/jit/instrswasm.h Resolved

@AndyAyersMS AndyAyersMS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, just one comment you might consider.

Comment thread src/coreclr/jit/instrswasm.h Resolved
@davidwrighton
davidwrighton merged commit 47655ce into dotnet:main Mar 23, 2026
127 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 23, 2026
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Jun 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

4 participants