Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
to_radix.cpp
Go to the documentation of this file.
2
6
7namespace bb::avm2 {
8
9namespace {
10
11// The number of limbs that the field modulus, p, decomposes into given a radix.
12const std::array<size_t, 257> p_limbs_per_radix_sizes = {
13 0, 0, 254, 161, 127, 110, 99, 91, 85, 81, 77, 74, 71, 69, 67, 65, 64, 63, 61, 60, 59, 58, 57, 57, 56, 55,
14 54, 54, 53, 53, 52, 52, 51, 51, 50, 50, 50, 49, 49, 48, 48, 48, 48, 47, 47, 47, 46, 46, 46, 46, 45, 45,
15 45, 45, 45, 44, 44, 44, 44, 44, 43, 43, 43, 43, 43, 43, 42, 42, 42, 42, 42, 42, 42, 41, 41, 41, 41, 41,
16 41, 41, 41, 41, 40, 40, 40, 40, 40, 40, 40, 40, 40, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 38,
17 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37,
18 37, 37, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 35, 35, 35, 35,
19 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 34, 34, 34, 34, 34, 34,
20 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 33, 33,
21 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
22 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
23};
24
31std::array<std::vector<uint8_t>, 257> create_p_limbs_per_radix()
32{
33 std::array<std::vector<uint8_t>, 257> limbs_per_radix;
34
35 for (size_t radix = 2; radix < 257; ++radix) {
36 std::vector<uint8_t> p_limbs;
37 p_limbs.reserve(p_limbs_per_radix_sizes[radix]);
39
40 while (p != 0) {
41 const auto [quotient, remainder] = p.divmod(static_cast<uint64_t>(radix));
42 p_limbs.push_back(static_cast<uint8_t>(remainder));
43 p = quotient;
44 }
45
46 limbs_per_radix[radix] = p_limbs;
47 }
48
49 return limbs_per_radix;
50}
51
52} // namespace
53
61{
62 static const std::array<std::vector<uint8_t>, 257> limbs_per_radix = create_p_limbs_per_radix();
63 return limbs_per_radix;
64}
65
75size_t get_p_limbs_per_radix_size(size_t radix)
76{
77 BB_ASSERT_LTE(radix, static_cast<decltype(radix)>(256), "Radix out of bounds");
78 return p_limbs_per_radix_sizes[radix];
79}
80
81} // namespace bb::avm2
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:158
constexpr std::pair< uint256_t, uint256_t > divmod(const uint256_t &b) const
const std::array< std::vector< uint8_t >, 257 > & get_p_limbs_per_radix()
Gets the p limbs per radix array. Each element is a vector containing the little endian decomposition...
Definition to_radix.cpp:60
size_t get_p_limbs_per_radix_size(size_t radix)
Gets the number of limbs that the modulus, p, decomposes into for a given radix.
Definition to_radix.cpp:75
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static constexpr uint256_t modulus