Skip to content

Commit dd1e5b4

Browse files
committed
refactor(avm): less codegen
1 parent 9c1d9f1 commit dd1e5b4

20 files changed

+434
-5739
lines changed

barretenberg/cpp/src/barretenberg/vm2/constraining/flavor.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class AvmFlavor {
167167
class WitnessEntities : public WireEntities<DataType>, public DerivedWitnessEntities<DataType> {
168168
public:
169169
DEFINE_COMPOUND_GET_ALL(WireEntities<DataType>, DerivedWitnessEntities<DataType>)
170+
170171
auto get_wires() { return WireEntities<DataType>::get_all(); }
171172
static const auto& get_wires_labels() { return WireEntities<DataType>::get_labels(); }
172173
auto get_derived() { return DerivedWitnessEntities<DataType>::get_all(); }
@@ -305,7 +306,7 @@ class AvmFlavor {
305306
ProverPolynomials(ProvingKey& proving_key);
306307

307308
size_t get_polynomial_size() const { return execution_input.size(); }
308-
// This is only used in VM1 check_circuit. Remove.
309+
// This is only used in check_circuit. Remove.
309310
AllConstRefValues get_standard_row(size_t row_idx) const
310311
{
311312
return [row_idx](auto&... entities) -> AllConstRefValues {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#pragma once
2+
3+
#include <cstddef>
4+
5+
#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp"
6+
#include "barretenberg/vm2/generated/columns.hpp"
7+
8+
namespace bb::avm2 {
9+
10+
template <typename Settings_> struct lookup_settings : public Settings_ {
11+
static constexpr size_t READ_TERMS = 1;
12+
static constexpr size_t WRITE_TERMS = 1;
13+
static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 };
14+
static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 };
15+
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4;
16+
static constexpr size_t READ_TERM_DEGREE = 0;
17+
static constexpr size_t WRITE_TERM_DEGREE = 0;
18+
19+
template <typename AllEntities> static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in)
20+
{
21+
return (in.get(static_cast<ColumnAndShifts>(Settings_::SRC_SELECTOR)) == 1 ||
22+
in.get(static_cast<ColumnAndShifts>(Settings_::DST_SELECTOR)) == 1);
23+
}
24+
25+
template <typename Accumulator, typename AllEntities>
26+
static inline auto compute_inverse_exists(const AllEntities& in)
27+
{
28+
using View = typename Accumulator::View;
29+
const auto is_operation = View(in.get(static_cast<ColumnAndShifts>(Settings_::SRC_SELECTOR)));
30+
const auto is_table_entry = View(in.get(static_cast<ColumnAndShifts>(Settings_::DST_SELECTOR)));
31+
return (is_operation + is_table_entry - is_operation * is_table_entry);
32+
}
33+
34+
template <typename AllEntities> static inline auto get_entities(AllEntities&& in)
35+
{
36+
return []<size_t... ISource, size_t... IDest>(
37+
AllEntities&& in, std::index_sequence<ISource...>, std::index_sequence<IDest...>) {
38+
return std::forward_as_tuple(in.get(static_cast<ColumnAndShifts>(Settings_::INVERSES)),
39+
in.get(static_cast<ColumnAndShifts>(Settings_::COUNTS)),
40+
in.get(static_cast<ColumnAndShifts>(Settings_::SRC_SELECTOR)),
41+
in.get(static_cast<ColumnAndShifts>(Settings_::DST_SELECTOR)),
42+
in.get(Settings_::SRC_COLUMNS[ISource])...,
43+
in.get(Settings_::DST_COLUMNS[IDest])...);
44+
}(std::forward<AllEntities>(in),
45+
std::make_index_sequence<Settings_::SRC_COLUMNS.size()>{},
46+
std::make_index_sequence<Settings_::DST_COLUMNS.size()>{});
47+
}
48+
49+
template <typename AllEntities> static inline auto get_const_entities(const AllEntities& in)
50+
{
51+
return get_entities(in);
52+
}
53+
54+
template <typename AllEntities> static inline auto get_nonconst_entities(AllEntities& in)
55+
{
56+
return get_entities(in);
57+
}
58+
};
59+
60+
template <typename FF_, typename Settings_> struct lookup_relation_base : public GenericLookupRelation<Settings_, FF_> {
61+
using Settings = Settings_;
62+
static constexpr std::string_view NAME = Settings::NAME;
63+
static constexpr std::string_view RELATION_NAME = Settings::RELATION_NAME;
64+
65+
template <typename AllEntities> inline static bool skip(const AllEntities& in)
66+
{
67+
auto inverse = std::get<0>(Settings::get_entities(in));
68+
return inverse.is_zero();
69+
}
70+
71+
static std::string get_subrelation_label(size_t index)
72+
{
73+
switch (index) {
74+
case 0:
75+
return "INVERSES_ARE_CORRECT";
76+
case 1:
77+
return "ACCUMULATION_IS_CORRECT";
78+
default:
79+
return std::to_string(index);
80+
}
81+
}
82+
};
83+
84+
} // namespace bb::avm2

0 commit comments

Comments
 (0)