Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::numeric::uintx< base_uint > Class Template Reference

#include <uintx.hpp>

Public Member Functions

constexpr uintx (const uint64_t &data=0)
 
constexpr uintx (const uint256_t &data)
 
constexpr uintx (const base_uint input_lo)
 
constexpr uintx (const base_uint input_lo, const base_uint input_hi)
 
constexpr uintx (const uintx &other)=default
 
constexpr uintx (uintx &&other) noexcept=default
 
uintxoperator= (const uintx &other)=default
 
uintxoperator= (uintx &&other) noexcept=default
 
 ~uintx ()=default
 
constexpr operator bool () const
 
constexpr operator uint8_t () const
 
constexpr operator uint16_t () const
 
constexpr operator uint32_t () const
 
constexpr operator uint64_t () const
 
constexpr operator base_uint () const
 
bool get_bit (uint64_t bit_index) const
 
constexpr uint64_t get_msb () const
 
constexpr uintx slice (const uint64_t start, const uint64_t end) const
 
constexpr uintx operator- (const uintx &other) const
 
constexpr uintx operator<< (const uint64_t other) const
 
constexpr uintx operator>> (const uint64_t other) const
 
constexpr uintx operator+ (const uintx &other) const
 
uintx operator- () const
 
uintx operator* (const uintx &other) const
 
uintx operator/ (const uintx &other) const
 
uintx operator% (const uintx &other) const
 
std::pair< uintx, uintxmul_extended (const uintx &other) const
 
constexpr uintx operator& (const uintx &other) const
 
uintx operator^ (const uintx &other) const
 
uintx operator| (const uintx &other) const
 
uintx operator~ () const
 
bool operator== (const uintx &other) const
 
bool operator!= (const uintx &other) const
 
bool operator! () const
 
bool operator> (const uintx &other) const
 
bool operator< (const uintx &other) const
 
bool operator>= (const uintx &other) const
 
bool operator<= (const uintx &other) const
 
uintxoperator+= (const uintx &other)
 
uintxoperator-= (const uintx &other)
 
uintxoperator*= (const uintx &other)
 
uintxoperator/= (const uintx &other)
 
uintxoperator%= (const uintx &other)
 
uintxoperator++ ()
 
uintxoperator-- ()
 
uintxoperator&= (const uintx &other)
 
uintxoperator^= (const uintx &other)
 
uintxoperator|= (const uintx &other)
 
uintxoperator>>= (const uint64_t other)
 
uintxoperator<<= (const uint64_t other)
 
uintx invmod (const uintx &modulus) const
 
uintx unsafe_invmod (const uintx &modulus) const
 
template<base_uint modulus>
std::pair< uintx, uintxbarrett_reduction () const
 
std::pair< uintx, uintxdivmod (const uintx &b) const
 
std::pair< uintx, uintxdivmod_base (const uintx &b) const
 
template<base_uint modulus>
std::pair< uintx< base_uint >, uintx< base_uint > > barrett_reduction () const
 Compute fast division via a barrett reduction Evaluates x = qm + r where m = modulus. returns q, r.
 

Static Public Member Functions

static constexpr size_t length ()
 

Public Attributes

base_uint lo
 
base_uint hi
 

Detailed Description

template<class base_uint>
class bb::numeric::uintx< base_uint >

Definition at line 29 of file uintx.hpp.

Constructor & Destructor Documentation

◆ uintx() [1/6]

template<class base_uint >
constexpr bb::numeric::uintx< base_uint >::uintx ( const uint64_t &  data = 0)
inlineconstexpr

Definition at line 31 of file uintx.hpp.

◆ uintx() [2/6]

template<class base_uint >
constexpr bb::numeric::uintx< base_uint >::uintx ( const uint256_t data)
inlineconstexpr

Definition at line 36 of file uintx.hpp.

◆ uintx() [3/6]

template<class base_uint >
constexpr bb::numeric::uintx< base_uint >::uintx ( const base_uint  input_lo)
inlineconstexpr

