Skip to content

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

Open
davidwrighton wants to merge 2 commits intodotnet:mainfrom
davidwrighton:generalized_variable_length_wasm_instructions
Open

Add support for generalized variable length wasm instructions to the emitter#125862
davidwrighton wants to merge 2 commits intodotnet:mainfrom
davidwrighton:generalized_variable_length_wasm_instructions

Conversation

@davidwrighton
Copy link
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
Contributor

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

Copy link
Contributor

Copilot AI left a comment

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.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

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.

// control flow
//
INST(invalid, "INVALID", 0, IF_NONE, BAD_CODE)
INST2(invalid, "INVALID", 0, IF_NONE, 0xFC, BAD_CODE)
Copy link
Member

Choose a reason for hiding this comment

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

As is this 0xFC nnnn won't ever get emitted, either we need to change this to specify IF_OPCODE (and rework some internal asserts to catch this case) or else the value doesn't matter.

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

Labels

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.

3 participants