Expand description
RV64E-subset instruction encoders — the single source the generator and the decode round-trip test both drive off.
The two existing x3/x4 test files (javm-recompiler-x86/tests/x3_x4_spill.rs
and javm-bench/tests/x3_x4_differential.rs) each hand-rolled a handful of
ad-hoc encoders. This centralizes them and extends to the full implemented
ISA via the OPS spec table, validated against javm_exec::decode in the
tests below (every op must round-trip to a non-Reserved instruction).
Structs§
- OpSpec
- One implemented instruction: enough to encode it from operands.
Enums§
Constants§
- HALT
ecalli 0— HostCall(0), the clean trampoline halt both engines surface asexit_reason = 4. Appended by the replay harness, not stored in vectors.- OPS
- Every instruction family the generator can emit. Validated against the
decoder in
round_trip_all_ops(each must decode to a non-Reservedinstruction). Excludes terminators (ecalli/trap/fallthrough),fence, and anything reserved (SYSTEM, x3/x4, x16–31). - SIG_
BASE_ REG - Scratch base register for the signature stores. x3 is spilled — it is not in
the captured set (slots 0..=12) and is invocation-local (dropped at exit), so
clobbering it is invisible to the differential, and both engines agree on
x3/x4 spill semantics (the
x3_x4_differentialnet). Using it as the store base leaves every captured register untouched, so the stored values are the program’s exact post-body register file. - SIG_
BYTES - Byte length of the register signature: one little-endian
u64per captured slot. Fits in a single page and inSCRATCHPAD_HEAD_LEN(128). - SIG_
REGS - Number of host-mapped register slots captured by the signature (slots
0..=12 → x1, x2, x5, x6, x7, x8–x15; see
crate::oracle::slot_to_xreg). - SIG_
XREGS - The x-register stored at signature slot
i(the inverse ofjavm_exec::regs::reg_slot_or_ff, matchingcrate::oracle::slot_to_xreg). Slot 7 = x10 (the former foldreturn_value). The epilogue stores each at byte offset8*iof the signature region.
Functions§
- add
- addi
- beq
- div
- enc
- Pack instruction words into a little-endian byte stream.
- encode_
op - Encode
opwith the given operands. Operands not used by the format are ignored (e.g.rs2forFmt::I,immforFmt::Unary). For shift formats the low bits ofimmare the shift amount; forFmt::U,immis the 20-bit upper immediate. - ld
- li64
- Materialize an arbitrary
valueintordusing onlyrd(no scratch register): build MSB-first in 11-bit chunks viaaddi/slli. Eachaddiadds an 11-bit (always non-negative) chunk into freshly-zeroed low bits. - lui
- mulhsu
- rem
- rori
- sd
- signature_
epilogue - Emit the signature epilogue (no terminator): materialize
sig_baseinto the scratch base register, thensdeach captured register tosig_base + 8*i.sig_baseis the guest VA the scratchpad (slot[0]) DataCap maps at; the guest’s stores CoW the region’s pages, and the host reads the effective bytes back as the run’s lossless register signature (vs the old lossy x10 fold). - slli
- sub
- xor