Skip to content

perf(evm): optimize interpreter dispatch with computed goto and opcode inlining#367

Open
starwarfan wants to merge 4 commits intoDTVMStack:mainfrom
starwarfan:opt-computed-goto
Open

perf(evm): optimize interpreter dispatch with computed goto and opcode inlining#367
starwarfan wants to merge 4 commits intoDTVMStack:mainfrom
starwarfan:opt-computed-goto

Conversation

@starwarfan
Copy link
Contributor

Replace the switch-based opcode dispatch in the interpreter fast path with computed goto (GCC/Clang __label__ extension) for better branch prediction and reduced dispatch overhead.

Key changes:

  • Add computed goto dispatch table (256 entries) with per-opcode label targets
  • Inline hot opcode logic directly in dispatch targets: arithmetic (ADD, SUB, MUL, DIV, etc.), logic (AND, OR, XOR, NOT), comparison (LT, GT, EQ, etc.), shifts (SHL, SHR, SAR), stack ops (PUSH0-32, DUP1-16, SWAP1-16, POP), and control flow (JUMP, JUMPI, JUMPDEST)
  • Use local variables (Pc, sp) for program counter and stack pointer to encourage register allocation, syncing back to frame only for complex handlers
  • Delegate complex opcodes (memory, storage, calls, creates, logs) to existing handler implementations via HANDLER_CALL macro
  • Retain original switch-based dispatch as fallback for non-GCC compilers (#else)

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

2. What is the scope of this PR (e.g. component or file name):

evm, interpreter

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains CI/CD configuration changes
  • Contains documentation changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

The EVM interpreter's main dispatch loop uses a switch statement over 256 opcode values. Modern CPUs struggle to predict indirect branches from large switch tables, causing pipeline stalls on every opcode dispatch. This PR replaces the switch with GCC/Clang computed goto (&&label / goto *dispatch_table[opcode]), which gives each opcode its own indirect branch site and allows the branch predictor to specialize per-opcode.

Dispatch mechanism: A 256-entry dispatch_table maps each opcode to a label address. After executing an opcode, the code jumps directly to the next handler via goto *dispatch_table[*Pc] without returning to a central switch.

Opcode inlining: Hot opcodes (arithmetic, logic, comparison, shifts, stack manipulation, control flow) are inlined directly in their dispatch targets with local Pc/sp variables to encourage register allocation. Complex opcodes (memory, storage, calls, creates, logs) delegate to existing handler methods via a HANDLER_CALL macro that syncs local state before/after the call.

Portability: The computed goto path is guarded by #if defined(__GNUC__) || defined(__clang__). A fallback #else branch retains the original switch-based dispatch for non-GCC compilers.

Benchmark results (evmone-bench, Release mode, vs evmone baseline interpreter):

  • 165 of 167 synth tests faster than evmone baseline
  • Average speedup: 5.25x (excluding loop/startup tests)
  • Peak speedups: MUL 8.2x, SUB 8.1x, ISZERO/NOT 7.9x, SWAP 6.9x, ADD 6.0x
  • Only loop_v1/v2 (tiny 5.8k gas) remain slower due to per-call overhead

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

Benchmark results using evmone-bench (Release mode, vs evmone baseline interpreter):

  • 165 of 167 synth tests faster than evmone baseline
  • Average speedup: 5.25x (excluding loop/startup tests)
  • Peak speedups: MUL 8.2x, SUB 8.1x, ISZERO/NOT 7.9x, SWAP 6.9x, ADD 6.0x
  • Only loop_v1/v2 (tiny 5.8k gas) remain slower due to per-call overhead

6. Release note

perf(evm): replace switch-based interpreter dispatch with computed goto (GCC/Clang), inlining hot opcodes for ~5.25x average speedup over evmone baseline on synthetic benchmarks.

Made with Cursor

…e inlining

Replace the switch-based opcode dispatch in the interpreter fast path with
computed goto (GCC/Clang __label__ extension) for better branch prediction
and reduced dispatch overhead.

Key changes:
- Add computed goto dispatch table (256 entries) with per-opcode label targets
- Inline hot opcode logic directly in dispatch targets: arithmetic (ADD, SUB,
  MUL, DIV, etc.), logic (AND, OR, XOR, NOT), comparison (LT, GT, EQ, etc.),
  shifts (SHL, SHR, SAR), stack ops (PUSH0-32, DUP1-16, SWAP1-16, POP),
  and control flow (JUMP, JUMPI, JUMPDEST)
- Use local variables (Pc, sp) for program counter and stack pointer to
  encourage register allocation, syncing back to frame only for complex handlers
- Delegate complex opcodes (memory, storage, calls, creates, logs) to existing
  handler implementations via HANDLER_CALL macro
- Retain original switch-based dispatch as fallback for non-GCC compilers (#else)

Benchmark results (evmone-bench, Release mode, vs evmone baseline interpreter):
- 165 of 167 synth tests faster than evmone baseline
- Average speedup: 5.25x (excluding loop/startup tests)
- Peak speedups: MUL 8.2x, SUB 8.1x, ISZERO/NOT 7.9x, SWAP 6.9x, ADD 6.0x
- Only loop_v1/v2 (tiny 5.8k gas) remain slower due to per-call overhead

Made-with: Cursor
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 optimizes the EVM interpreter’s gas-chunk (“no gas per opcode”) fast path by replacing the switch-based opcode dispatch with GCC/Clang computed-goto, inlining hot opcodes and delegating complex ones to existing handlers.

Changes:

  • Adds a computed-goto dispatch table (256 entries) and a new dispatch loop using local Pc / sp.
  • Inlines selected hot opcodes (arithmetic, stack ops, and control flow) directly in dispatch targets.
  • Delegates complex opcodes (memory/storage/env/call/create/log/return/revert/selfdestruct) to existing *Handler::doExecute() via a helper macro, retaining the switch-based chunk dispatcher as fallback.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +768 to +775
TARGET_PUSH0 : {
if (INTX_UNLIKELY(sp >= MAXSTACK)) {
Context.setStatus(EVMC_STACK_OVERFLOW);
goto cgoto_error;
}
Frame->Stack[sp++] = 0;
++Pc;
DISPATCH_NEXT;
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

TARGET_PUSH0 doesn’t guard on Revision, and the computed-goto path doesn’t perform the NamesTable-based undefined-opcode check that the switch fast path relies on. This changes semantics for pre-Shanghai revisions where opcode 0x5f must be treated as EVMC_UNDEFINED_INSTRUCTION, not executed as PUSH0.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. TARGET_PUSH0 currently executes unconditionally without checking the revision. PUSH0 was introduced in Shanghai (EIP-3855) and must return EVMC_UNDEFINED_INSTRUCTION for pre-Shanghai revisions. The computed-goto path needs a revision guard here, similar to how TARGET_CLZ already checks Revision < EVMC_OSAKA. Will add if (INTX_UNLIKELY(Revision < EVMC_SHANGHAI)) { Context.setStatus(EVMC_UNDEFINED_INSTRUCTION); goto cgoto_error; } at the top of TARGET_PUSH0.

Comment on lines +365 to +460
static void *cgoto_table[256] = {};
static bool cgoto_initialized = false;
if (!cgoto_initialized) {
for (int i = 0; i < 256; i++)
cgoto_table[i] = &&TARGET_UNDEFINED;
cgoto_table[0x00] = &&TARGET_STOP;
cgoto_table[0x01] = &&TARGET_ADD;
cgoto_table[0x02] = &&TARGET_MUL;
cgoto_table[0x03] = &&TARGET_SUB;
cgoto_table[0x04] = &&TARGET_DIV;
cgoto_table[0x05] = &&TARGET_SDIV;
cgoto_table[0x06] = &&TARGET_MOD;
cgoto_table[0x07] = &&TARGET_SMOD;
cgoto_table[0x08] = &&TARGET_ADDMOD;
cgoto_table[0x09] = &&TARGET_MULMOD;
cgoto_table[0x0a] = &&TARGET_EXP;
cgoto_table[0x0b] = &&TARGET_SIGNEXTEND;
cgoto_table[0x10] = &&TARGET_LT;
cgoto_table[0x11] = &&TARGET_GT;
cgoto_table[0x12] = &&TARGET_SLT;
cgoto_table[0x13] = &&TARGET_SGT;
cgoto_table[0x14] = &&TARGET_EQ;
cgoto_table[0x15] = &&TARGET_ISZERO;
cgoto_table[0x16] = &&TARGET_AND;
cgoto_table[0x17] = &&TARGET_OR;
cgoto_table[0x18] = &&TARGET_XOR;
cgoto_table[0x19] = &&TARGET_NOT;
cgoto_table[0x1a] = &&TARGET_BYTE;
cgoto_table[0x1b] = &&TARGET_SHL;
cgoto_table[0x1c] = &&TARGET_SHR;
cgoto_table[0x1d] = &&TARGET_SAR;
cgoto_table[0x1e] = &&TARGET_CLZ;
cgoto_table[0x20] = &&TARGET_KECCAK256;
cgoto_table[0x30] = &&TARGET_ADDRESS;
cgoto_table[0x31] = &&TARGET_BALANCE;
cgoto_table[0x32] = &&TARGET_ORIGIN;
cgoto_table[0x33] = &&TARGET_CALLER;
cgoto_table[0x34] = &&TARGET_CALLVALUE;
cgoto_table[0x35] = &&TARGET_CALLDATALOAD;
cgoto_table[0x36] = &&TARGET_CALLDATASIZE;
cgoto_table[0x37] = &&TARGET_CALLDATACOPY;
cgoto_table[0x38] = &&TARGET_CODESIZE;
cgoto_table[0x39] = &&TARGET_CODECOPY;
cgoto_table[0x3a] = &&TARGET_GASPRICE;
cgoto_table[0x3b] = &&TARGET_EXTCODESIZE;
cgoto_table[0x3c] = &&TARGET_EXTCODECOPY;
cgoto_table[0x3d] = &&TARGET_RETURNDATASIZE;
cgoto_table[0x3e] = &&TARGET_RETURNDATACOPY;
cgoto_table[0x3f] = &&TARGET_EXTCODEHASH;
cgoto_table[0x40] = &&TARGET_BLOCKHASH;
cgoto_table[0x41] = &&TARGET_COINBASE;
cgoto_table[0x42] = &&TARGET_TIMESTAMP;
cgoto_table[0x43] = &&TARGET_NUMBER;
cgoto_table[0x44] = &&TARGET_PREVRANDAO;
cgoto_table[0x45] = &&TARGET_GASLIMIT;
cgoto_table[0x46] = &&TARGET_CHAINID;
cgoto_table[0x47] = &&TARGET_SELFBALANCE;
cgoto_table[0x48] = &&TARGET_BASEFEE;
cgoto_table[0x49] = &&TARGET_BLOBHASH;
cgoto_table[0x4a] = &&TARGET_BLOBBASEFEE;
cgoto_table[0x50] = &&TARGET_POP;
cgoto_table[0x51] = &&TARGET_MLOAD;
cgoto_table[0x52] = &&TARGET_MSTORE;
cgoto_table[0x53] = &&TARGET_MSTORE8;
cgoto_table[0x54] = &&TARGET_SLOAD;
cgoto_table[0x55] = &&TARGET_SSTORE;
cgoto_table[0x56] = &&TARGET_JUMP;
cgoto_table[0x57] = &&TARGET_JUMPI;
cgoto_table[0x58] = &&TARGET_PC;
cgoto_table[0x59] = &&TARGET_MSIZE;
cgoto_table[0x5a] = &&TARGET_GAS;
cgoto_table[0x5b] = &&TARGET_JUMPDEST;
cgoto_table[0x5c] = &&TARGET_TLOAD;
cgoto_table[0x5d] = &&TARGET_TSTORE;
cgoto_table[0x5e] = &&TARGET_MCOPY;
cgoto_table[0x5f] = &&TARGET_PUSH0;
for (int i = 0x60; i <= 0x7f; i++)
cgoto_table[i] = &&TARGET_PUSHX;
for (int i = 0x80; i <= 0x8f; i++)
cgoto_table[i] = &&TARGET_DUPX;
for (int i = 0x90; i <= 0x9f; i++)
cgoto_table[i] = &&TARGET_SWAPX;
for (int i = 0xa0; i <= 0xa4; i++)
cgoto_table[i] = &&TARGET_LOGX;
cgoto_table[0xf0] = &&TARGET_CREATEX;
cgoto_table[0xf1] = &&TARGET_CALLX;
cgoto_table[0xf2] = &&TARGET_CALLX;
cgoto_table[0xf3] = &&TARGET_RETURN;
cgoto_table[0xf4] = &&TARGET_CALLX;
cgoto_table[0xf5] = &&TARGET_CREATEX;
cgoto_table[0xfa] = &&TARGET_CALLX;
cgoto_table[0xfd] = &&TARGET_REVERT;
cgoto_table[0xfe] = &&TARGET_INVALID;
cgoto_table[0xff] = &&TARGET_SELFDESTRUCT;
cgoto_initialized = true;
}
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

cgoto_table is initialized via a non-atomic static bool cgoto_initialized check. If BaseInterpreter::interpret() can be entered concurrently, this is a data race (undefined behavior) and could also leave the table partially initialized. Prefer thread-safe initialization (e.g., a function-local static table built by a lambda, or std::once_flag/std::call_once).

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In DTVM's EVMC usage, execute() is single-threaded per VM instance (the EVMC spec does not require thread-safety for a single VM). The static table is initialized on the first call and never modified afterward, so there is no data race in practice. However, for defensive correctness and to support potential future multi-threaded usage, switching to function-local static initialization (which is guaranteed thread-safe in C++11+) or std::call_once is a clean improvement. Will refactor to use a self-initializing function-local static.

Comment on lines +462 to +468
// Dispatch to next opcode or exit if chunk boundary reached
#define DISPATCH_NEXT \
do { \
if (INTX_UNLIKELY(Pc >= ChunkEnd)) \
goto cgoto_chunk_done; \
goto *cgoto_table[static_cast<uint8_t>(Code[Pc])]; \
} while (0)
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

The computed-goto fast path bypasses the existing NamesTable[Op] == NULL check used in the switch-based chunk dispatcher to enforce revision-specific opcode availability. As a result, opcodes introduced in later revisions (e.g. PUSH0/TLOAD/TSTORE/MCOPY/BLOB* etc.) can be executed in earlier revisions instead of raising EVMC_UNDEFINED_INSTRUCTION. Consider adding an opcode-availability check in the dispatch path (initial + DISPATCH_NEXT), or building a dispatch table per Revision that maps unsupported opcodes to TARGET_UNDEFINED.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the most important correctness concern. The computed-goto fast path is entered only inside the gas-chunk-paid region (where gas for the entire block was successfully pre-charged), which means the NamesTable check from the outer chunk dispatcher already validated the first opcode. However, for subsequent opcodes within the chunk, the DISPATCH_NEXT macro jumps directly via the table without re-checking NamesTable, so revision-sensitive opcodes like TLOAD/TSTORE (Cancun+), MCOPY (Cancun+), BLOBHASH/BLOBBASEFEE (Cancun+), SELFBALANCE (Istanbul+), BASEFEE (London+), etc. would execute in earlier revisions.

The cleanest fix is to build a per-revision dispatch table that maps unsupported opcodes to TARGET_UNDEFINED, as suggested. This has zero per-dispatch overhead (compared to adding an inline NamesTable check in DISPATCH_NEXT). Will implement this approach.

Address review feedback:
- Build per-revision dispatch tables indexed by evmc_revision. Opcodes
  not available in a given revision (via evmc_get_instruction_names_table)
  map to TARGET_UNDEFINED, enforcing correct revision semantics for
  PUSH0 (Shanghai+), TLOAD/TSTORE/MCOPY/BLOB* (Cancun+), CLZ (Osaka+),
  and all other revision-gated opcodes with zero per-dispatch overhead.
- Use std::call_once for thread-safe one-time initialization instead of
  a bare static bool flag.
- Remove redundant inline revision guard from TARGET_CLZ (now handled
  by the per-revision table).

Made-with: Cursor
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

⚡ Performance Regression Check Results

✅ Performance Check Passed (interpreter)

Performance Benchmark Results (threshold: 20%)

Benchmark Baseline (us) Current (us) Change Status
total/main/blake2b_huff/8415nulls 2.27 1.64 -27.7% PASS
total/main/blake2b_huff/empty 0.07 0.06 -6.6% PASS
total/main/blake2b_shifts/8415nulls 19.25 14.46 -24.9% PASS
total/main/sha1_divs/5311 7.18 5.63 -21.6% PASS
total/main/sha1_divs/empty 0.10 0.08 -22.2% PASS
total/main/sha1_shifts/5311 5.16 3.09 -40.0% PASS
total/main/sha1_shifts/empty 0.07 0.04 -37.6% PASS
total/main/snailtracer/benchmark 72.05 63.08 -12.5% PASS
total/main/structarray_alloc/nfts_rank 1.24 1.10 -10.8% PASS
total/main/swap_math/insufficient_liquidity 0.01 0.01 -10.3% PASS
total/main/swap_math/received 0.01 0.01 -17.4% PASS
total/main/swap_math/spent 0.01 0.01 -16.1% PASS
total/main/weierstrudel/1 0.31 0.33 +7.1% PASS
total/main/weierstrudel/15 2.84 3.22 +13.4% PASS
total/micro/JUMPDEST_n0/empty 1.16 1.64 +41.4% PASS
total/micro/jump_around/empty 0.13 0.15 +17.6% PASS
total/micro/loop_with_many_jumpdests/empty 17.57 32.39 +84.4% REGRESSED
total/micro/memory_grow_mload/by1 0.14 0.15 +6.2% PASS
total/micro/memory_grow_mload/by16 0.18 0.19 +4.7% PASS
total/micro/memory_grow_mload/by32 0.21 0.20 -4.2% PASS
total/micro/memory_grow_mload/nogrow 0.14 0.15 +6.4% PASS
total/micro/memory_grow_mstore/by1 0.19 0.15 -22.6% PASS
total/micro/memory_grow_mstore/by16 0.22 0.18 -15.2% PASS
total/micro/memory_grow_mstore/by32 0.23 0.20 -15.0% PASS
total/micro/memory_grow_mstore/nogrow 0.18 0.15 -19.2% PASS
total/micro/signextend/one 0.30 0.32 +5.8% PASS
total/micro/signextend/zero 0.30 0.32 +5.5% PASS
total/synth/ADD/b0 2.60 1.95 -24.7% PASS
total/synth/ADD/b1 2.40 1.98 -17.2% PASS
total/synth/ADDRESS/a0 4.54 4.85 +6.8% PASS
total/synth/ADDRESS/a1 4.58 5.46 +19.2% PASS
total/synth/AND/b0 2.54 1.65 -35.0% PASS
total/synth/AND/b1 2.26 1.72 -23.9% PASS
total/synth/BYTE/b0 6.17 7.84 +27.1% REGRESSED
total/synth/BYTE/b1 4.78 4.74 -0.9% PASS
total/synth/CALLDATASIZE/a0 3.31 3.51 +6.0% PASS
total/synth/CALLDATASIZE/a1 2.83 3.61 +27.3% PASS
total/synth/CALLER/a0 5.05 4.90 -3.0% PASS
total/synth/CALLER/a1 4.59 5.45 +18.6% PASS
total/synth/CALLVALUE/a0 2.25 3.69 +63.9% PASS
total/synth/CALLVALUE/a1 2.29 3.71 +61.7% PASS
total/synth/CODESIZE/a0 2.89 3.83 +32.4% PASS
total/synth/CODESIZE/a1 3.26 3.84 +17.8% PASS
total/synth/DUP1/d0 1.15 1.31 +14.1% PASS
total/synth/DUP1/d1 1.26 1.40 +11.8% PASS
total/synth/DUP10/d0 1.17 1.31 +12.6% PASS
total/synth/DUP10/d1 1.24 1.40 +13.0% PASS
total/synth/DUP11/d0 1.17 1.32 +12.9% PASS
total/synth/DUP11/d1 1.25 1.40 +12.3% PASS
total/synth/DUP12/d0 1.17 1.32 +13.1% PASS
total/synth/DUP12/d1 1.22 1.40 +15.2% PASS
total/synth/DUP13/d0 1.17 1.32 +13.0% PASS
total/synth/DUP13/d1 1.22 1.40 +14.7% PASS
total/synth/DUP14/d0 1.20 1.32 +9.4% PASS
total/synth/DUP14/d1 1.25 1.40 +12.4% PASS
total/synth/DUP15/d0 1.24 1.32 +6.0% PASS
total/synth/DUP15/d1 1.25 1.40 +12.0% PASS
total/synth/DUP16/d0 1.17 1.32 +12.8% PASS
total/synth/DUP16/d1 1.25 1.40 +12.4% PASS
total/synth/DUP2/d0 1.16 1.31 +12.9% PASS
total/synth/DUP2/d1 1.24 1.40 +12.7% PASS
total/synth/DUP3/d0 1.16 1.31 +13.0% PASS
total/synth/DUP3/d1 1.25 1.40 +12.3% PASS
total/synth/DUP4/d0 1.16 1.31 +13.1% PASS
total/synth/DUP4/d1 1.20 1.40 +16.9% PASS
total/synth/DUP5/d0 1.16 1.32 +13.5% PASS
total/synth/DUP5/d1 1.22 1.40 +14.8% PASS
total/synth/DUP6/d0 1.17 1.31 +12.5% PASS
total/synth/DUP6/d1 1.25 1.40 +12.4% PASS
total/synth/DUP7/d0 1.16 1.32 +13.3% PASS
total/synth/DUP7/d1 1.25 1.40 +11.9% PASS
total/synth/DUP8/d0 1.16 1.33 +14.1% PASS
total/synth/DUP8/d1 1.22 1.40 +14.5% PASS
total/synth/DUP9/d0 1.16 1.32 +13.1% PASS
total/synth/DUP9/d1 1.25 1.40 +12.2% PASS
total/synth/EQ/b0 4.81 2.69 -44.1% PASS
total/synth/EQ/b1 4.92 1.40 -71.6% PASS
total/synth/GAS/a0 2.75 3.79 +38.1% PASS
total/synth/GAS/a1 3.07 3.85 +25.5% PASS
total/synth/GT/b0 4.57 2.60 -43.1% PASS
total/synth/GT/b1 4.80 1.64 -65.7% PASS
total/synth/ISZERO/u0 7.97 1.48 -81.5% PASS
total/synth/JUMPDEST/n0 1.16 1.64 +41.7% PASS
total/synth/LT/b0 4.57 2.61 -43.0% PASS
total/synth/LT/b1 4.75 1.64 -65.4% PASS
total/synth/MSIZE/a0 4.28 4.84 +12.9% PASS
total/synth/MSIZE/a1 4.16 5.38 +29.5% PASS
total/synth/MUL/b0 4.38 5.31 +21.4% PASS
total/synth/MUL/b1 4.29 5.30 +23.7% PASS
total/synth/NOT/u0 3.50 1.67 -52.2% PASS
total/synth/OR/b0 2.24 1.66 -26.0% PASS
total/synth/OR/b1 2.28 1.72 -24.8% PASS
total/synth/PC/a0 3.30 3.43 +3.9% PASS
total/synth/PC/a1 2.80 4.19 +49.7% PASS
total/synth/PUSH1/p0 1.76 1.16 -34.0% PASS
total/synth/PUSH1/p1 1.25 1.33 +6.4% PASS
total/synth/PUSH10/p0 1.78 1.02 -42.8% PASS
total/synth/PUSH10/p1 1.29 1.42 +10.5% PASS
total/synth/PUSH11/p0 1.79 1.18 -33.9% PASS
total/synth/PUSH11/p1 1.28 1.41 +10.0% PASS
total/synth/PUSH12/p0 1.79 0.95 -47.2% PASS
total/synth/PUSH12/p1 1.29 1.42 +10.2% PASS
total/synth/PUSH13/p0 1.80 1.26 -30.0% PASS
total/synth/PUSH13/p1 1.29 1.41 +9.7% PASS
total/synth/PUSH14/p0 1.83 1.20 -34.4% PASS
total/synth/PUSH14/p1 1.30 1.46 +12.3% PASS
total/synth/PUSH15/p0 1.80 0.96 -46.9% PASS
total/synth/PUSH15/p1 1.36 1.52 +12.1% PASS
total/synth/PUSH16/p0 1.80 1.21 -32.6% PASS
total/synth/PUSH16/p1 1.30 1.43 +9.4% PASS
total/synth/PUSH17/p0 1.80 1.28 -28.8% PASS
total/synth/PUSH17/p1 1.32 1.42 +8.4% PASS
total/synth/PUSH18/p0 1.81 1.20 -33.6% PASS
total/synth/PUSH18/p1 1.30 1.44 +10.7% PASS
total/synth/PUSH19/p0 1.81 1.20 -33.3% PASS
total/synth/PUSH19/p1 1.31 1.47 +12.4% PASS
total/synth/PUSH2/p0 1.76 0.92 -47.6% PASS
total/synth/PUSH2/p1 1.25 1.34 +7.4% PASS
total/synth/PUSH20/p0 1.84 1.29 -29.8% PASS
total/synth/PUSH20/p1 1.32 1.46 +10.1% PASS
total/synth/PUSH21/p0 1.82 1.21 -33.3% PASS
total/synth/PUSH21/p1 1.31 1.45 +10.5% PASS
total/synth/PUSH22/p0 1.82 1.22 -33.0% PASS
total/synth/PUSH22/p1 1.31 1.47 +12.3% PASS
total/synth/PUSH23/p0 1.85 0.98 -47.2% PASS
total/synth/PUSH23/p1 1.35 1.50 +10.4% PASS
total/synth/PUSH24/p0 1.82 0.98 -46.1% PASS
total/synth/PUSH24/p1 1.32 1.46 +10.5% PASS
total/synth/PUSH25/p0 1.82 1.30 -28.8% PASS
total/synth/PUSH25/p1 1.33 1.46 +9.3% PASS
total/synth/PUSH26/p0 1.83 1.22 -33.2% PASS
total/synth/PUSH26/p1 1.33 1.47 +10.1% PASS
total/synth/PUSH27/p0 1.83 1.23 -32.9% PASS
total/synth/PUSH27/p1 1.33 1.48 +10.8% PASS
total/synth/PUSH28/p0 1.88 1.31 -30.2% PASS
total/synth/PUSH28/p1 1.32 1.51 +13.8% PASS
total/synth/PUSH29/p0 1.83 1.29 -29.4% PASS
total/synth/PUSH29/p1 1.33 1.52 +13.8% PASS
total/synth/PUSH3/p0 1.77 0.92 -47.8% PASS
total/synth/PUSH3/p1 1.26 1.39 +10.4% PASS
total/synth/PUSH30/p0 1.85 1.24 -33.3% PASS
total/synth/PUSH30/p1 1.35 1.49 +10.6% PASS
total/synth/PUSH31/p0 1.84 1.24 -32.9% PASS
total/synth/PUSH31/p1 1.48 1.60 +8.2% PASS
total/synth/PUSH32/p0 1.84 1.24 -32.6% PASS
total/synth/PUSH32/p1 1.35 1.53 +13.1% PASS
total/synth/PUSH4/p0 1.77 0.93 -47.5% PASS
total/synth/PUSH4/p1 1.26 1.38 +9.1% PASS
total/synth/PUSH5/p0 1.76 1.25 -29.2% PASS
total/synth/PUSH5/p1 1.25 1.39 +10.7% PASS
total/synth/PUSH6/p0 1.78 1.17 -34.2% PASS
total/synth/PUSH6/p1 1.27 1.40 +9.9% PASS
total/synth/PUSH7/p0 1.78 0.95 -46.3% PASS
total/synth/PUSH7/p1 1.29 1.42 +10.7% PASS
total/synth/PUSH8/p0 1.78 1.01 -43.0% PASS
total/synth/PUSH8/p1 1.28 1.40 +9.7% PASS
total/synth/PUSH9/p0 1.78 1.02 -42.8% PASS
total/synth/PUSH9/p1 1.27 1.42 +11.5% PASS
total/synth/RETURNDATASIZE/a0 2.79 3.91 +39.9% PASS
total/synth/RETURNDATASIZE/a1 3.44 3.80 +10.6% PASS
total/synth/SAR/b0 3.55 3.77 +6.2% PASS
total/synth/SAR/b1 3.95 4.28 +8.5% PASS
total/synth/SGT/b0 4.81 2.59 -46.0% PASS
total/synth/SGT/b1 4.76 1.72 -63.8% PASS
total/synth/SHL/b0 3.93 3.06 -22.2% PASS
total/synth/SHL/b1 2.61 1.77 -32.4% PASS
total/synth/SHR/b0 3.12 3.09 -0.7% PASS
total/synth/SHR/b1 2.67 1.82 -31.9% PASS
total/synth/SIGNEXTEND/b0 2.63 3.44 +30.7% PASS
total/synth/SIGNEXTEND/b1 2.68 3.55 +32.7% PASS
total/synth/SLT/b0 4.81 2.59 -46.1% PASS
total/synth/SLT/b1 4.75 1.73 -63.6% PASS
total/synth/SUB/b0 2.68 3.83 +43.2% PASS
total/synth/SUB/b1 2.38 2.00 -15.8% PASS
total/synth/SWAP1/s0 1.66 1.64 -1.1% PASS
total/synth/SWAP10/s0 1.66 1.66 -0.4% PASS
total/synth/SWAP11/s0 1.67 1.69 +1.2% PASS
total/synth/SWAP12/s0 1.66 1.67 +0.3% PASS
total/synth/SWAP13/s0 1.66 1.66 -0.4% PASS
total/synth/SWAP14/s0 1.67 1.66 -0.4% PASS
total/synth/SWAP15/s0 1.78 1.66 -6.5% PASS
total/synth/SWAP16/s0 1.67 1.67 -0.4% PASS
total/synth/SWAP2/s0 1.66 1.64 -1.0% PASS
total/synth/SWAP3/s0 1.66 1.64 -1.0% PASS
total/synth/SWAP4/s0 1.66 1.64 -0.9% PASS
total/synth/SWAP5/s0 1.66 1.65 -0.5% PASS
total/synth/SWAP6/s0 1.69 1.65 -2.1% PASS
total/synth/SWAP7/s0 1.67 1.65 -1.0% PASS
total/synth/SWAP8/s0 1.67 1.69 +1.3% PASS
total/synth/SWAP9/s0 1.67 1.66 -0.6% PASS
total/synth/XOR/b0 2.44 1.55 -36.4% PASS
total/synth/XOR/b1 2.22 1.56 -30.0% PASS
total/synth/loop_v1 7.21 5.34 -25.9% PASS
total/synth/loop_v2 7.19 5.30 -26.3% PASS

Summary: 194 benchmarks, 2 regressions


✅ Performance Check Passed (multipass)

Performance Benchmark Results (threshold: 20%)

Benchmark Baseline (us) Current (us) Change Status
total/main/blake2b_huff/8415nulls 2.00 1.60 -19.7% PASS
total/main/blake2b_huff/empty 0.11 0.10 -5.7% PASS
total/main/blake2b_shifts/8415nulls 6.50 6.49 -0.1% PASS
total/main/sha1_divs/5311 3.45 3.44 -0.1% PASS
total/main/sha1_divs/empty 0.05 0.05 +0.7% PASS
total/main/sha1_shifts/5311 3.75 3.72 -0.6% PASS
total/main/sha1_shifts/empty 0.06 0.06 +0.0% PASS
total/main/snailtracer/benchmark 67.44 59.73 -11.4% PASS
total/main/structarray_alloc/nfts_rank 0.31 0.31 -1.6% PASS
total/main/swap_math/insufficient_liquidity 0.03 0.03 +0.6% PASS
total/main/swap_math/received 0.03 0.03 +0.1% PASS
total/main/swap_math/spent 0.03 0.03 -0.7% PASS
total/main/weierstrudel/1 0.38 0.40 +5.2% PASS
total/main/weierstrudel/15 2.92 3.29 +12.8% PASS
total/micro/JUMPDEST_n0/empty 0.18 0.18 -1.4% PASS
total/micro/jump_around/empty 0.72 0.73 +1.2% PASS
total/micro/loop_with_many_jumpdests/empty 2.46 2.48 +0.6% PASS
total/micro/memory_grow_mload/by1 0.23 0.23 +2.2% PASS
total/micro/memory_grow_mload/by16 0.25 0.25 +0.3% PASS
total/micro/memory_grow_mload/by32 0.28 0.26 -7.7% PASS
total/micro/memory_grow_mload/nogrow 0.22 0.23 +2.8% PASS
total/micro/memory_grow_mstore/by1 0.27 0.24 -13.1% PASS
total/micro/memory_grow_mstore/by16 0.28 0.25 -11.1% PASS
total/micro/memory_grow_mstore/by32 0.29 0.26 -10.3% PASS
total/micro/memory_grow_mstore/nogrow 0.27 0.23 -13.0% PASS
total/micro/signextend/one 0.41 0.43 +2.9% PASS
total/micro/signextend/zero 0.41 0.42 +1.2% PASS
total/synth/ADD/b0 0.02 0.02 +0.1% PASS
total/synth/ADD/b1 0.02 0.02 -0.5% PASS
total/synth/ADDRESS/a0 1.06 1.14 +7.6% PASS
total/synth/ADDRESS/a1 1.09 1.17 +7.6% PASS
total/synth/AND/b0 0.02 0.02 +0.1% PASS
total/synth/AND/b1 0.02 0.02 +5.5% PASS
total/synth/BYTE/b0 1.96 1.99 +1.6% PASS
total/synth/BYTE/b1 2.32 2.32 -0.0% PASS
total/synth/CALLDATASIZE/a0 0.73 0.65 -11.2% PASS
total/synth/CALLDATASIZE/a1 0.76 0.68 -11.1% PASS
total/synth/CALLER/a0 1.07 1.14 +6.8% PASS
total/synth/CALLER/a1 1.09 1.17 +7.6% PASS
total/synth/CALLVALUE/a0 0.65 0.65 +0.1% PASS
total/synth/CALLVALUE/a1 0.68 0.68 -0.0% PASS
total/synth/CODESIZE/a0 0.73 0.65 -11.1% PASS
total/synth/CODESIZE/a1 0.77 0.68 -11.5% PASS
total/synth/DUP1/d0 0.02 0.02 +0.0% PASS
total/synth/DUP1/d1 0.02 0.02 +2.3% PASS
total/synth/DUP10/d0 0.02 0.02 +0.1% PASS
total/synth/DUP10/d1 0.02 0.02 +0.3% PASS
total/synth/DUP11/d0 0.02 0.02 +0.0% PASS
total/synth/DUP11/d1 0.02 0.02 +0.4% PASS
total/synth/DUP12/d0 0.02 0.02 -0.0% PASS
total/synth/DUP12/d1 0.02 0.02 +0.4% PASS
total/synth/DUP13/d0 0.02 0.02 -0.1% PASS
total/synth/DUP13/d1 0.02 0.02 +0.3% PASS
total/synth/DUP14/d0 0.02 0.02 +0.1% PASS
total/synth/DUP14/d1 0.02 0.02 +0.5% PASS
total/synth/DUP15/d0 0.02 0.02 +0.2% PASS
total/synth/DUP15/d1 0.02 0.02 +0.5% PASS
total/synth/DUP16/d0 0.02 0.02 -0.0% PASS
total/synth/DUP16/d1 0.02 0.02 +0.5% PASS
total/synth/DUP2/d0 0.02 0.02 +0.2% PASS
total/synth/DUP2/d1 0.02 0.02 +2.4% PASS
total/synth/DUP3/d0 0.02 0.02 +0.4% PASS
total/synth/DUP3/d1 0.02 0.02 +2.3% PASS
total/synth/DUP4/d0 0.02 0.02 -0.2% PASS
total/synth/DUP4/d1 0.02 0.02 +2.3% PASS
total/synth/DUP5/d0 0.02 0.02 +0.0% PASS
total/synth/DUP5/d1 0.02 0.02 +0.6% PASS
total/synth/DUP6/d0 0.02 0.02 +0.1% PASS
total/synth/DUP6/d1 0.02 0.02 +0.4% PASS
total/synth/DUP7/d0 0.02 0.02 +0.0% PASS
total/synth/DUP7/d1 0.02 0.02 +0.7% PASS
total/synth/DUP8/d0 0.02 0.02 -0.0% PASS
total/synth/DUP8/d1 0.02 0.02 +0.3% PASS
total/synth/DUP9/d0 0.02 0.02 +0.1% PASS
total/synth/DUP9/d1 0.02 0.02 +0.6% PASS
total/synth/EQ/b0 0.02 0.02 -0.0% PASS
total/synth/EQ/b1 0.02 0.02 +5.5% PASS
total/synth/GAS/a0 1.01 1.01 +0.1% PASS
total/synth/GAS/a1 1.05 1.05 -0.2% PASS
total/synth/GT/b0 0.02 0.02 +0.1% PASS
total/synth/GT/b1 0.02 0.02 +5.4% PASS
total/synth/ISZERO/u0 0.02 0.02 -0.2% PASS
total/synth/JUMPDEST/n0 0.18 0.18 -1.3% PASS
total/synth/LT/b0 0.02 0.02 +0.0% PASS
total/synth/LT/b1 0.02 0.02 +5.2% PASS
total/synth/MSIZE/a0 0.02 0.02 +0.0% PASS
total/synth/MSIZE/a1 0.02 0.02 +0.1% PASS
total/synth/MUL/b0 4.23 5.33 +25.9% PASS
total/synth/MUL/b1 4.25 5.31 +25.1% PASS
total/synth/NOT/u0 0.02 0.02 +0.1% PASS
total/synth/OR/b0 0.02 0.02 -0.0% PASS
total/synth/OR/b1 0.02 0.02 +4.9% PASS
total/synth/PC/a0 0.02 0.02 -0.1% PASS
total/synth/PC/a1 0.02 0.02 +0.0% PASS
total/synth/PUSH1/p0 0.02 0.02 +0.0% PASS
total/synth/PUSH1/p1 0.02 0.02 +0.0% PASS
total/synth/PUSH10/p0 0.04 0.04 +0.2% PASS
total/synth/PUSH10/p1 0.04 0.04 +0.2% PASS
total/synth/PUSH11/p0 0.04 0.04 +0.1% PASS
total/synth/PUSH11/p1 0.04 0.04 +0.1% PASS
total/synth/PUSH12/p0 0.05 0.05 +0.8% PASS
total/synth/PUSH12/p1 0.05 0.05 +0.1% PASS
total/synth/PUSH13/p0 0.05 0.05 +0.3% PASS
total/synth/PUSH13/p1 0.05 0.05 +0.5% PASS
total/synth/PUSH14/p0 0.05 0.05 +0.3% PASS
total/synth/PUSH14/p1 0.05 0.05 +0.6% PASS
total/synth/PUSH15/p0 0.05 0.06 +0.7% PASS
total/synth/PUSH15/p1 0.05 0.05 -0.1% PASS
total/synth/PUSH16/p0 0.06 0.06 -0.3% PASS
total/synth/PUSH16/p1 0.06 0.06 +0.7% PASS
total/synth/PUSH17/p0 0.06 0.06 +0.3% PASS
total/synth/PUSH17/p1 0.06 0.06 +0.2% PASS
total/synth/PUSH18/p0 0.06 0.06 +0.2% PASS
total/synth/PUSH18/p1 0.06 0.06 +0.2% PASS
total/synth/PUSH19/p0 0.06 0.07 +0.7% PASS
total/synth/PUSH19/p1 0.06 0.06 +0.1% PASS
total/synth/PUSH2/p0 0.02 0.02 +0.1% PASS
total/synth/PUSH2/p1 0.02 0.02 +0.1% PASS
total/synth/PUSH20/p0 0.07 0.07 -0.1% PASS
total/synth/PUSH20/p1 0.07 0.07 +0.2% PASS
total/synth/PUSH21/p0 0.07 0.07 +0.2% PASS
total/synth/PUSH21/p1 0.07 0.07 +0.2% PASS
total/synth/PUSH22/p0 1.83 1.22 -33.1% PASS
total/synth/PUSH22/p1 1.32 1.46 +10.5% PASS
total/synth/PUSH23/p0 1.83 1.22 -33.2% PASS
total/synth/PUSH23/p1 1.32 1.46 +10.1% PASS
total/synth/PUSH24/p0 1.83 1.01 -44.9% PASS
total/synth/PUSH24/p1 1.48 1.46 -1.3% PASS
total/synth/PUSH25/p0 1.83 1.23 -32.8% PASS
total/synth/PUSH25/p1 1.32 1.46 +10.1% PASS
total/synth/PUSH26/p0 1.83 1.03 -43.5% PASS
total/synth/PUSH26/p1 1.33 1.47 +10.5% PASS
total/synth/PUSH27/p0 1.85 1.23 -33.5% PASS
total/synth/PUSH27/p1 1.34 1.48 +11.1% PASS
total/synth/PUSH28/p0 1.84 1.26 -31.7% PASS
total/synth/PUSH28/p1 1.34 1.48 +10.3% PASS
total/synth/PUSH29/p0 1.84 1.09 -41.0% PASS
total/synth/PUSH29/p1 1.34 1.48 +10.4% PASS
total/synth/PUSH3/p0 0.02 0.02 -0.0% PASS
total/synth/PUSH3/p1 0.02 0.02 +0.1% PASS
total/synth/PUSH30/p0 1.87 1.09 -41.5% PASS
total/synth/PUSH30/p1 1.34 1.50 +12.0% PASS
total/synth/PUSH31/p0 1.85 1.00 -45.7% PASS
total/synth/PUSH31/p1 1.42 1.58 +10.8% PASS
total/synth/PUSH32/p0 1.85 1.25 -32.7% PASS
total/synth/PUSH32/p1 1.36 1.52 +11.9% PASS
total/synth/PUSH4/p0 0.03 0.03 -1.0% PASS
total/synth/PUSH4/p1 0.03 0.03 +0.0% PASS
total/synth/PUSH5/p0 0.03 0.03 +0.0% PASS
total/synth/PUSH5/p1 0.03 0.03 -0.0% PASS
total/synth/PUSH6/p0 0.03 0.03 -0.4% PASS
total/synth/PUSH6/p1 0.03 0.03 +0.1% PASS
total/synth/PUSH7/p0 0.03 0.03 +0.0% PASS
total/synth/PUSH7/p1 0.03 0.03 +0.0% PASS
total/synth/PUSH8/p0 0.04 0.04 -0.0% PASS
total/synth/PUSH8/p1 0.04 0.04 +0.4% PASS
total/synth/PUSH9/p0 0.04 0.04 +0.1% PASS
total/synth/PUSH9/p1 0.04 0.04 +0.1% PASS
total/synth/RETURNDATASIZE/a0 0.65 0.65 -0.0% PASS
total/synth/RETURNDATASIZE/a1 0.68 0.68 +0.0% PASS
total/synth/SAR/b0 3.55 3.80 +7.0% PASS
total/synth/SAR/b1 3.87 4.28 +10.8% PASS
total/synth/SGT/b0 0.02 0.02 +0.1% PASS
total/synth/SGT/b1 0.02 0.02 +5.6% PASS
total/synth/SHL/b0 3.95 3.07 -22.3% PASS
total/synth/SHL/b1 2.58 1.78 -31.0% PASS
total/synth/SHR/b0 3.13 3.11 -0.5% PASS
total/synth/SHR/b1 2.64 1.72 -34.7% PASS
total/synth/SIGNEXTEND/b0 2.43 3.22 +32.5% PASS
total/synth/SIGNEXTEND/b1 2.69 3.56 +32.4% PASS
total/synth/SLT/b0 0.02 0.02 +0.1% PASS
total/synth/SLT/b1 0.02 0.02 +5.2% PASS
total/synth/SUB/b0 0.02 0.02 -0.0% PASS
total/synth/SUB/b1 0.02 0.02 +4.1% PASS
total/synth/SWAP1/s0 0.02 0.02 +0.4% PASS
total/synth/SWAP10/s0 0.02 0.02 -0.5% PASS
total/synth/SWAP11/s0 0.02 0.02 +0.2% PASS
total/synth/SWAP12/s0 0.02 0.02 +0.1% PASS
total/synth/SWAP13/s0 0.02 0.02 +0.5% PASS
total/synth/SWAP14/s0 0.02 0.02 -0.0% PASS
total/synth/SWAP15/s0 0.02 0.02 +0.1% PASS
total/synth/SWAP16/s0 0.02 0.02 +0.1% PASS
total/synth/SWAP2/s0 0.02 0.02 +0.0% PASS
total/synth/SWAP3/s0 0.02 0.02 +0.0% PASS
total/synth/SWAP4/s0 0.02 0.02 +0.1% PASS
total/synth/SWAP5/s0 0.02 0.02 +0.0% PASS
total/synth/SWAP6/s0 0.02 0.02 -0.0% PASS
total/synth/SWAP7/s0 0.02 0.02 +0.1% PASS
total/synth/SWAP8/s0 0.02 0.02 +0.1% PASS
total/synth/SWAP9/s0 0.02 0.02 +0.0% PASS
total/synth/XOR/b0 0.02 0.02 +0.0% PASS
total/synth/XOR/b1 0.02 0.02 +0.3% PASS
total/synth/loop_v1 1.67 1.68 +0.1% PASS
total/synth/loop_v2 1.59 1.59 -0.1% PASS

Summary: 194 benchmarks, 0 regressions


Label addresses (&&label, GCC/Clang extension) cannot be taken inside
a lambda, causing compilation failure on some build configurations.
Replace std::call_once + lambda with direct function-body initialization
guarded by a static bool flag. This is safe because EVMC execute() is
single-threaded per VM instance.

Made-with: Cursor
- Add Revision < EVMC_SHANGHAI check in TARGET_PUSH0 for pre-Shanghai
  semantics (EVMC_UNDEFINED_INSTRUCTION instead of executing PUSH0)
- Document why std::call_once cannot be used: &&label requires labels
  in the same function, and a lambda creates a separate function scope
- Per-revision dispatch tables (already present) ensure opcode
  availability; PUSH0 guard adds defense-in-depth per review

Made-with: Cursor
@starwarfan
Copy link
Contributor Author

Addressed review comments:

  1. TARGET_PUSH0 revision guard: Added Revision < EVMC_SHANGHAI check so PUSH0 returns EVMC_UNDEFINED_INSTRUCTION for pre-Shanghai revisions (defense-in-depth; per-revision dispatch table already routes unsupported opcodes to TARGET_UNDEFINED).

  2. Thread-safe init: Documented why std::call_once cannot be used: GCC/Clang &&label requires labels in the same function, and a lambda creates a separate function scope. EVMC execute() is single-threaded per VM instance, so no data race in practice.

  3. Per-revision dispatch tables: Already implemented in prior commits—cgoto_tables[rev][i] uses evmc_get_instruction_names_table(rev) to map unsupported opcodes to TARGET_UNDEFINED.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants