Skip to main content

Opcode

Enum Opcode 

#[repr(i16)]
pub enum Opcode {
Show 29 variants Nop = 0, Add = 1, Sub = 2, Mul = 3, Div = 4, Rem = 5, Min = 6, Max = 7, Cmp3 = 8, Neg = 9, Abs = 10, Addi = 11, Shl = 12, Shr = 13, Lw = 14, Sw = 15, Jal = 16, Jalr = 17, Br3 = 18, Brz = 19, Halt = 20, Lt = 21, St = 22, Brn = 23, Brp = 24, Csrr = 25, Csrw = 26, Tret = 27, Ecall = 28,
}
Expand description

Every defined operation.

Discriminants are the encoded opcode values. Negative values are reserved for future extension and never appear here.

Variants§

§

Nop = 0

do nothing; pc <- pc + 1

§

Add = 1

rd <- rs1 + rs2

§

Sub = 2

rd <- rs1 - rs2

§

Mul = 3

rd <- rs1 * rs2

§

Div = 4

rd <- rs1 / rs2, truncating

§

Rem = 5

rd <- rs1 % rs2

§

Min = 6

rd <- per-trit minimum of rs1, rs2; Kleene AND

§

Max = 7

rd <- per-trit maximum of rs1, rs2; Kleene OR

§

Cmp3 = 8

rd <- -1, 0 or +1 as rs1 <, ==, > rs2

§

Neg = 9

rd <- -rs1; also the per-trit logical NOT

§

Abs = 10

rd <- |rs1|; total, because the range is symmetric

§

Addi = 11

rd <- rs1 + imm

§

Shl = 12

rd <- rs1 * 3^imm, an exact trit shift

§

Shr = 13

rd <- rs1 / 3^imm, rounded to nearest

§

Lw = 14

rd <- memory word at rs1 + imm trytes

§

Sw = 15

memory word at rs1 + imm trytes <- rd

§

Jal = 16

rd <- pc + 1; pc <- pc + imm

§

Jalr = 17

rd <- pc + 1; pc <- rs1 + imm

§

Br3 = 18

three-way: pc <- pc + imm if rs1 > 0; pc <- pc - imm if rs1 < 0; pc <- pc + 1 if rs1 == 0

§

Brz = 19

pc <- pc + imm if rs1 == 0, else pc <- pc + 1

§

Halt = 20

stop execution

§

Lt = 21

rd <- memory tryte at rs1 + imm trytes; no alignment requirement

§

St = 22

memory tryte at rs1 + imm trytes <- rd; no alignment requirement

§

Brn = 23

pc <- pc + imm if rs1 < 0, else pc <- pc + 1

§

Brp = 24

pc <- pc + imm if rs1 > 0, else pc <- pc + 1

§

Csrr = 25

rd <- control register imm; supervisor or machine only

§

Csrw = 26

control register imm <- rs1; supervisor or machine only

§

Tret = 27

pc <- tepc; priv <- tpriv; supervisor or machine only

§

Ecall = 28

trap to tvec with cause Ecall

Implementations§

§

impl Opcode

pub const fn from_value(v: i64) -> Result<Opcode, DecodeError>

Decodes an opcode field value.

A match, so dispatch compiles to a jump table rather than a linear scan of [TABLE].

pub const fn value(self) -> i64

The encoded value.

pub const fn mnemonic(self) -> &'static str

The assembly mnemonic.

pub const fn format(self) -> Format

Which operands this instruction takes.

pub const fn imm_unit(self) -> ImmUnit

What this instruction’s immediate counts.

pub const fn summary(self) -> &'static str

One-line description.

Trait Implementations§

§

impl Clone for Opcode

§

fn clone(&self) -> Opcode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Copy for Opcode

§

impl Debug for Opcode

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Eq for Opcode

§

impl Hash for Opcode

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for Opcode

§

fn eq(&self, other: &Opcode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl StructuralPartialEq for Opcode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.