Definition at line 42 of file uintx.hpp.

◆ uintx() [4/6]

template<class base_uint >
constexpr bb::numeric::uintx< base_uint >::uintx ( const base_uint  input_lo,
const base_uint  input_hi 
)
inlineconstexpr

Definition at line 47 of file uintx.hpp.

◆ uintx() [5/6]

template<class base_uint >
constexpr bb::numeric::uintx< base_uint >::uintx ( const uintx< base_uint > &  other)
constexprdefault

◆ uintx() [6/6]

template<class base_uint >
constexpr bb::numeric::uintx< base_uint >::uintx ( uintx< base_uint > &&  other)
constexprdefaultnoexcept

◆ ~uintx()

template<class base_uint >
bb::numeric::uintx< base_uint >::~uintx ( )
default

Member Function Documentation

◆ barrett_reduction() [1/2]

template<class base_uint >
template<base_uint modulus>
template std::pair< uint1024_t, uint1024_t > bb::numeric::uintx< base_uint >::barrett_reduction< TEST_MODULUS > ( ) const

◆ barrett_reduction() [2/2]

template<class base_uint >
template<base_uint modulus>
std::pair< uintx< base_uint >, uintx< base_uint > > bb::numeric::uintx< base_uint >::barrett_reduction ( ) const

Compute fast division via a barrett reduction Evaluates x = qm + r where m = modulus. returns q, r.

This implementation is less efficient due to making no assumptions about the value of *self. When using this method to perform modular reductions e.g. (*self) mod m, if (*self) < m^2 a lot of the uintx operations in this method could be replaced with base_uint operations

Template Parameters
base_uint
modulus
Returns
std::pair<uintx<base_uint>, uintx<base_uint>>

Definition at line 272 of file uintx_impl.hpp.

◆ divmod()

template<class base_uint >
std::pair< uintx< base_uint >, uintx< base_uint > > bb::numeric::uintx< base_uint >::divmod ( const uintx< base_uint > &  b) const

Definition at line 236 of file uintx_impl.hpp.

◆ divmod_base()

template<class base_uint >
std::pair< uintx< base_uint >, uintx< base_uint > > bb::numeric::uintx< base_uint >::divmod_base ( const uintx< base_uint > &  b) const

Definition at line 13 of file uintx_impl.hpp.

◆ get_bit()

template<class base_uint >
bool bb::numeric::uintx< base_uint >::get_bit ( uint64_t  bit_index) const

Definition at line 118 of file uintx_impl.hpp.

◆ get_msb()

template<class base_uint >
constexpr uint64_t bb::numeric::uintx< base_uint >::get_msb ( ) const
inlineconstexpr

Definition at line 69 of file uintx.hpp.

◆ invmod()

template<class base_uint >
uintx< base_uint > bb::numeric::uintx< base_uint >::invmod ( const uintx< base_uint > &  modulus) const

Computes the inverse of *this, modulo modulus, via the extended Euclidean algorithm.

Delegates to appropriate unsafe_invmod (if the modulus is close to uintx top margin there is a need to expand)

Parameters
modulusThe modulus
Returns
The inverse of *this modulo modulus

Definition at line 104 of file uintx_impl.hpp.

◆ length()

template<class base_uint >
static constexpr size_t bb::numeric::uintx< base_uint >::length ( )
inlinestaticconstexpr

Definition at line 55 of file uintx.hpp.

◆ mul_extended()

template<class base_uint >
std::pair< uintx< base_uint >, uintx< base_uint > > bb::numeric::uintx< base_uint >::mul_extended ( const uintx< base_uint > &  other) const

Definition at line 143 of file uintx_impl.hpp.

◆ operator base_uint()

template<class base_uint >
constexpr bb::numeric::uintx< base_uint >::operator base_uint ( ) const
inlineexplicitconstexpr

Definition at line 66 of file uintx.hpp.

◆ operator bool()

template<class base_uint >
constexpr bb::numeric::uintx< base_uint >::operator bool ( ) const
inlineexplicitconstexpr

