Skip to content

Commit

Permalink
chore(avm): migrate lookups and permutations (#7335)
Browse files Browse the repository at this point in the history
  • Loading branch information
fcarreiro authored and AztecBot committed Jul 5, 2024
1 parent f0fa9b6 commit 0623807
Show file tree
Hide file tree
Showing 54 changed files with 54 additions and 4,452 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#pragma once

#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp"
Expand All @@ -25,81 +23,20 @@ namespace bb {
*/
class incl_main_tag_err_lookup_settings {
public:
/**
* @brief The number of read terms (how many lookups we perform) in each row
*
*/
static constexpr size_t READ_TERMS = 1;
/**
* @brief The number of write terms (how many additions to the lookup table we make) in each row
*
*/
static constexpr size_t WRITE_TERMS = 1;

/**
* @brief The type of READ_TERM used for each read index (basic and scaled)
*
*/
static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 };

/**
* @brief They type of WRITE_TERM used for each write index
*
*/
static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 };

/**
* @brief How many values represent a single lookup object. This value is used by the automatic read term
* implementation in the relation in case the lookup is a basic or scaled tuple and in the write term if it's a
* basic tuple
*
*/
static constexpr size_t LOOKUP_TUPLE_SIZE = 1;

/**
* @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed
*
*/
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4;

/**
* @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read
* terms, but will cause compilation error if not defined
*
*/
static constexpr size_t READ_TERM_DEGREE = 0;

/**
* @brief The degree of the write term if implemented arbitrarily. This value is not used by the basic write
* term, but will cause compilation error if not defined
*
*/

static constexpr size_t WRITE_TERM_DEGREE = 0;

/**
* @brief If this method returns true on a row of values, then the inverse polynomial exists at this index.
* Otherwise the value needs to be set to zero.
*
* @details If this is true then the lookup takes place in this row
*
*/

template <typename AllEntities> static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in)
{
return (in.mem_tag_err == 1 || in.main_tag_err == 1);
}

/**
* @brief Subprocedure for computing the value deciding if the inverse polynomial value needs to be checked in this
* row
*
* @tparam Accumulator Type specified by the lookup relation
* @tparam AllEntities Values/Univariates of all entities row
* @param in Value/Univariate of all entities at row/edge
* @return Accumulator
*/

