Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::numeric Namespace Reference

Classes

class  DebugEngine
 
class  RandomEngine
 
class  RNG
 
class  sparse_int
 
class  uint256_t
 
class  uintx
 

Typedefs

using uint512_t = uintx< uint256_t >
 
using uint1024_t = uintx< uint512_t >
 

Functions

template<typename T >
constexpr size_t count_leading_zeros (T const &u)
 
template<>
constexpr size_t count_leading_zeros< uint32_t > (uint32_t const &u)
 
template<>
constexpr size_t count_leading_zeros< uint64_t > (uint64_t const &u)
 
template<>
constexpr size_t count_leading_zeros< uint128_t > (uint128_t const &u)
 
template<>
constexpr size_t count_leading_zeros< uint256_t > (uint256_t const &u)
 
constexpr uint32_t get_msb32 (const uint32_t in)
 
constexpr uint64_t get_msb64 (const uint64_t in)
 
template<typename T >
constexpr T get_msb (const T in)
 
template<typename T >
constexpr T round_up_power_2 (const T in)
 
template<typename T >
keep_n_lsb (T const &input, size_t num_bits)
 
constexpr uint64_t pow64 (const uint64_t input, const uint64_t exponent)
 
constexpr bool is_power_of_two (uint64_t x)
 
constexpr uint64_t rotate64 (const uint64_t value, const uint64_t rotation)
 
constexpr uint32_t rotate32 (const uint32_t value, const uint32_t rotation)
 
std::vector< uint64_t > slice_input (const uint256_t &input, const uint64_t base, const size_t num_slices)
 
std::vector< uint64_t > slice_input_using_variable_bases (const uint256_t &input, const std::vector< uint64_t > &bases)
 
template<uint64_t base, uint64_t num_slices>
constexpr std::array< uint256_t, num_slices > get_base_powers ()
 
template<uint64_t base>
constexpr uint256_t map_into_sparse_form (const uint64_t input)
 
template<uint64_t base>
constexpr uint64_t map_from_sparse_form (const uint256_t &input)
 
template<typename T >
constexpr T ceil_div (const T &numerator, const T &denominator)
 Computes the ceiling of the division of two integral types.
 
RNGget_debug_randomness (bool reset, std::uint_fast64_t seed)
 
RNGget_randomness ()
 
std::ostream & operator<< (std::ostream &os, uint256_t const &a)
 
template<typename B >
void read (B &it, uint256_t &value)
 
template<typename B >
void write (B &it, uint256_t const &value)
 
constexpr uint512_t TEST_MODULUS (uint256_t{ "0x04689e957a1242c84a50189c6d96cadca602072d09eac1013b5458a2275d69b1" }, uint256_t{ "0x0925c4b8763cbf9c599a6f7c0348d21cb00b85511637560626edfa5c34c6b38d" })
 
template<typename B , typename Params >
void read (B &it, uintx< Params > &value)
 
template<typename B , typename Params >
void write (B &it, uintx< Params > const &value)
 
template<class base_uint >
std::ostream & operator<< (std::ostream &os, uintx< base_uint > const &a)
 

Detailed Description

uint256_t Copyright Aztec 2020

An unsigned 256 bit integer type.

Constructor and all methods are constexpr. Ideally, uint256_t should be able to be treated like any other literal type.

Not optimized for performance, this code doesn't touch any of our hot paths when constructing proofs.

uintx Copyright Aztec 2020

An unsigned 512 bit integer type.

Constructor and all methods are constexpr. Ideally, uintx should be able to be treated like any other literal type.

Not optimized for performance, this code doesn"t touch any of our hot paths when constructing PLONK proofs

Typedef Documentation

◆ uint1024_t

Definition at line 309 of file uintx.hpp.

◆ uint512_t

Definition at line 307 of file uintx.hpp.

Function Documentation

◆ ceil_div()

template<typename T >
constexpr T bb::numeric::ceil_div ( const T &  numerator,
const T &  denominator 
)
constexpr

Computes the ceiling of the division of two integral types.

Calculates the ceiling of the division of numerator by denominator. Ensures that the denominator is greater than zero and that the type is an integral type.

Template Parameters
TThe integral type of numerator and denominator.
Parameters
numeratorThe value to be divided.
denominatorThe value to divide by.
Returns
The ceiling of the division result.

Definition at line 23 of file general.hpp.

◆ count_leading_zeros()

template<typename T >
constexpr size_t bb::numeric::count_leading_zeros ( T const &  u)
inlineconstexpr

Returns the number of leading 0 bits for a given integer type. Implemented in terms of intrinsics which will use instructions such as bsr or lzcnt for best performance. Undefined behavior when input is 0.

◆ count_leading_zeros< uint128_t >()

template<>
constexpr size_t bb::numeric::count_leading_zeros< uint128_t > ( uint128_t const &  u)
inlineconstexpr

Definition at line 31 of file count_leading_zeros.hpp.

◆ count_leading_zeros< uint256_t >()

template<>
constexpr size_t bb::numeric::count_leading_zeros< uint256_t > ( uint256_t const &  u)
inlineconstexpr

Definition at line 41 of file count_leading_zeros.hpp.

◆ count_leading_zeros< uint32_t >()