Definition at line 60 of file uintx.hpp.

◆ operator uint16_t()

template<class base_uint >
constexpr bb::numeric::uintx< base_uint >::operator uint16_t ( ) const
inlineexplicitconstexpr

Definition at line 62 of file uintx.hpp.

◆ operator uint32_t()

template<class base_uint >
constexpr bb::numeric::uintx< base_uint >::operator uint32_t ( ) const
inlineexplicitconstexpr

Definition at line 63 of file uintx.hpp.

◆ operator uint64_t()

template<class base_uint >
constexpr bb::numeric::uintx< base_uint >::operator uint64_t ( ) const
inlineexplicitconstexpr

Definition at line 64 of file uintx.hpp.

◆ operator uint8_t()

template<class base_uint >
constexpr bb::numeric::uintx< base_uint >::operator uint8_t ( ) const
inlineexplicitconstexpr

Definition at line 61 of file uintx.hpp.

◆ operator!()

template<class base_uint >
bool bb::numeric::uintx< base_uint >::operator! ( ) const

Definition at line 207 of file uintx_impl.hpp.

◆ operator!=()

template<class base_uint >
bool bb::numeric::uintx< base_uint >::operator!= ( const uintx< base_uint > &  other) const

Definition at line 202 of file uintx_impl.hpp.

◆ operator%()

template<class base_uint >
uintx< base_uint > bb::numeric::uintx< base_uint >::operator% ( const uintx< base_uint > &  other) const

Definition at line 176 of file uintx_impl.hpp.

◆ operator%=()

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator%= ( const uintx< base_uint > &  other)
inline

Definition at line 224 of file uintx.hpp.

◆ operator&()

template<class base_uint >
constexpr uintx bb::numeric::uintx< base_uint >::operator& ( const uintx< base_uint > &  other) const
inlineconstexpr

Definition at line 188 of file uintx.hpp.

◆ operator&=()

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator&= ( const uintx< base_uint > &  other)
inline

Definition at line 242 of file uintx.hpp.

◆ operator*()

template<class base_uint >
uintx< base_uint > bb::numeric::uintx< base_uint >::operator* ( const uintx< base_uint > &  other) const

Definition at line 131 of file uintx_impl.hpp.

◆ operator*=()

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator*= ( const uintx< base_uint > &  other)
inline

Definition at line 213 of file uintx.hpp.

◆ operator+()

template<class base_uint >
constexpr uintx bb::numeric::uintx< base_uint >::operator+ ( const uintx< base_uint > &  other) const
inlineconstexpr

Definition at line 172 of file uintx.hpp.

◆ operator++()

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator++ ( )
inline

Definition at line 231 of file uintx.hpp.

◆ operator+=()

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator+= ( const uintx< base_uint > &  other)
inline

Definition at line 203 of file uintx.hpp.

◆ operator-() [1/2]

template<class base_uint >
uintx< base_uint > bb::numeric::uintx< base_uint >::operator- ( ) const

Definition at line 126 of file uintx_impl.hpp.

◆ operator-() [2/2]

template<class base_uint >
constexpr uintx bb::numeric::uintx< base_uint >::operator- ( const uintx< base_uint > &  other) const
inlineconstexpr

Definition at line 90 of file uintx.hpp.

◆ operator--()

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator-- ( )
inline

Definition at line 236 of file uintx.hpp.

◆ operator-=()

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator-= ( const uintx< base_uint > &  other)
inline

Definition at line 208 of file uintx.hpp.

◆ operator/()

template<class base_uint >
uintx< base_uint > bb::numeric::uintx< base_uint >::operator/ ( const uintx< base_uint > &  other) const

Definition at line 170 of file uintx_impl.hpp.

◆ operator/=()

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator/= ( const uintx< base_uint > &  other)
inline

Definition at line 218 of file uintx.hpp.

◆ operator<()

template<class base_uint >
bool bb::numeric::uintx< base_uint >::operator< ( const uintx< base_uint > &  other) const

