Field Operations
Miden assembly provides a set of instructions which can perform operations with raw field elements. These instructions are described in the tables below.
While most operations place no restrictions on inputs, some operations expect inputs to be binary values, and fail if executed with non-binary inputs.
For instructions where one or more operands can be provided as immediate parameters (e.g., add
and add.b
), we provide stack transition diagrams only for the non-immediate version. For the immediate version, it can be assumed that the operand with the specified name is not present on the stack.
Assertions and tests
Instruction | Stack_input | Stack_output | Notes |
---|---|---|---|
assert - (1 cycle) | [a, ...] | [...] | If , removes it from the stack. Fails if |
assertz - (2 cycles) | [a, ...] | [...] | If , removes it from the stack, Fails if |
assert_eq - (2 cycles) | [b, a, ...] | [...] | If , removes them from the stack. Fails if |
assert_eqw - (11 cycles) | [B, A, ...] | [...] | If , removes them from the stack. Fails if |
Arithmetic and Boolean operations
Instruction | Stack_input | Stack_output | Notes |
---|---|---|---|
add - (1 cycle) add.b - (1-2 cycle) | [b, a, ...] | [c, ...] | |
sub - (2 cycles) sub.b - (2 cycles) | [b, a, ...] | [c, ...] | |
mul - (1 cycle) mul.b - (2 cycles) | [b, a, ...] | [c, ...] | |
div - (2 cycles) div.b - (2 cycles) | [b, a, ...] | [c, ...] | Fails if |
neg - (1 cycle) | [a, ...] | [b, ...] | |
inv - (1 cycle) | [a, ...] | [b, ...] | Fails if |
pow2 - (16 cycles) | [a, ...] | [b, ...] | Fails if |
exp.uxx - (9 + xx cycles) exp.b - (9 + log2(b) cycles) | [b, a, ...] | [c, ...] | Fails if xx is outside [0, 63) exp is equivalent to exp.u64 and needs 73 cycles |
not - (1 cycle) | [a, ...] | [b, ...] | Fails if |
and - (1 cycle) | [b, a, ...] | [c, ...] | Fails if |
or - (1 cycle) | [b, a, ...] | [c, ...] | Fails if |
xor - (7 cycles) | [b, a, ...] | [c, ...] | Fails if |
Comparison operations
Instruction | Stack_input | Stack_output | Notes |
---|---|---|---|
eq - (1 cycle) eq.b - (1-2 cycles) | [b, a, ...] | [c, ...] | |
neq - (2 cycle) neq.b - (2-3 cycles) | [b, a, ...] | [c, ...] | |
lt - (17 cycles) | [b, a, ...] | [c, ...] | |
lte - (18 cycles) | [b, a, ...] | [c, ...] | |
gt - (18 cycles) | [b, a, ...] | [c, ...] | |
gte - (19 cycles) | [b, a, ...] | [c, ...] | |
is_odd - (5 cycles) | [a, ...] | [b, ...] | |
eqw - (15 cycles) | [A, B, ...] | [c, A, B, ...] |
Extension Field Operations
Instruction | Stack Input | Stack Output | Notes |
---|---|---|---|
ext2add - (5 cycles) | [b, a, ...] | [c, ...] | |
ext2sub - (7 cycles) | [b, a, ...] | [c, ...] | |
ext2mul - (3 cycles) | [b, a, ...] | [c, ...] | |
ext2div - (11 cycles) | [b, a, ...] | [c, ...] | Fails if |
ext2neg - (4 cycles) | [a, ...] | [b, ...] | |
ext2inv - (8 cycles) | [a, ...] | [b, ...] | Fails if |
where is an irreducible polynomial over for