openvm_custom_insn

Macro custom_insn_i

Source
custom_insn_i!() { /* proc-macro */ }
Expand description

Custom RISC-V instruction macro for the zkVM.

This macro is used to define custom I-type RISC-V instructions for the zkVM. Usage:

custom_insn_r!(
    opcode = OPCODE,
    funct3 = FUNCT3,
    rd = InOut x0,
    rs1 = In rs1,
    imm = Const 123
);

Here, opcode, funct3 are the opcode and funct3 fields of the RISC-V instruction. rd, rs1, and imm are the destination register, source register 1, and immediate value respectively. The In, Out, InOut, and Const keywords are required to specify the type of the register arguments. They translate to in(reg), out(reg), inout(reg), and const respectively, and mean

  • “read the value from this variable” before execution (In),
  • “write the value to this variable” after execution (Out),
  • “read the value from this variable, then write it back to the same variable” after execution (InOut), and
  • “use this constant value” (Const).

The imm argument is required to be a constant value.