Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(avm): migrate to template engine #7316

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 6 additions & 141 deletions barretenberg/cpp/src/barretenberg/relations/generated/avm/alu.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

#pragma once
#include "../../relation_parameters.hpp"
#include "../../relation_types.hpp"
#include "./declare_views.hpp"

#include "barretenberg/relations/generated/avm/declare_views.hpp"
#include "barretenberg/relations/relation_parameters.hpp"
#include "barretenberg/relations/relation_types.hpp"

namespace bb::Avm_vm {

Expand All @@ -22,28 +22,21 @@ template <typename FF> struct BinaryRow {
FF binary_op_id{};
FF binary_op_id_shift{};
FF binary_sel_bin{};

[[maybe_unused]] static std::vector<std::string> names();
};

inline std::string get_relation_label_binary(int index)
{
switch (index) {
case 1:
return "OP_ID_REL";

case 2:
return "MEM_TAG_REL";

case 3:
return "SEL_BIN_CTR_REL";

case 7:
return "ACC_REL_A";

case 8:
return "ACC_REL_B";

case 9:
return "ACC_REL_C";
}
Expand All @@ -54,45 +47,38 @@ template <typename FF_> class binaryImpl {
public:
using FF = FF_;

static constexpr std::array<size_t, 10> SUBRELATION_PARTIAL_LENGTHS{
3, 3, 3, 4, 3, 3, 3, 4, 4, 4,
};
static constexpr std::array<size_t, 10> SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 3, 4, 3, 3, 3, 4, 4, 4 };

template <typename ContainerOverSubrelations, typename AllEntities>
void static accumulate(ContainerOverSubrelations& evals,
const AllEntities& new_term,
[[maybe_unused]] const RelationParameters<FF>&,
[[maybe_unused]] const FF& scaling_factor)
{

// Contribution 0
{
Avm_DECLARE_VIEWS(0);

auto tmp = (binary_sel_bin * (-binary_sel_bin + FF(1)));
tmp *= scaling_factor;
std::get<0>(evals) += tmp;
}
// Contribution 1
{
Avm_DECLARE_VIEWS(1);

auto tmp = ((binary_op_id_shift - binary_op_id) * binary_mem_tag_ctr);
tmp *= scaling_factor;
std::get<1>(evals) += tmp;
}
// Contribution 2
{
Avm_DECLARE_VIEWS(2);

auto tmp = (((binary_mem_tag_ctr_shift - binary_mem_tag_ctr) + FF(1)) * binary_mem_tag_ctr);
tmp *= scaling_factor;
std::get<2>(evals) += tmp;
}
// Contribution 3
{
Avm_DECLARE_VIEWS(3);

auto tmp = ((binary_mem_tag_ctr *
(((-binary_sel_bin + FF(1)) * (-binary_mem_tag_ctr_inv + FF(1))) + binary_mem_tag_ctr_inv)) -
binary_sel_bin);
Expand All @@ -102,47 +88,41 @@ template <typename FF_> class binaryImpl {
// Contribution 4
{
Avm_DECLARE_VIEWS(4);

auto tmp = ((-binary_sel_bin + FF(1)) * binary_acc_ia);
tmp *= scaling_factor;
std::get<4>(evals) += tmp;
}
// Contribution 5
{
Avm_DECLARE_VIEWS(5);

auto tmp = ((-binary_sel_bin + FF(1)) * binary_acc_ib);
tmp *= scaling_factor;
std::get<5>(evals) += tmp;
}
// Contribution 6
{
Avm_DECLARE_VIEWS(6);

auto tmp = ((-binary_sel_bin + FF(1)) * binary_acc_ic);
tmp *= scaling_factor;
std::get<6>(evals) += tmp;
}
// Contribution 7
{
Avm_DECLARE_VIEWS(7);

auto tmp = (((binary_acc_ia - binary_ia_bytes) - (binary_acc_ia_shift * FF(256))) * binary_mem_tag_ctr);
tmp *= scaling_factor;
std::get<7>(evals) += tmp;
}
// Contribution 8
{
Avm_DECLARE_VIEWS(8);

auto tmp = (((binary_acc_ib - binary_ib_bytes) - (binary_acc_ib_shift * FF(256))) * binary_mem_tag_ctr);
tmp *= scaling_factor;
std::get<8>(evals) += tmp;
}
// Contribution 9
{
Avm_DECLARE_VIEWS(9);

auto tmp = (((binary_acc_ic - binary_ic_bytes) - (binary_acc_ic_shift * FF(256))) * binary_mem_tag_ctr);
tmp *= scaling_factor;
std::get<9>(evals) += tmp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

#pragma once
#include "../../relation_parameters.hpp"
#include "../../relation_types.hpp"
#include "./declare_views.hpp"

#include "barretenberg/relations/generated/avm/declare_views.hpp"
#include "barretenberg/relations/relation_parameters.hpp"
#include "barretenberg/relations/relation_types.hpp"

namespace bb::Avm_vm {

template <typename FF> struct ConversionRow {
FF conversion_sel_to_radix_le{};

[[maybe_unused]] static std::vector<std::string> names();
};

inline std::string get_relation_label_conversion(int index)
Expand All @@ -22,21 +20,17 @@ template <typename FF_> class conversionImpl {
public:
using FF = FF_;

static constexpr std::array<size_t, 1> SUBRELATION_PARTIAL_LENGTHS{
3,
};
static constexpr std::array<size_t, 1> SUBRELATION_PARTIAL_LENGTHS = { 3 };

template <typename ContainerOverSubrelations, typename AllEntities>
void static accumulate(ContainerOverSubrelations& evals,
const AllEntities& new_term,
[[maybe_unused]] const RelationParameters<FF>&,
[[maybe_unused]] const FF& scaling_factor)
{

// Contribution 0
{
Avm_DECLARE_VIEWS(0);

auto tmp = (conversion_sel_to_radix_le * (-conversion_sel_to_radix_le + FF(1)));
tmp *= scaling_factor;
std::get<0>(evals) += tmp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once

#define Avm_DECLARE_VIEWS(index) \
using Accumulator = typename std::tuple_element<index, ContainerOverSubrelations>::type; \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@

#pragma once
#include "../../relation_parameters.hpp"
#include "../../relation_types.hpp"
#include "./declare_views.hpp"

#include "barretenberg/relations/generated/avm/declare_views.hpp"
#include "barretenberg/relations/relation_parameters.hpp"
#include "barretenberg/relations/relation_types.hpp"

namespace bb::Avm_vm {

template <typename FF> struct GasRow {
FF gas_da_gas_fixed_table{};
FF gas_l2_gas_fixed_table{};
FF gas_sel_gas_cost{};

[[maybe_unused]] static std::vector<std::string> names();
};

inline std::string get_relation_label_gas(int index)
Expand All @@ -24,39 +22,31 @@ template <typename FF_> class gasImpl {
public:
using FF = FF_;

static constexpr std::array<size_t, 3> SUBRELATION_PARTIAL_LENGTHS{
2,
2,
2,
};
static constexpr std::array<size_t, 3> SUBRELATION_PARTIAL_LENGTHS = { 2, 2, 2 };

template <typename ContainerOverSubrelations, typename AllEntities>
void static accumulate(ContainerOverSubrelations& evals,
const AllEntities& new_term,
[[maybe_unused]] const RelationParameters<FF>&,
[[maybe_unused]] const FF& scaling_factor)
{

// Contribution 0
{
Avm_DECLARE_VIEWS(0);

auto tmp = (gas_sel_gas_cost - gas_sel_gas_cost);
tmp *= scaling_factor;
std::get<0>(evals) += tmp;
}
// Contribution 1
{
Avm_DECLARE_VIEWS(1);

auto tmp = (gas_l2_gas_fixed_table - gas_l2_gas_fixed_table);
tmp *= scaling_factor;
std::get<1>(evals) += tmp;
}
// Contribution 2
{
Avm_DECLARE_VIEWS(2);

auto tmp = (gas_da_gas_fixed_table - gas_da_gas_fixed_table);
tmp *= scaling_factor;
std::get<2>(evals) += tmp;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

#pragma once
#include "../../relation_parameters.hpp"
#include "../../relation_types.hpp"
#include "./declare_views.hpp"

#include "barretenberg/relations/generated/avm/declare_views.hpp"
#include "barretenberg/relations/relation_parameters.hpp"
#include "barretenberg/relations/relation_types.hpp"

namespace bb::Avm_vm {

template <typename FF> struct Keccakf1600Row {
FF keccakf1600_sel_keccakf1600{};

[[maybe_unused]] static std::vector<std::string> names();
};

inline std::string get_relation_label_keccakf1600(int index)
Expand All @@ -22,21 +20,17 @@ template <typename FF_> class keccakf1600Impl {
public:
using FF = FF_;

static constexpr std::array<size_t, 1> SUBRELATION_PARTIAL_LENGTHS{
3,
};
static constexpr std::array<size_t, 1> SUBRELATION_PARTIAL_LENGTHS = { 3 };

template <typename ContainerOverSubrelations, typename AllEntities>
void static accumulate(ContainerOverSubrelations& evals,
const AllEntities& new_term,
[[maybe_unused]] const RelationParameters<FF>&,
[[maybe_unused]] const FF& scaling_factor)
{

// Contribution 0
{
Avm_DECLARE_VIEWS(0);

auto tmp = (keccakf1600_sel_keccakf1600 * (-keccakf1600_sel_keccakf1600 + FF(1)));
tmp *= scaling_factor;
std::get<0>(evals) += tmp;
Expand Down
Loading
Loading