1 unstable release

Uses new Rust 2024

0.4.1 Sep 8, 2025

#451 in Programming languages

26 downloads per month
Used in fidget

MPL-2.0 license

465KB
10K SLoC

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:

Byte Value
0 opcode
1 output register
2 first input register
3 second 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:

Byte Value
0 opcode
1 output register
2 first input register
3 not 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:

Byte Value
0 opcode
1 input or output register
2 not used
3 not 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.


fidget-bytecode implements a u32 bytecode tape for math expressions.

It is typically used through the fidget crate, which imports it under the bytecode namespace

» Crate » Docs » CI » MPL-2.0

Dependencies

~8.5MB
~166K SLoC