Enum aluvm::isa::BytesOp [−][src]
pub enum BytesOp {}Show variants
Put(u8, Box<ByteStr>, bool), Mov(u8, u8), Swp(u8, u8), Fill(u8, Reg32, Reg32, Reg32, bool), Len(u8, RegA, Reg32), Cnt(u8, Reg16, Reg16), Eq(u8, u8), Con(u8, u8, u6, Reg32, Reg32), Find(u8, u8), Extr(Reg32, RegR, Reg16, Reg16), Inj(Reg32, RegR, Reg16, Reg16), Join(u8, u8, u8), Splt(SplitFlag, Reg32, u8, u8, u8), Ins(InsertFlag, Reg32, u8, u8), Del(DeleteFlag, RegA2, Reg32, RegA2, Reg32, bool, bool, u8, u8), Rev(u8, u8),
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 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.
Move bytestring value between registers
Swap bytestring value between registers
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, settingst0
value tofalse
; - if the flag is
false
, the destination register is set toNone
andst0
is set tofalse
.
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.
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
.
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
.
Check equality of two strings, putting result into st0
.
If both of strings are uninitialized, st0
assigned true
value.
Compute offset and length of the n
th fragment shared between two strings (“conjoint
fragment”), putting it to the destination u16
registers. If strings have no conjoint
fragment sets destination to None
.
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
.
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
.
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 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.
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(InsertFlag, Reg32, u8, u8)
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.
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.
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
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
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
Auto Trait Implementations
impl RefUnwindSafe for BytesOp
impl UnwindSafe for BytesOp
Blanket Implementations
Mutably borrows from an owned value. Read more