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
5
6namespace bb::avm2 {
7
8namespace {
9
10// The number of limbs that the field modulus, p, decomposes into given a radix.
11const std::array<size_t, 257> p_limbs_per_radix_sizes = {
12 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,
13 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,
14 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,
15 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,
16 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,
17 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,
18 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,
19 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,
20 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,
21 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
22};
23
24// The little endian decompositions of Fr modulus into limbs for each radix.
25// Radix goes up to 256 so we need 257 decompositions.
26std::array<std::vector<uint8_t>, 257> create_p_limbs_per_radix()
27{
28 std::array<std::vector<uint8_t>, 257> limbs_per_radix;
29
30 for (size_t radix = 2; radix < 257; ++radix) {
31 std::vector<uint8_t> p_limbs{};
32 p_limbs.reserve(31);
34 while (p != 0) {
35 auto [quotient, remainder] = p.divmod(radix);
36 p_limbs.push_back(static_cast<uint8_t>(remainder));
37 p = quotient;
38 }
39
40 limbs_per_radix[radix] = p_limbs;
41 }
42
43 return limbs_per_radix;
44}
45
46} // namespace
47
49{
50 static const std::array<std::vector<uint8_t>, 257> limbs_per_radix = create_p_limbs_per_radix();
51 return limbs_per_radix;
52}
53
54size_t get_p_limbs_per_radix_size(size_t radix)
55{
56 assert(radix <= 256);
57 return p_limbs_per_radix_sizes[radix];
58}
59
60} // namespace bb::avm2
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()
Definition to_radix.cpp:48
size_t get_p_limbs_per_radix_size(size_t radix)
Definition to_radix.cpp:54
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static constexpr uint256_t modulus