template<>
constexpr size_t bb::numeric::count_leading_zeros< uint32_t > ( uint32_t const &  u)
inlineconstexpr

Definition at line 21 of file count_leading_zeros.hpp.

◆ count_leading_zeros< uint64_t >()

template<>
constexpr size_t bb::numeric::count_leading_zeros< uint64_t > ( uint64_t const &  u)
inlineconstexpr

Definition at line 26 of file count_leading_zeros.hpp.

◆ get_base_powers()

template<uint64_t base, uint64_t num_slices>
constexpr std::array< uint256_t, num_slices > bb::numeric::get_base_powers ( )
constexpr

Definition at line 51 of file sparse_form.hpp.

◆ get_debug_randomness()

RNG & bb::numeric::get_debug_randomness ( bool  reset,
std::uint_fast64_t  seed 
)

Used by tests to ensure consistent behavior.

Definition at line 190 of file engine.cpp.

◆ get_msb()

template<typename T >
constexpr T bb::numeric::get_msb ( const T  in)
inlineconstexpr

Definition at line 47 of file get_msb.hpp.

◆ get_msb32()

constexpr uint32_t bb::numeric::get_msb32 ( const uint32_t  in)
inlineconstexpr

Definition at line 14 of file get_msb.hpp.

◆ get_msb64()

constexpr uint64_t bb::numeric::get_msb64 ( const uint64_t  in)
inlineconstexpr

Definition at line 30 of file get_msb.hpp.

◆ get_randomness()

RNG & bb::numeric::get_randomness ( )

Default engine. If wanting consistent proof construction, uncomment the line to return the debug engine.

Definition at line 203 of file engine.cpp.

◆ is_power_of_two()

constexpr bool bb::numeric::is_power_of_two ( uint64_t  x)
constexpr

Definition at line 35 of file pow.hpp.

◆ keep_n_lsb()

template<typename T >
T bb::numeric::keep_n_lsb ( T const &  input,
size_t  num_bits 
)
inline

Definition at line 12 of file keep_n_lsb.hpp.

◆ map_from_sparse_form()

template<uint64_t base>
constexpr uint64_t bb::numeric::map_from_sparse_form ( const uint256_t input)
constexpr

Definition at line 76 of file sparse_form.hpp.

◆ map_into_sparse_form()

template<uint64_t base>
constexpr uint256_t bb::numeric::map_into_sparse_form ( const uint64_t  input)
constexpr

Definition at line 61 of file sparse_form.hpp.

◆ operator<<() [1/2]

std::ostream & bb::numeric::operator<< ( std::ostream &  os,
uint256_t const &  a 
)
inline

Definition at line 246 of file uint256.hpp.

◆ operator<<() [2/2]

template<class base_uint >
std::ostream & bb::numeric::operator<< ( std::ostream &  os,
uintx< base_uint > const &  a 
)
inline

Definition at line 300 of file uintx.hpp.

◆ pow64()

constexpr uint64_t bb::numeric::pow64 ( const uint64_t  input,
const uint64_t  exponent 
)
constexpr

Definition at line 13 of file pow.hpp.

◆ read() [1/2]

template<typename B >
void bb::numeric::read ( B &  it,
uint256_t value 
)
inline

Definition at line 255 of file uint256.hpp.

◆ read() [2/2]

template<typename B , typename Params >
void bb::numeric::read ( B &  it,
uintx< Params > &  value 
)
inline

Definition at line 283 of file uintx.hpp.

◆ rotate32()

constexpr uint32_t bb::numeric::rotate32 ( const uint32_t  value,
const uint32_t  rotation 
)
inlineconstexpr

Definition at line 18 of file rotate.hpp.

◆ rotate64()

constexpr uint64_t bb::numeric::rotate64 ( const uint64_t  value,
const uint64_t  rotation 
)
inlineconstexpr

Definition at line 13 of file rotate.hpp.

◆ round_up_power_2()

template<typename T >
constexpr T bb::numeric::round_up_power_2 ( const T  in)
inlineconstexpr

Definition at line 52 of file get_msb.hpp.

◆ slice_input()

std::vector< uint64_t > bb::numeric::slice_input ( const uint256_t input,
const uint64_t  base,
const size_t  num_slices 
)
inline

Definition at line 18 of file sparse_form.hpp.

◆ slice_input_using_variable_bases()

std::vector< uint64_t > bb::numeric::slice_input_using_variable_bases ( const uint256_t input,
const std::vector< uint64_t > &  bases 
)
inline

Definition at line 36 of file sparse_form.hpp.

◆ TEST_MODULUS()

constexpr uint512_t bb::numeric::TEST_MODULUS ( uint256_t{ "0x04689e957a1242c84a50189c6d96cadca602072d09eac1013b5458a2275d69b1" }  ,
uint256_t{ "0x0925c4b8763cbf9c599a6f7c0348d21cb00b85511637560626edfa5c34c6b38d" }   
)
constexpr

◆ write() [1/2]

template<typename B >
void bb::numeric::write ( B &  it,
uint256_t const &  value 
)
inline

Definition at line 269 of file uint256.hpp.

◆ write() [2/2]

template<typename B , typename Params >
void bb::numeric::write ( B &  it,
uintx< Params > const &  value 
)
inline

Definition at line 293 of file uintx.hpp.