Enum aluvm::isa::BytesOp[][src]

pub enum BytesOp {
Show variants Put(u8Box<ByteStr>, bool), Mov(u8u8), Swp(u8u8), Fill(u8Reg32Reg32Reg32bool), Len(u8RegAReg32), Cnt(u8Reg16Reg16), Eq(u8u8), Con(u8u8, u6, Reg32Reg32), Find(u8u8), Extr(Reg32RegRReg16Reg16), Inj(Reg32RegRReg16Reg16), Join(u8u8u8), Splt(SplitFlagReg32u8u8u8), Ins(InsertFlagReg32u8u8), Del(DeleteFlagRegA2Reg32RegA2Reg32boolboolu8u8), Rev(u8u8),
}
Expand description

Operations on byte strings.

All of these operations either set st0 to false, if an exception occurred during their execution, or do not modify st0 register value. Since each of the exceptions can be predicted with a code run by VM beforehand (unlike for arithmetic exceptions), the absence of st0 value change upon success allows batching multiple string operations and checking their final result, while still maintaining ability to predict/detect which of the operations has failed.

Variants

Put(u8Box<ByteStr>, bool)

Put bytestring into a byte string register

Data are kept in the separate data segment, thus when the instruction is pared from the code segment it knows only data offset and length. If this offset or length exceeds the size of the data segment, the instruction truncates the string to the part that is present in the data segment (or zero-length string if the offset exceeds data segment length) and sets st0 to false. Otherwise, st0 is unaffected.

Mov(u8u8)

Move bytestring value between registers

Swp(u8u8)

Swap bytestring value between registers

Fill(u8Reg32Reg32Reg32bool)

Fill segment of bytestring with specific byte value, setting the length of the string in the destination register to specific value.

The start offset is the least offset from one of the a16 register provided in offset arguments, the end offset is the greatest one. If any of the offsets exceeds the length of the string in the destination register, operation behaviour is defined by the provided boolean flag:

  • if the flag is true, the string length is extended to the largest of the offsets and all bytes between previous string length and start offset are filled with zeros, setting st0 value to false;
  • if the flag is false, the destination register is set to None and st0 is set to false.

If both of the offsets lie within the length of the string, the st0 register value is not modified.

If any of the offsets or value registers are unset, sets st0 to false and does not change destination value.

Len(u8RegAReg32)

Put length of the string into the destination register.

If the string register is empty, or destination register can’t fit the length, sets st0 to false and destination register to None.

Cnt(u8Reg16Reg16)

Count number of byte occurrences from the a8 register within the string and stores that value into destination a16 register.

If the string register is empty, or destination register can’t fit the length, sets st0 to false and destination register to None.

If the source byte value register is uninitialized, sets destination register to None and st0 to false.

Eq(u8u8)

Check equality of two strings, putting result into st0.

If both of strings are uninitialized, st0 assigned true value.

Con(u8u8, u6, Reg32Reg32)

Compute offset and length of the nth fragment shared between two strings (“conjoint fragment”), putting it to the destination u16 registers. If strings have no conjoint fragment sets destination to None.

Find(u8u8)

Count number of occurrences of one string within another putting result to a16[1],

If the first or the second string is None, sets st0 to false and a16[1] to None.

If the number of occurrences is u16::MAX + 1, sets a16[1] to u16::MAX and st0 to false.

Extr(Reg32RegRReg16Reg16)

Extract byte string slice into general r register. The length of the extracted string is equal to the bit dimension of the destination register. If the bit size of the destination plus the initial offset exceeds string length the rest of the destination register bits is filled with zeros and st0 is set to false. Otherwise, st0 value is not modified.

If the source string register - or offset register is uninitialized, sets destination to uninitialized state and st0 to false.

Inj(Reg32RegRReg16Reg16)

Inject general R register value at a given position to string register, replacing value of the corresponding bytes. If the insert offset is larger than the current length of the string, the length is extended and all bytes inbetween previous length and the new length are initialized with zeros. If the length of the inserted string plus insert offset exceeds the maximum string register length (2^16 bytes), than the destination register is set to None state and st0 is set to false. Otherwise, st0 value is not modified.

Join(u8u8u8)

Join bytestrings from two registers into destination, overwriting its value. If the length of the joined string exceeds the maximum string register length (2^16 bytes), than the destination register is set to None state and st0 is set to false. Otherwise, st0 value is not modified.

Splt(SplitFlagReg32u8u8u8)