template <typename Accumulator, typename AllEntities>
static inline auto compute_inverse_exists(const AllEntities& in)
{
Expand All @@ -109,30 +46,8 @@ class incl_main_tag_err_lookup_settings {
return (is_operation + is_table_entry - is_operation * is_table_entry);
}

/**
* @brief Get all the entities for the lookup when need to update them
*
* @details The generic structure of this tuple is described in ./generic_lookup_relation.hpp . The following is
description for the current case:
The entities are returned as a tuple of references in the following order (this is for ):
* - The entity/polynomial used to store the product of the inverse values
* - The entity/polynomial that specifies how many times the lookup table entry at this row has been looked up
* - READ_TERMS entities/polynomials that enable individual lookup operations
* - The entity/polynomial that enables adding an entry to the lookup table in this row
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the basic tuple being looked up as the first read term
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the previous accumulators in the second read term
(scaled tuple)
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the shifts in the second read term (scaled tuple)
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the current accumulators in the second read term
(scaled tuple)
* - LOOKUP_TUPLE_SIZE entities/polynomials representing basic tuples added to the table
*
* @return All the entities needed for the lookup
*/

template <typename AllEntities> static inline auto get_const_entities(const AllEntities& in)
{

return std::forward_as_tuple(in.incl_main_tag_err,
in.incl_main_tag_err_counts,
in.mem_tag_err,
Expand All @@ -141,16 +56,8 @@ class incl_main_tag_err_lookup_settings {
in.main_clk);
}

/**
* @brief Get all the entities for the lookup when we only need to read them
* @details Same as in get_const_entities, but nonconst
*
* @return All the entities needed for the lookup
*/

template <typename AllEntities> static inline auto get_nonconst_entities(AllEntities& in)
{

return std::forward_as_tuple(in.incl_main_tag_err,
in.incl_main_tag_err_counts,
in.mem_tag_err,
Expand All @@ -164,4 +71,4 @@ template <typename FF_>
using incl_main_tag_err_relation = GenericLookupRelation<incl_main_tag_err_lookup_settings, FF_>;
template <typename FF_> using incl_main_tag_err = GenericLookup<incl_main_tag_err_lookup_settings, FF_>;

} // namespace bb
} // namespace bb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#pragma once

#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp"
Expand All @@ -25,81 +23,20 @@ namespace bb {
*/
class incl_mem_tag_err_lookup_settings {
public:
/**
* @brief The number of read terms (how many lookups we perform) in each row
*
*/
static constexpr size_t READ_TERMS = 1;
/**
* @brief The number of write terms (how many additions to the lookup table we make) in each row
*
*/
static constexpr size_t WRITE_TERMS = 1;

/**
* @brief The type of READ_TERM used for each read index (basic and scaled)
*
*/
static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 };

/**
* @brief They type of WRITE_TERM used for each write index
*
*/
static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 };

/**
* @brief How many values represent a single lookup object. This value is used by the automatic read term
* implementation in the relation in case the lookup is a basic or scaled tuple and in the write term if it's a
* basic tuple
*
*/
static constexpr size_t LOOKUP_TUPLE_SIZE = 1;

/**
* @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed
*
*/
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4;

/**
* @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read
* terms, but will cause compilation error if not defined
*
*/
static constexpr size_t READ_TERM_DEGREE = 0;

/**
* @brief The degree of the write term if implemented arbitrarily. This value is not used by the basic write
* term, but will cause compilation error if not defined
*
*/

static constexpr size_t WRITE_TERM_DEGREE = 0;

/**
* @brief If this method returns true on a row of values, then the inverse polynomial exists at this index.
* Otherwise the value needs to be set to zero.
*
* @details If this is true then the lookup takes place in this row
*
*/

template <typename AllEntities> static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in)
{
return (in.main_tag_err == 1 || in.mem_tag_err == 1);
}

/**
* @brief Subprocedure for computing the value deciding if the inverse polynomial value needs to be checked in this
* row
*
* @tparam Accumulator Type specified by the lookup relation
* @tparam AllEntities Values/Univariates of all entities row
* @param in Value/Univariate of all entities at row/edge
* @return Accumulator
*/

template <typename Accumulator, typename AllEntities>
static inline auto compute_inverse_exists(const AllEntities& in)
{
Expand All @@ -109,44 +46,14 @@ class incl_mem_tag_err_lookup_settings {
return (is_operation + is_table_entry - is_operation * is_table_entry);
}

/**
* @brief Get all the entities for the lookup when need to update them
*
* @details The generic structure of this tuple is described in ./generic_lookup_relation.hpp . The following is
description for the current case:
The entities are returned as a tuple of references in the following order (this is for ):
* - The entity/polynomial used to store the product of the inverse values
* - The entity/polynomial that specifies how many times the lookup table entry at this row has been looked up
* - READ_TERMS entities/polynomials that enable individual lookup operations
* - The entity/polynomial that enables adding an entry to the lookup table in this row
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the basic tuple being looked up as the first read term
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the previous accumulators in the second read term
(scaled tuple)
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the shifts in the second read term (scaled tuple)
* - LOOKUP_TUPLE_SIZE entities/polynomials representing the current accumulators in the second read term
(scaled tuple)
* - LOOKUP_TUPLE_SIZE entities/polynomials representing basic tuples added to the table
*
* @return All the entities needed for the lookup
*/

template <typename AllEntities> static inline auto get_const_entities(const AllEntities& in)
{

return std::forward_as_tuple(
in.incl_mem_tag_err, in.incl_mem_tag_err_counts, in.main_tag_err, in.mem_tag_err, in.main_clk, in.mem_clk);
}

/**
* @brief Get all the entities for the lookup when we only need to read them
* @details Same as in get_const_entities, but nonconst
*
* @return All the entities needed for the lookup
*/

template <typename AllEntities> static inline auto get_nonconst_entities(AllEntities& in)
{

return std::forward_as_tuple(
in.incl_mem_tag_err, in.incl_mem_tag_err_counts, in.main_tag_err, in.mem_tag_err, in.main_clk, in.mem_clk);
}
Expand All @@ -155,4 +62,4 @@ class incl_mem_tag_err_lookup_settings {
template <typename FF_> using incl_mem_tag_err_relation = GenericLookupRelation<incl_mem_tag_err_lookup_settings, FF_>;
template <typename FF_> using incl_mem_tag_err = GenericLookup<incl_mem_tag_err_lookup_settings, FF_>;

} // namespace bb
} // namespace bb
Loading

0 comments on commit 0623807

Please sign in to comment.