Crate fidget_bytecode

Crate fidget_bytecode 

Source
Expand description

Tape bytecode format

Fidget’s bytecode is a packed representation of a RegTape. It may be used as the evaluation tape for non-Rust VMs, e.g. an interpreter running on a GPU.

The format is not stable; it may change without notice. It would be wise to dynamically check any interpreter against iter_ops, which associates opcode integers with their names.

The bytecode format is a list of little-endian u32 words, representing tape operations in forward-evaluation order. Each operation in the tape maps to two words, though the second word is not always used. Having a fixed-length representation makes it easier to iterate both forwards (for evaluation) and backwards (for simplification).

The first two words are always 0xFFFF_FFFF 0x0000_0000, and the last two words are always 0xFFFF_FFFF 0xFFFF_FFFF. Note that this is equivalent to an operation with opcode 0xFF; this special opcode may also be used with user-defined semantics, as long as the immediate is not either reserved value.

§Register-only operations

Register-only operations (i.e. opcodes without an immediate f32 or u32) are packed into a single u32 as follows:

ByteValue
0opcode
1output register
2first input register
3second input register

Depending on the opcode, the input register bytes may not be used.

The second word is always 0xFF000000

§Operations with an f32 immediate

Operations with an f32 immediate are packed into two u32 words. The first word is similar to before:

ByteValue
0opcode
1output register
2first input register
3not used

The second word is the f32 reinterpreted as a u32.

§Operations with an u32 immediate

Operations with a u32 immediate (e.g. Load) are also packed into two u32 words. The first word is what you’d expect:

ByteValue
0opcode
1input or output register
2not used
3not used

The second word is the u32 immediate.

§Opcode values

Opcode values are generated automatically from BytecodeOp values, which are one-to-one with RegOp variants.

Structs§

Bytecode
Serialized bytecode for external evaluation

Enums§

BytecodeOp
RegOp discriminant value

Functions§

iter_ops
Iterates over opcode (names, value) tuples, with names in CamelCase