Skip to main content

Module gas_cost

Module gas_cost 

Source
Expand description

Per-basic-block gas cost model (JAR v0.8.0).

Simulates a CPU pipeline to compute gas cost for a basic block. Cost = max(simulation_cycles - 3, 1).

Pipeline model:

  • Reorder buffer: max 32 entries
  • 4 decode slots per cycle, 5 dispatch slots per cycle
  • Execution units: ALU:4, LOAD:4, STORE:4, MUL:1, DIV:1

Structs§

FastCost
Compact instruction cost for the fast simulator.

Constants§

DEFAULT_MEM_CYCLES
Compute FastCost from raw register bytes (no Args enum needed). For branches, extracts target from raw code bytes. Default load/store latency (L2 cache hit baseline).

Functions§

fast_cost_from_decoded
Compute FastCost using pre-decoded branch target from Args.
fast_cost_from_raw
fast_cost_lut
Compute FastCost via lookup table — replaces the 256-arm match dispatch with a single array access + lightweight mask computation.
fast_cost_lut_regs
Like fast_cost_lut but takes pre-extracted register bytes to avoid re-reading code[pc+1] and code[pc+2] (already decoded by the caller).
feed_gas_direct
Feed the gas simulator directly from raw register bytes, skipping FastCost construction. Returns (is_terminator, is_branch_or_special) — the caller uses is_branch_or_special to fall back to the full path for rare cases.
gas_cost_for_block
Compute gas cost for a basic block starting at start_pc. Returns max(simulation_cycles - 3, 1).
gas_cost_for_block_decoded
gas_cost_for_block_fast
Fast gas cost computation using bitmask-based pipeline simulator.
skip_distance
Compute skip distance (bytes to next instruction start).