Skip to main content

Module predecode

Module predecode 

Source
Expand description

Single-pass predecode for PVM2 (RV+C+custom-0) byte streams.

Walks the code from PC=0, decoding every instruction and recording:

  • Decoded instruction array (Vec<RvPreDecodedInst>): one entry per static instruction, with PC + next-PC pre-computed so the codegen loop doesn’t redo decoding.
  • Gas-block-start markers: PC=0 plus every PC immediately following a terminator. The strict post-terminator set is sound because runtime jalr targets are validated to be block starts (the linker injects a Fallthrough terminator before any branch target that isn’t naturally post-terminator).

Per-block gas costs are computed by running the pipeline simulator in crate::gas_cost::rv_gas_cost_for_block once per basic block; the results are stored in Predecode::block_costs.

Structs§

Predecode
Output of the predecode pass over an RV+C+custom-0 code section.
RvGasMeta
Pre-resolved metadata used by the per-block gas accountant. The fields are computed once at decode time so the gas hot path does not have to re-match the Inst variant on each invocation.
RvPreDecodedInst
One decoded instruction with its PC, next-PC, block-start flag, and pre-resolved gas metadata.

Functions§

is_ecall_block
ecall.jar / ecalli — the instructions that form their own (singleton) gas block, charged dynamically at dispatch rather than by a static block preamble. A cost == 0 block start marks one.
is_terminator
Block-terminating instructions: anything that can leave the fall-through path. Used to mark the next instruction as a gas-block start.
predecode
Predecode an entire RV+C+custom-0 code section.
predecode_rv_with_mem_cycles
Like predecode but takes an explicit mem_cycles parameter. Used by callers that want to override the default L2-hit latency (e.g. for tier-specific gas modeling).