Split bytestring at a given offset taken from a16 register into two destination strings, overwriting their value. If offset exceeds the length of the string in the register, than the behaviour is determined by the SplitFlag value.

+--------------------
|       | ....
+--------------------
        ^       ^
        |       +-- Split offset (`offset`)
        +-- Source string length (`src_len`)

`offset == 0`:
  (1) first, second <- None; `st0` <- false
  (2) first <- None, second <- `src_len > 0` ? src : None; `st0` <- false
  (3) first <- None, second <- `src_len > 0` ? src : zero-len; `st0` <- false
  (4) first <- zero-len, second <- `src_len > 0` ? src : zero-len
`offset > 0 && offset < src_len`: `st0` always set to false
  (1) first, second <- None
  (5) first <- short, second <- None
  (6) first <- short, second <- zero-len
  (7) first <- zero-ext, second <- None
  (8) first <- zero-ext, second <- zero-len
`offset = src_len`:
  (1) first, second <- None; `st0` <- false
  (5,7) first <- ok, second <- None; `st0` <- false
  (6,8) first <- ok, second <- zero-len
`offset > src_len`: operation succeeds anyway, `st0` value is not changed

Rule on st0 changes: if at least one of the destination registers is set to None, or offset value exceeds source string length, st0 is set to false; otherwise its value is not modified

Ins(InsertFlagReg32u8u8)

Insert value from one of bytestring register at a given index of other bytestring register, shifting string bytes. If the destination register does not fit the length of the new string, or the offset exceeds the length of destination string operation behaviour is defined by the provided InsertFlag.

+--------------------
|       | ....
+--------------------
        ^       ^
        |       +-- Insert offset (`offset`)
        +-- Destination string length (`dst_len`)

`offset < dst_len && src_len + dst_len > 2^16`:
  (6) Set destination to `None`
  (7) Cut destination string part exceeding `2^16`
  (8) Reduce `src_len` such that it will fit the destination
`offset > dst_len && src_len + dst_len + offset <= 2^16`:
  (1) Set destination to `None`
  (2) Fill destination from `dst_let` to `offset` with zeros
  (3) Use `src_len` instead of `offset`
`offset > dst_len && src_len + dst_len + offset > 2^16`:
  (4) Set destination to `None`
  (5) Fill destination from `dst_let` to `offset` with zeros and cut source string part
      exceeding `2^16`
  (6-8) Use `src_len` instead of `offset` and use flag value from the first section

In all of these cases st0 is set to false. Otherwise, st0 value is not modified.

Del(DeleteFlagRegA2Reg32RegA2Reg32boolboolu8u8)

Delete bytes in a given range, shifting the remaining bytes leftward. The start offset is the least offset from one of the a16 register provided in offset arguments, the end offset is the greatest one. If any of the offsets exceeds the length of the string in the destination register, operation behaviour is defined by the provided DeleteFlag argument.

+----------------------------------
|                   | ....
+----------------------------------
    ^               ^       ^  
    |               |       +-- End offset (`offset_end`)
    |               +-- Source string length (`src_len`)
    +-- Start offset (`offset_start`)

`offset_start > src_len`:
  (1) set destination to `None`
  (2) set destination to zero-length string
`offset_end > src_len && offser_start <= src_len`:
  (1) set destination to `None`
  (3) set destination to the fragment of the string `offset_start..src_len`
  (4) set destination to the fragment of the string `offset_start..src_len` and extend
      its length up to `offset_end - offset_start` with trailing zeros.

flag1 and flag2 arguments indicate whether st0 should be set to false if offset_start > src_len and offset_end > src_len && offser_start <= src_len. In all other cases, st0 value is not modified.

Rev(u8u8)

Revert byte order of the string.

If the source string register is uninitialized, resets destination to the uninitialized state and sets st0 to false.

Trait Implementations

Returns number of bytes which instruction and its argument occupies

Returns range of instruction btecodes covered by a set of operations

Returns byte representing instruction code (without its arguments)

Writes instruction arguments as bytecode, omitting instruction code byte

Reads the instruction from bytecode

If the instruction call or references any external library, returns the call site in that library. Read more

Writes the instruction as bytecode

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

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

ISA Extensions used by the provided instruction set. Read more

Returns computational complexity of the instruction

Executes given instruction taking all registers as input and output. Read more

ISA Extension IDs represented as a standard string (space-separated) Read more

ISA Extension IDs encoded in a standard way (space-separated) Read more

Checks whether provided ISA extension ID is supported by the current instruction set

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.