12
12
#include " barretenberg/transcript/transcript.hpp"
13
13
14
14
#include " barretenberg/vm2/common/aztec_constants.hpp"
15
- #include " barretenberg/vm2/common/macros.hpp"
16
15
#include " barretenberg/vm2/constraining/flavor_settings.hpp"
17
16
18
17
#include " barretenberg/vm2/generated/columns.hpp"
21
20
// Metaprogramming to concatenate tuple types.
22
21
template <typename ... input_t > using tuple_cat_t = decltype (std::tuple_cat(std::declval<input_t >()...));
23
22
24
- // clang-format off
25
- // These getters are used to speedup logderivative inverses.
26
- // See https://github.com/AztecProtocol/aztec-packages/pull/11605/ for a full explanation.
27
- #define DEFAULT_GETTERS (ENTITY ) \
28
- inline auto & _##ENTITY() { return ENTITY; } \
29
- inline auto & _##ENTITY() const { return ENTITY; }
30
- #define ROW_PROXY_GETTERS (ENTITY ) \
31
- inline auto & _##ENTITY() { return pp.ENTITY [row_idx]; } \
32
- inline auto & _##ENTITY() const { return pp.ENTITY [row_idx]; }
33
- #define DEFINE_GETTERS (GETTER_MACRO, ENTITIES ) \
34
- FOR_EACH (GETTER_MACRO, ENTITIES)
35
- // clang-format on
36
-
37
23
namespace bb ::avm2 {
38
24
25
+ // This helper lets us access entities by column.
26
+ // It is critical to achieve performance when calculating lookup inverses.
27
+ // See https://github.com/AztecProtocol/aztec-packages/pull/11605 for more details.
28
+ template <typename Entities> auto & get_entity_by_column (Entities& entities, ColumnAndShifts c)
29
+ {
30
+ // A statically constructed pointer to members of the class, indexed by column.
31
+ // This should only be created once per Entities class.
32
+ static std::array<typename Entities::DataType (Entities::*), NUM_COLUMNS_WITH_SHIFTS> col_ptrs = {
33
+ AVM2_ALL_ENTITIES_E (&Entities::)
34
+ };
35
+ return (entities.*col_ptrs[static_cast <size_t >(c)]);
36
+ }
37
+
39
38
class AvmFlavor {
40
39
public:
41
40
using Curve = AvmFlavorSettings::Curve;
@@ -139,32 +138,28 @@ class AvmFlavor {
139
138
template <typename DataType> class PrecomputedEntities {
140
139
public:
141
140
DEFINE_FLAVOR_MEMBERS (DataType, AVM2_PRECOMPUTED_ENTITIES)
142
- DEFINE_GETTERS (DEFAULT_GETTERS, AVM2_PRECOMPUTED_ENTITIES)
143
141
};
144
142
145
143
private:
146
144
template <typename DataType> class WireEntities {
147
145
public:
148
146
DEFINE_FLAVOR_MEMBERS (DataType, AVM2_WIRE_ENTITIES)
149
- DEFINE_GETTERS (DEFAULT_GETTERS, AVM2_WIRE_ENTITIES)
150
147
};
151
148
152
149
template <typename DataType> class DerivedWitnessEntities {
153
150
public:
154
151
DEFINE_FLAVOR_MEMBERS (DataType, AVM2_DERIVED_WITNESS_ENTITIES)
155
- DEFINE_GETTERS (DEFAULT_GETTERS, AVM2_DERIVED_WITNESS_ENTITIES)
156
152
};
157
153
158
154
template <typename DataType> class ShiftedEntities {
159
155
public:
160
156
DEFINE_FLAVOR_MEMBERS (DataType, AVM2_SHIFTED_ENTITIES)
161
- DEFINE_GETTERS (DEFAULT_GETTERS, AVM2_SHIFTED_ENTITIES)
162
157
};
163
158
164
159
template <typename DataType, typename PrecomputedAndWitnessEntitiesSuperset>
165
- static auto get_to_be_shifted ([[maybe_unused]] PrecomputedAndWitnessEntitiesSuperset& entities)
160
+ static auto get_to_be_shifted (PrecomputedAndWitnessEntitiesSuperset& entities)
166
161
{
167
- return RefArray<DataType, NUM_SHIFTED_ENTITIES>{ AVM2_TO_BE_SHIFTED (entities) };
162
+ return RefArray<DataType, NUM_SHIFTED_ENTITIES>{ AVM2_TO_BE_SHIFTED_E (entities. ) };
168
163
}
169
164
170
165
public:
@@ -178,11 +173,12 @@ class AvmFlavor {
178
173
static const auto & get_derived_labels () { return DerivedWitnessEntities<DataType>::get_labels (); }
179
174
};
180
175
181
- template <typename DataType >
182
- class AllEntities : public PrecomputedEntities <DataType >,
183
- public WitnessEntities<DataType >,
184
- public ShiftedEntities<DataType > {
176
+ template <typename DataType_ >
177
+ class AllEntities : public PrecomputedEntities <DataType_ >,
178
+ public WitnessEntities<DataType_ >,
179
+ public ShiftedEntities<DataType_ > {
185
180
public:
181
+ using DataType = DataType_;
186
182
DEFINE_COMPOUND_GET_ALL (PrecomputedEntities<DataType>, WitnessEntities<DataType>, ShiftedEntities<DataType>)
187
183
188
184
auto get_unshifted ()
@@ -200,6 +196,10 @@ class AvmFlavor {
200
196
auto get_to_be_shifted () { return AvmFlavor::get_to_be_shifted<DataType>(*this ); }
201
197
auto get_shifted () { return ShiftedEntities<DataType>::get_all (); }
202
198
auto get_precomputed () { return PrecomputedEntities<DataType>::get_all (); }
199
+
200
+ // We need both const and non-const versions.
201
+ DataType& get (ColumnAndShifts c) { return get_entity_by_column (*this , c); }
202
+ const DataType& get (ColumnAndShifts c) const { return get_entity_by_column (*this , c); }
203
203
};
204
204
205
205
class ProvingKey : public PrecomputedEntities <Polynomial>, public WitnessEntities<Polynomial> {
@@ -258,6 +258,7 @@ class AvmFlavor {
258
258
std::vector<FF> to_field_elements () const ;
259
259
};
260
260
261
+ // Used by sumcheck.
261
262
class AllValues : public AllEntities <FF> {
262
263
public:
263
264
using Base = AllEntities<FF>;
@@ -270,7 +271,6 @@ class AvmFlavor {
270
271
using BaseDataType = const FF;
271
272
using DataType = BaseDataType&;
272
273
DEFINE_FLAVOR_MEMBERS (DataType, AVM2_ALL_ENTITIES)
273
- DEFINE_GETTERS (DEFAULT_GETTERS, AVM2_ALL_ENTITIES)
274
274
};
275
275
276
276
template <typename Polynomials> class PolynomialEntitiesAtFixedRow {
@@ -279,7 +279,10 @@ class AvmFlavor {
279
279
: row_idx(row_idx)
280
280
, pp(pp)
281
281
{}
282
- DEFINE_GETTERS (ROW_PROXY_GETTERS, AVM2_ALL_ENTITIES)
282
+
283
+ // We need both const and non-const versions.
284
+ auto & get (ColumnAndShifts c) { return pp.get (c)[row_idx]; }
285
+ const auto & get (ColumnAndShifts c) const { return pp.get (c)[row_idx]; }
283
286
284
287
private:
285
288
const size_t row_idx;
0 commit comments