Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
instruction_spec.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstdint>
5#include <optional>
6#include <unordered_map>
7#include <vector>
8
11
12namespace bb::avm2 {
13
14constexpr size_t NUM_OP_DC_SELECTORS = 18;
15
17 struct GasInfo {
18 uint16_t opcode_gas; // Base l2 gas is computed as opcode_gas + addressing_gas
19 uint16_t base_da;
20 uint16_t dyn_l2;
21 uint16_t dyn_da;
22
23 bool operator==(const GasInfo& other) const = default;
24 };
25
26 // This builder is used to generate the register information based on the number of inputs and outputs.
27 // Output will always come last.
29 public:
31 RegisterInfo& add_inputs(const std::vector<std::optional<ValueTag>>& tags);
33
34 size_t num_inputs() const { return inputs.size(); }
35 size_t num_outputs() const { return has_output ? 1 : 0; }
36 size_t total_registers() const { return num_inputs() + num_outputs(); }
37
38 // Given a register index, returns if the register is active for this instruction
39 bool is_active(size_t index) const;
40 // Given a register index, returns if the register is used for writing to memory
41 bool is_write(size_t index) const;
42 // Given a register index, returns if the tag check is needed.
43 bool need_tag_check(size_t index) const;
44 // Given a register index, returns the expected tag for this instruction.
45 std::optional<ValueTag> expected_tag(size_t index) const;
46
47 static constexpr auto ANY_TAG = std::nullopt;
48
49 bool operator==(const RegisterInfo& other) const = default;
50
51 private:
53 bool has_output = false;
54 };
55
58 uint32_t dyn_gas_id = 0; // Composition of dyn gas selectors.
60
61 bool operator==(const ExecInstructionSpec& other) const = default;
62};
63
66 uint32_t size_in_bytes;
67 std::array<uint8_t, NUM_OP_DC_SELECTORS> op_dc_selectors;
69 tag_operand_idx; // Index of relevant operand in vector of operands as defined in WireOpCode_WIRE_FORMAT
70
71 bool operator==(const WireInstructionSpec& other) const = default;
72};
73
74// These are "extern" because the definition is in a different file.
75// Note: in the circuit, we can choose to merge both tables.
78
79} // namespace bb::avm2
RegisterInfo & add_inputs(const std::vector< std::optional< ValueTag > > &tags)
bool operator==(const RegisterInfo &other) const =default
std::optional< ValueTag > expected_tag(size_t index) const
RegisterInfo & add_input(std::optional< ValueTag > tag=std::nullopt)
std::vector< std::optional< ValueTag > > inputs
constexpr size_t NUM_OP_DC_SELECTORS
const std::unordered_map< WireOpCode, WireInstructionSpec > WIRE_INSTRUCTION_SPEC
const std::unordered_map< ExecutionOpCode, ExecInstructionSpec > EXEC_INSTRUCTION_SPEC
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
bool operator==(const GasInfo &other) const =default
bool operator==(const ExecInstructionSpec &other) const =default
std::optional< uint8_t > tag_operand_idx
std::array< uint8_t, NUM_OP_DC_SELECTORS > op_dc_selectors
bool operator==(const WireInstructionSpec &other) const =default