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§
- Fast
Cost - 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_lutbut 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).