Execution unit requirements for an instruction.
Constructor
Jar.JAVM.ExecUnits.mk
Fields
alu : Nat
load : Nat
store : Nat
mul : Nat
div : Nat
Per-basic-block gas metering simulates a pipelined processor with 4-wide decode, out-of-order execution, and 5 execution units (4 ALU, 4 LOAD, 4 STORE, 1 MUL, 1 DIV). Each instruction has a cycle latency, decode slot cost, and execution unit requirements.
Jar.JAVM.ExecUnits : TypeJar.JAVM.ExecUnits : Type
Execution unit requirements for an instruction.
Jar.JAVM.ExecUnits.mk
alu : Nat
load : Nat
store : Nat
mul : Nat
div : Nat
Jar.JAVM.InstrCost : TypeJar.JAVM.InstrCost : Type
Result of instruction cost analysis.
Jar.JAVM.InstrCost.mk
cycles : Nat
decodeSlots : Nat
execUnits : Jar.JAVM.ExecUnits
destRegs : Array Nat
srcRegs : Array Nat
isTerminator : Bool
isMoveReg : Bool
Jar.JAVM.branchCost (code bitmask : ByteArray) (targetPC : Nat) : NatJar.JAVM.branchCost (code bitmask : ByteArray) (targetPC : Nat) : Nat
Branch cost 𝔟: 1 if target is unlikely(2) or trap(0), else 20.
Jar.JAVM.instructionCost (code bitmask : ByteArray) (pc : Nat) (memCycles : Nat := 25) : Jar.JAVM.InstrCostJar.JAVM.instructionCost (code bitmask : ByteArray) (pc : Nat) (memCycles : Nat := 25) : Jar.JAVM.InstrCost
Instruction cost lookup. Returns cost info based on opcode. Uses code/bitmask for branch target lookup.
The full pipeline gas model simulates an out-of-order processor with a reorder buffer (ROB), tracking instruction decode, dispatch, execution, and retirement. This is the reference model — it produces the same results as single-pass for the rv64em ISA but at higher computational cost.
Jar.JAVM.RobEntry : TypeJar.JAVM.RobEntry : Type
Reorder buffer entry.
Jar.JAVM.RobEntry.mk
state : Jar.JAVM.RobState
cyclesLeft : Nat
deps : Array Nat
destRegs : Array Nat
execUnits : Jar.JAVM.ExecUnits
Jar.JAVM.RobState : TypeJar.JAVM.RobState : Type
ROB entry state.
dec : Jar.JAVM.RobState
wait : Jar.JAVM.RobState
exe : Jar.JAVM.RobState
fin : Jar.JAVM.RobState
Jar.JAVM.GasSimState : TypeJar.JAVM.GasSimState : Type
Pipeline simulation state.
Jar.JAVM.GasSimState.mk
ι : Option Nat
cycles : Nat
remainingDecodeSlots : Nat
remainingStartSlots : Nat
remainingExecUnits : Jar.JAVM.ExecUnits
rob : Array Jar.JAVM.RobEntry
Can we decode the next instruction?
Decode the next instruction and update state.
Can we dispatch an instruction?
Dispatch the oldest ready instruction.
Find index of oldest WAIT entry that is ready to dispatch.
Check if all dependencies of a ROB entry are finished.
Advance one cycle: increment counter, reset slots, tick EXE entries.
Check if ROB is all finished (or empty).
Jar.JAVM.gasCostForBlockFull (code bitmask : ByteArray) (startPC : Nat) : NatJar.JAVM.gasCostForBlockFull (code bitmask : ByteArray) (startPC : Nat) : Nat
Compute gas cost for a basic block using full pipeline simulation.
Returns max(cycles - 3, 1).
In jar1, gas costs are computed by the single-pass model — an O(n) pipeline simulation that tracks per-register readiness cycles. This omits execution unit contention (subsumed by decode throughput for the rv64em ISA) and dispatch width limits, yielding equivalent results with significantly less computation.
Jar.JAVM.GasSimStateSP : TypeJar.JAVM.GasSimStateSP : Type
Single-pass simulation state.
Jar.JAVM.GasSimStateSP.mk
ι : Option Nat
cycle : Nat
decodeUsed : Nat
regDone : Array Nat
maxDone : Nat
Jar.JAVM.gasCostForBlockSinglePass (code bitmask : ByteArray) (startPC : Nat) (memCycles : Nat := 25) : NatJar.JAVM.gasCostForBlockSinglePass (code bitmask : ByteArray) (startPC : Nat) (memCycles : Nat := 25) : Nat
Compute gas cost for a basic block using the single-pass model.
Returns max(maxDone - 3, 1).