Support EXT1/EXT2/EXT3 operand extension opcodes#189
Open
hadashiA wants to merge 2 commits into
Open
Conversation
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #188
Problem
The VM never decoded mruby's
EXT1/EXT2/EXT3operand-widening prefix opcodes — they existed in theOpCodeenum but fell through toThrowInvalidOpCode. Any method whose literal pool or symbol table exceeded 255 entries (e.g. many string literals in one method) made the native compiler emit an EXT prefix, crashing withNotSupportedException: Invalid opcode EXT2.The disassembler (
CodeDump) had the same bug in a quieter form: it skipped EXT as a 1-byte no-op, so all subsequent output was misaligned.Changes
Operands.cs: operand structs now exposeushortfields and take anextparameter. Theext == 0fast path is a single predictable branch; the widened decode (2-byte big-endian per mruby spec) is[NoInlining]out of line.MRubyState.Vm.cs: the dispatch loop consumes an EXT prefix, re-fetches the real opcode, and passesextto every widenable operand read (B/BB/BBB/BS/BSS; already-wideS/Woperands are never prefixed).MRubyState.Dump.cs: same treatment, so disassembly of EXT-containing ireps stays aligned.STRING) and 300 distinct method definitions/calls (symbol overflow → EXT2 onSSEND), both previously crashing.Perf
A/B-measured (in-process median, interleaved runs):
The ao regression comes from
extbeing live across the hot switch, not from the read bodies (int/ushort/mask variants all measured identical). Making it zero-cost would require duplicating the full opcode switch as a cold path — deemed not worth the maintenance surface for a rare prefix. Correctness over the last 2% here.Also adds a
--quick-bench <script> [warmup] [iters]mode to the benchmark sandbox used for these measurements.🤖 Generated with Claude Code