Definition at line 226 of file uintx_impl.hpp.

◆ operator<<()

template<class base_uint >
constexpr uintx bb::numeric::uintx< base_uint >::operator<< ( const uint64_t  other) const
inlineconstexpr

Definition at line 99 of file uintx.hpp.

◆ operator<<=()

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator<<= ( const uint64_t  other)
inline

Definition at line 263 of file uintx.hpp.

◆ operator<=()

template<class base_uint >
bool bb::numeric::uintx< base_uint >::operator<= ( const uintx< base_uint > &  other) const

Definition at line 231 of file uintx_impl.hpp.

◆ operator=() [1/2]

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator= ( const uintx< base_uint > &  other)
default

◆ operator=() [2/2]

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator= ( uintx< base_uint > &&  other)
defaultnoexcept

◆ operator==()

template<class base_uint >
bool bb::numeric::uintx< base_uint >::operator== ( const uintx< base_uint > &  other) const

Definition at line 197 of file uintx_impl.hpp.

◆ operator>()

template<class base_uint >
bool bb::numeric::uintx< base_uint >::operator> ( const uintx< base_uint > &  other) const

Definition at line 212 of file uintx_impl.hpp.

◆ operator>=()

template<class base_uint >
bool bb::numeric::uintx< base_uint >::operator>= ( const uintx< base_uint > &  other) const

Definition at line 221 of file uintx_impl.hpp.

◆ operator>>()

template<class base_uint >
constexpr uintx bb::numeric::uintx< base_uint >::operator>> ( const uint64_t  other) const
inlineconstexpr

Definition at line 135 of file uintx.hpp.

◆ operator>>=()

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator>>= ( const uint64_t  other)
inline

Definition at line 258 of file uintx.hpp.

◆ operator^()

template<class base_uint >
uintx< base_uint > bb::numeric::uintx< base_uint >::operator^ ( const uintx< base_uint > &  other) const

Definition at line 182 of file uintx_impl.hpp.

◆ operator^=()

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator^= ( const uintx< base_uint > &  other)
inline

Definition at line 247 of file uintx.hpp.

◆ operator|()

template<class base_uint >
uintx< base_uint > bb::numeric::uintx< base_uint >::operator| ( const uintx< base_uint > &  other) const

Definition at line 187 of file uintx_impl.hpp.

◆ operator|=()

template<class base_uint >
uintx & bb::numeric::uintx< base_uint >::operator|= ( const uintx< base_uint > &  other)
inline

Definition at line 252 of file uintx.hpp.

◆ operator~()

template<class base_uint >
uintx< base_uint > bb::numeric::uintx< base_uint >::operator~ ( ) const

Definition at line 192 of file uintx_impl.hpp.

◆ slice()

template<class base_uint >
constexpr uintx bb::numeric::uintx< base_uint >::slice ( const uint64_t  start,
const uint64_t  end 
) const
inlineconstexpr

Viewing this as a bit string, and counting bits from 0, slices a substring.

Returns
the uintx equal to the substring of bits from (and including) the start-th bit, to (but excluding) the end-th bit of this. constexpr to be used in constant calculation.

Definition at line 82 of file uintx.hpp.

◆ unsafe_invmod()

template<class base_uint >
uintx< base_uint > bb::numeric::uintx< base_uint >::unsafe_invmod ( const uintx< base_uint > &  modulus) const

Computes invmod. Only for internal usage within the class. This is an insecure version of the algorithm that doesn't take into account the 0 case and cases when modulus is close to the top margin.

Parameters
modulusThe modulus of the ring
Returns
The inverse of *this modulo modulus

Definition at line 72 of file uintx_impl.hpp.

Member Data Documentation

◆ hi

template<class base_uint >
base_uint bb::numeric::uintx< base_uint >::hi

Definition at line 273 of file uintx.hpp.

◆ lo

template<class base_uint >
base_uint bb::numeric::uintx< base_uint >::lo

Definition at line 272 of file uintx.hpp.


The documentation for this class was generated from the following files: