Skip to main content

Module regs

Module regs 

Source
Expand description

Register state: 15 general-purpose 64-bit registers + PC.

PVM2 is RV64E — a 16-register integer base (x0x15) — so it has the full 15 GPRs (x1, x2, x5x15, plus x3, x4) with x0 hardwired to zero, plus an instruction pointer. x3/x4 map to the two high slots (13, 14) so the 13 commonly-used registers keep slots 0..=12; the recompiler holds those 13 in host registers and spills x3/x4 to memory (see reg_is_spilled). Only x16x31 (which do not exist in the E base) remain reserved.

Structs§

Regs
Full register state: 15 GPRs + PC.

Enums§

RegClass
Classification of a 5-bit RV register index in PVM2.

Constants§

REG_COUNT
Number of general-purpose registers.
REG_SLOT_LUT
32-entry const-folded copy of reg_slot_or_ff for the recompiler’s codegen/gas hot path — a single load beats the range-match (the profiler showed the match at ~8.8% of compile). Generated from reg_class, so it cannot drift from the canonical classification.

Functions§

reg_class
Classify a 5-bit RV register index (low 5 bits of x). See RegClass.
reg_is_reserved
True iff x is a reserved register (x16..x31 — they do not exist in the RV64E base) — as opposed to x0, which also lacks a slot but is valid. Drives the reserved-encoding (illegal) check in both engines.
reg_is_spilled
True iff x is a spilled register — x3 or x4, the two GPRs that map to the high slots (13, 14). They are real, fully-valid registers (the interpreter executes them as ordinary GPRs), but the x86-64 recompiler’s host register file is exhausted by the other 13 slots, so it holds x3/x4 in memory and materialises them per access. The recompiler uses this to route an x3/x4 instruction to its cold spill path; the gas model uses it to charge the memory-spill cost.
reg_slot_or_ff
PVM2 GPR slot (0..=14) for x, or 0xFF if x has no slot — x0 (hardwired zero) or a reserved register (x16..x31). The gas simulator reads 0xFF as “no dependency / no write”; both engines’ gas paths use this (the recompiler via the const-folded REG_SLOT_LUT) so gas agrees bit-for-bit. Note 0xFF conflates x0 with reserved — use reg_is_reserved when that distinction matters.