ed255 / riscu-jolt

RISCU emulator and zk circuit simulator as a reference for a Jolt implementation
23 stars 1 forks source link

Implement virtual instructions and virtual registers #25

Closed ed255 closed 1 year ago

ed255 commented 1 year ago

See Jolt 6.1

Jolt defines a few virtual instructions that are not part of RISC-V:

It also defines a virtual set of registers used by the virtual instructions:

Since virtual instructions don't correspond to the original program, Jolt mentions having two program counters, one to keep track of the RISCV PC, and the other to keep track of all instructions (including virtual ones).

I believe we should also implement the virtual instructions in the emulator. We could do the following:

  1. Take the source program (as a list of instructions) and transform it to another program with the virtual instructions (by replacing div, rem, etc. by their virtual code)
  2. While doing 1, build a map (in the form of a table) from original PC to virtual PC
  3. The emulator will now work on the extended program and will have pc and pc_virt. Each non-virtual instruction increments both pc and pc_virt, and virtual instructions only increment pc_virt.
  4. To fetch instructions we use pc with the mapping we built in point 2, to obtain the instruction from the extended program.