#[repr(C)]pub struct Instruction {
pub opcode: Opcode,
pub op_a: u8,
pub op_b: u32,
pub op_c: u32,
pub imm_b: bool,
pub imm_c: bool,
}
Expand description
RISC-V 32IM Instruction.
The structure of the instruction differs from the RISC-V ISA. We do not encode the instructions as 32-bit words, but instead use a custom encoding that is more friendly to decode in the SP1 zkVM.
Fields§
§opcode: Opcode
The operation to execute.
op_a: u8
The first operand.
op_b: u32
The second operand.
op_c: u32
The third operand.
imm_b: bool
Whether the second operand is an immediate value.
imm_c: bool
Whether the third operand is an immediate value.
Implementations§
Source§impl Instruction
impl Instruction
Sourcepub const fn from_r_type(opcode: Opcode, dec_insn: &RType) -> Self
pub const fn from_r_type(opcode: Opcode, dec_insn: &RType) -> Self
Create a new Instruction
from an R-type instruction.
Sourcepub const fn from_i_type(opcode: Opcode, dec_insn: &IType) -> Self
pub const fn from_i_type(opcode: Opcode, dec_insn: &IType) -> Self
Create a new Instruction
from an I-type instruction.
Sourcepub const fn from_i_type_shamt(opcode: Opcode, dec_insn: &ITypeShamt) -> Self
pub const fn from_i_type_shamt(opcode: Opcode, dec_insn: &ITypeShamt) -> Self
Create a new Instruction
from an I-type instruction with a shamt.
Sourcepub const fn from_s_type(opcode: Opcode, dec_insn: &SType) -> Self
pub const fn from_s_type(opcode: Opcode, dec_insn: &SType) -> Self
Create a new Instruction
from an S-type instruction.
Sourcepub const fn from_b_type(opcode: Opcode, dec_insn: &BType) -> Self
pub const fn from_b_type(opcode: Opcode, dec_insn: &BType) -> Self
Create a new Instruction
from a B-type instruction.
Sourcepub const fn unimp() -> Self
pub const fn unimp() -> Self
Create a new Instruction
that is not implemented.
Sourcepub const fn is_r_type(&self) -> bool
pub const fn is_r_type(&self) -> bool
Returns if the Instruction
is an R-type instruction.
Sourcepub const fn is_i_type(&self) -> bool
pub const fn is_i_type(&self) -> bool
Returns whether the Instruction
is an I-type instruction.
Sourcepub fn r_type(&self) -> (Register, Register, Register)
pub fn r_type(&self) -> (Register, Register, Register)
Decode the Instruction
in the R-type format.
Sourcepub fn j_type(&self) -> (Register, u32)
pub fn j_type(&self) -> (Register, u32)
Decode the Instruction
in the J-type format.
Sourcepub fn u_type(&self) -> (Register, u32)
pub fn u_type(&self) -> (Register, u32)
Decode the Instruction
in the U-type format.
Source§impl Instruction
impl Instruction
Sourcepub const fn new(
opcode: Opcode,
op_a: u8,
op_b: u32,
op_c: u32,
imm_b: bool,
imm_c: bool,
) -> Self
pub const fn new( opcode: Opcode, op_a: u8, op_b: u32, op_c: u32, imm_b: bool, imm_c: bool, ) -> Self
Create a new [RiscvInstruction
].
Sourcepub const fn is_alu_instruction(&self) -> bool
pub const fn is_alu_instruction(&self) -> bool
Returns if the instruction is an ALU instruction.
Sourcepub const fn is_ecall_instruction(&self) -> bool
pub const fn is_ecall_instruction(&self) -> bool
Returns if the instruction is a ecall instruction.
Sourcepub const fn is_memory_load_instruction(&self) -> bool
pub const fn is_memory_load_instruction(&self) -> bool
Returns if the instruction is a memory load instruction.
Sourcepub const fn is_memory_store_instruction(&self) -> bool
pub const fn is_memory_store_instruction(&self) -> bool
Returns if the instruction is a memory store instruction.
Sourcepub const fn is_branch_instruction(&self) -> bool
pub const fn is_branch_instruction(&self) -> bool
Returns if the instruction is a branch instruction.
Sourcepub const fn is_jump_instruction(&self) -> bool
pub const fn is_jump_instruction(&self) -> bool
Returns if the instruction is a jump instruction.
Sourcepub const fn is_auipc_instruction(&self) -> bool
pub const fn is_auipc_instruction(&self) -> bool
Returns if the instruction is an auipc instruction.
Sourcepub const fn is_divrem_instruction(&self) -> bool
pub const fn is_divrem_instruction(&self) -> bool
Returns if the instruction is a divrem instruction.
Sourcepub const fn is_ebreak_instruction(&self) -> bool
pub const fn is_ebreak_instruction(&self) -> bool
Returns if the instruction is an ebreak instruction.
Sourcepub const fn is_unimp_instruction(&self) -> bool
pub const fn is_unimp_instruction(&self) -> bool
Returns if the instruction is an unimplemented instruction.
Trait Implementations§
Source§impl Clone for Instruction
impl Clone for Instruction
Source§fn clone(&self) -> Instruction
fn clone(&self) -> Instruction
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for Instruction
impl Debug for Instruction
Source§impl<'de> Deserialize<'de> for Instruction
impl<'de> Deserialize<'de> for Instruction
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 Serialize for Instruction
impl Serialize for Instruction
impl Copy for Instruction
Auto Trait Implementations§
impl Freeze for Instruction
impl RefUnwindSafe for Instruction
impl Send for Instruction
impl Sync for Instruction
impl Unpin for Instruction
impl UnwindSafe for Instruction
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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 more