#[repr(u8)]pub enum Opcode {
Show 53 variants
ADD = 0,
ADDI = 1,
SUB = 2,
XOR = 3,
OR = 4,
AND = 5,
SLL = 6,
SRL = 7,
SRA = 8,
SLT = 9,
SLTU = 10,
MUL = 11,
MULH = 12,
MULHU = 13,
MULHSU = 14,
DIV = 15,
DIVU = 16,
REM = 17,
REMU = 18,
LB = 19,
LH = 20,
LW = 21,
LBU = 22,
LHU = 23,
SB = 24,
SH = 25,
SW = 26,
BEQ = 27,
BNE = 28,
BLT = 29,
BGE = 30,
BLTU = 31,
BGEU = 32,
JAL = 33,
JALR = 34,
AUIPC = 35,
LUI = 36,
ECALL = 37,
EBREAK = 38,
ADDW = 39,
SUBW = 40,
SLLW = 41,
SRLW = 42,
SRAW = 43,
LWU = 44,
LD = 45,
SD = 46,
MULW = 47,
DIVW = 48,
DIVUW = 49,
REMW = 50,
REMUW = 51,
UNIMP = 52,
}Expand description
An opcode (short for “operation code”) specifies the operation to be performed by the processor.
In the context of the RISC-V ISA, an opcode specifies which operation (i.e., addition, subtraction, multiplication, etc.) to perform on up to three operands such as registers, immediates, or memory addresses.
While the SP1 zkVM targets the RISC-V ISA, it uses a custom instruction encoding that uses a different set of opcodes. The main difference is that the SP1 zkVM encodes register operations and immediate operations as the same opcode. For example, the RISC-V opcodes ADD and ADDI both become ADD inside the SP1 zkVM. We utilize flags inside the instruction itself to distinguish between the two.
Refer to the “RV32I Reference Card” here for more details.
Variants§
ADD = 0
rd ← rs1 + rs2, pc ← pc + 4
ADDI = 1
rd ← rs1 + imm, pc ← pc + 4
SUB = 2
rd ← rs1 - rs2, pc ← pc + 4
XOR = 3
rd ← rs1 ^ rs2, pc ← pc + 4
OR = 4
rd ← rs1 | rs2, pc ← pc + 4
AND = 5
rd ← rs1 & rs2, pc ← pc + 4
SLL = 6
rd ← rs1 << rs2, pc ← pc + 4
SRL = 7
rd ← rs1 >> rs2 (logical), pc ← pc + 4
SRA = 8
rd ← rs1 >> rs2 (arithmetic), pc ← pc + 4
SLT = 9
rd ← (rs1 < rs2) ? 1 : 0 (signed), pc ← pc + 4
SLTU = 10
rd ← (rs1 < rs2) ? 1 : 0 (unsigned), pc ← pc + 4
MUL = 11
rd ← rs1 * rs2 (signed), pc ← pc + 4
MULH = 12
rd ← rs1 * rs2 (half), pc ← pc + 4
MULHU = 13
rd ← rs1 * rs2 (half unsigned), pc ← pc + 4
MULHSU = 14
rd ← rs1 * rs2 (half signed unsigned), pc ← pc + 4
DIV = 15
rd ← rs1 / rs2 (signed), pc ← pc + 4
DIVU = 16
rd ← rs1 / rs2 (unsigned), pc ← pc + 4
REM = 17
rd ← rs1 % rs2 (signed), pc ← pc + 4
REMU = 18
rd ← rs1 % rs2 (unsigned), pc ← pc + 4
LB = 19
rd ← sx(m8(rs1 + imm)), pc ← pc + 4
LH = 20
rd ← sx(m16(rs1 + imm)), pc ← pc + 4
LW = 21
rd ← sx(m32(rs1 + imm)), pc ← pc + 4
LBU = 22
rd ← zx(m8(rs1 + imm)), pc ← pc + 4
LHU = 23
rd ← zx(m16(rs1 + imm)), pc ← pc + 4
SB = 24
m8(rs1 + imm) ← rs2[7:0], pc ← pc + 4
SH = 25
m16(rs1 + imm) ← rs2[15:0], pc ← pc + 4
SW = 26
m32(rs1 + imm) ← rs2[31:0], pc ← pc + 4
BEQ = 27
pc ← pc + ((rs1 == rs2) ? imm : 4)
BNE = 28
pc ← pc + ((rs1 != rs2) ? imm : 4)
BLT = 29
pc ← pc + ((rs1 < rs2) ? imm : 4) (signed)
BGE = 30
pc ← pc + ((rs1 >= rs2) ? imm : 4) (signed)
BLTU = 31
pc ← pc + ((rs1 < rs2) ? imm : 4) (unsigned)
BGEU = 32
pc ← pc + ((rs1 >= rs2) ? imm : 4) (unsigned)
JAL = 33
rd ← pc + 4, pc ← pc + imm
JALR = 34
rd ← pc + 4, pc ← (rs1 + imm) & ∼1
AUIPC = 35
rd ← pc + imm, pc ← pc + 4
LUI = 36
rd ← imm, pc ← pc + 4
ECALL = 37
Transfer control to the ecall handler.
EBREAK = 38
Transfer control to the debugger.
ADDW = 39
rd ← rs1 + rs2, pc ← pc + 4
SUBW = 40
rd ← rs1 - rs2, pc ← pc + 4
SLLW = 41
rd ← rs1 << rs2, pc ← pc + 4
SRLW = 42
rd ← rs1 >> rs2 (logical), pc ← pc + 4
SRAW = 43
rd ← rs1 >> rs2 (arithmetic), pc ← pc + 4
LWU = 44
rd ← sx(m32(rs1 + imm)), pc ← pc + 4
LD = 45
rd ← sx(m8(rs1 + imm)), pc ← pc + 4
SD = 46
m8(rs1 + imm) ← rs2[7:0], pc ← pc + 4
MULW = 47
rd ← rs1 + imm, pc ← pc + 4
DIVW = 48
rd ← rs1 / rs2 (signed), pc ← pc + 4
DIVUW = 49
rd ← rs1 / rs2 (unsigned), pc ← pc + 4
REMW = 50
rd ← rs1 % rs2 (signed), pc ← pc + 4
REMUW = 51
rd ← rs1 % rs2 (unsigned), pc ← pc + 4
UNIMP = 52
Unimplemented instruction.
Implementations§
Source§impl Opcode
impl Opcode
Sourcepub fn instruction_type(self) -> (InstructionType, Option<InstructionType>)
pub fn instruction_type(self) -> (InstructionType, Option<InstructionType>)
Returns the instruction type for the opcode.
Trait Implementations§
Source§impl DeepSizeOf for Opcode
impl DeepSizeOf for Opcode
Source§fn deep_size_of_children(&self, context: &mut Context) -> usize
fn deep_size_of_children(&self, context: &mut Context) -> usize
Source§fn deep_size_of(&self) -> usize
fn deep_size_of(&self) -> usize
Source§impl<'de> Deserialize<'de> for Opcode
impl<'de> Deserialize<'de> for Opcode
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<Opcode> for ByteOpcode
impl From<Opcode> for ByteOpcode
Source§impl Ord for Opcode
impl Ord for Opcode
Source§impl PartialOrd for Opcode
impl PartialOrd for Opcode
impl Copy for Opcode
impl Eq for Opcode
impl StructuralPartialEq for Opcode
Auto Trait Implementations§
impl Freeze for Opcode
impl RefUnwindSafe for Opcode
impl Send for Opcode
impl Sync for Opcode
impl Unpin for Opcode
impl UnsafeUnpin for Opcode
impl UnwindSafe for Opcode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<Challenger, A> FromChallenger<Challenger, A> for Challengerwhere
Challenger: Clone,
impl<Challenger, A> FromChallenger<Challenger, A> for Challengerwhere
Challenger: Clone,
fn from_challenger(challenger: &Challenger, _backend: &A) -> Challenger
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Separable for Twhere
T: Display,
impl<T> Separable for Twhere
T: Display,
Source§fn separate_by_policy(&self, policy: SeparatorPolicy<'_>) -> String
fn separate_by_policy(&self, policy: SeparatorPolicy<'_>) -> String
SeparatorPolicy. Read moreSource§fn separate_with_commas(&self) -> String
fn separate_with_commas(&self) -> String
Source§fn separate_with_spaces(&self) -> String
fn separate_with_spaces(&self) -> String
Source§fn separate_with_dots(&self) -> String
fn separate_with_dots(&self) -> String
Source§fn separate_with_underscores(&self) -> String
fn separate_with_underscores(&self) -> String
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.