Universal Numbers Library C++ API
sw::universal -- header-only custom arithmetic types (posit, cfloat, lns, fixpnt, dd/qd, and more)
Loading...
Searching...
No Matches
sw::universal::internal Namespace Reference

Classes

class  bitblock
struct  round_t
struct  round_t< 0, src_size >
class  uint128
struct  value_internal_exception
struct  value_shift_too_large
class  value

Functions

template<unsigned nbits>
bool twosComplementLessThan (const bitblock< nbits > &lhs, const bitblock< nbits > &rhs)
template<unsigned nbits>
bool operator== (const bitblock< nbits > &lhs, const bitblock< nbits > &rhs)
template<unsigned nbits>
bool operator< (const bitblock< nbits > &lhs, const bitblock< nbits > &rhs)
template<unsigned nbits>
bool operator<= (const bitblock< nbits > &lhs, const bitblock< nbits > &rhs)
template<unsigned nbits>
bool operator> (const bitblock< nbits > &lhs, const bitblock< nbits > &rhs)
template<unsigned nbits>
bool operator>= (const bitblock< nbits > &lhs, const bitblock< nbits > &rhs)
template<unsigned nbits>
bool increment_bitset (bitblock< nbits > &number)
template<unsigned nbits>
bool increment_unsigned (bitblock< nbits > &number, unsigned nrBits=nbits - 1)
template<unsigned nbits>
bool decrement_bitset (bitblock< nbits > &number)
template<unsigned nbits>
bool add_unsigned (bitblock< nbits > a, bitblock< nbits > b, bitblock< nbits+1 > &sum)
template<unsigned nbits>
bool subtract_unsigned (bitblock< nbits > a, bitblock< nbits > b, bitblock< nbits+1 > &dif)
template<unsigned nbits>
bool add_signed_magnitude (bitblock< nbits > a, bitblock< nbits > b, bitblock< nbits > &sum)
template<unsigned nbits>
bool subtract_signed_magnitude (bitblock< nbits > a, bitblock< nbits > b, bitblock< nbits > &diff)
template<unsigned nbits>
bitblock< nbits > extract_23b_fraction (uint32_t _23b_fraction_without_hidden_bit)
template<unsigned nbits>
bitblock< nbits > extract_52b_fraction (uint64_t _52b_fraction_without_hidden_bit)
template<unsigned nbits>
bitblock< nbits > extract_63b_fraction (uint64_t _63b_fraction_without_hidden_bit)
template<unsigned nbits>
bitblock< nbits > extract_long_double_fraction (uint128 &_112b_fraction_without_hidden_bit)
template<unsigned nbits>
bitblock< nbits > copy_integer_fraction (unsigned long long _fraction_without_hidden_bit)
template<unsigned src_size, unsigned tgt_size>
void copy_into (const bitblock< src_size > &src, unsigned shift, bitblock< tgt_size > &tgt)
template<unsigned src_size, unsigned tgt_size>
void copy_slice_into (bitblock< src_size > &src, bitblock< tgt_size > &tgt, unsigned begin=0, unsigned end=src_size, unsigned shift=0)
template<unsigned from, unsigned to, unsigned src_size>
bitblock< to - from > fixed_subset (const bitblock< src_size > &src)
template<unsigned src_size, unsigned tgt_size>
bool accumulate (const bitblock< src_size > &addend, bitblock< tgt_size > &accumulator)
template<unsigned operand_size>
void multiply_unsigned (const bitblock< operand_size > &a, const bitblock< operand_size > &b, bitblock< 2 *operand_size > &result)
template<unsigned src_size, unsigned tgt_size>
bool subtract (bitblock< tgt_size > &accumulator, const bitblock< src_size > &subtractand)
template<unsigned operand_size>
void integer_divide_unsigned (const bitblock< operand_size > &a, const bitblock< operand_size > &b, bitblock< 2 *operand_size > &result)
template<unsigned operand_size, unsigned result_size>
bool divide_with_fraction (const bitblock< operand_size > &a, const bitblock< operand_size > &b, bitblock< result_size > &result)
template<unsigned src_size, unsigned tgt_size>
void truncate (bitblock< src_size > &src, bitblock< tgt_size > &tgt)
template<unsigned tgt_size, unsigned src_size>
bitblock< tgt_size > round (const bitblock< src_size > &src, unsigned n)
 Round off n last bits of bitset src.
template<unsigned nbits>
int findMostSignificantBit (const bitblock< nbits > &bits)
template<unsigned nbits>
bitblock< nbits > ones_complement (bitblock< nbits > number)
template<unsigned nbits>
bitblock< nbits > twos_complement (bitblock< nbits > number)
template<unsigned nbits, class Type>
bitblock< nbits > convert_to_bitblock (Type number)
template<unsigned nbits>
std::string to_bit_string (bitblock< nbits > bits, bool separator=true)
template<unsigned nbits>
std::string to_hex (bitblock< nbits > bits, bool nibbleMarker=false, bool hexPrefix=true)
template<unsigned nbits>
std::string sign_magnitude_to_string (bitblock< nbits > bits)
template<unsigned nbits>
bitblock< nbits > flip_sign_bit (bitblock< nbits > number)
template<unsigned nbits>
bool anyAfter (const bitblock< nbits > &bits, int msb)
template<unsigned fbits>
value< fbits > abs (const value< fbits > &v)
template<unsigned nfbits>
std::string convert_to_string (std::ios_base::fmtflags flags, const value< nfbits > &v, std::streamsize precision=0)
template<unsigned nfbits>
std::ostream & operator<< (std::ostream &ostr, const value< nfbits > &v)
template<unsigned nfbits>
std::istream & operator>> (std::istream &istr, const value< nfbits > &v)
template<unsigned nfbits>
bool operator== (const value< nfbits > &lhs, const value< nfbits > &rhs)
template<unsigned nfbits>
bool operator!= (const value< nfbits > &lhs, const value< nfbits > &rhs)
template<unsigned nfbits>
bool operator< (const value< nfbits > &lhs, const value< nfbits > &rhs)
template<unsigned nfbits>
bool operator> (const value< nfbits > &lhs, const value< nfbits > &rhs)
template<unsigned nfbits>
bool operator<= (const value< nfbits > &lhs, const value< nfbits > &rhs)
template<unsigned nfbits>
bool operator>= (const value< nfbits > &lhs, const value< nfbits > &rhs)
template<unsigned nbits>
std::string to_binary (const bitblock< nbits > &a, bool nibbleMarker=true)
template<unsigned fbits>
std::string to_triple (const value< fbits > &v, bool nibbleMarker=true)
template<unsigned nfbits>
value< nfbits > abs (const value< nfbits > &v)
 Magnitude of a scientific notation value (equivalent to turning the sign bit off).
template<unsigned tgtbits, unsigned srcbits>
value< tgtbits > widen_value (const value< srcbits > &v)
template<unsigned fbits, unsigned abits>
bool sum_special_cases (const value< fbits > &lhs, const value< fbits > &rhs, value< abits+1 > &result)
template<unsigned fbits, unsigned abits>
void module_add (const value< fbits > &lhs, const value< fbits > &rhs, value< abits+1 > &result)
template<unsigned fbits, unsigned abits>
void module_subtract (const value< fbits > &lhs, const value< fbits > &rhs, value< abits+1 > &result)
template<unsigned fbits, unsigned abits>
void module_subtract_BROKEN (const value< fbits > &lhs, const value< fbits > &rhs, value< abits+1 > &result)
template<unsigned fbits, unsigned mbits>
void module_multiply (const value< fbits > &lhs, const value< fbits > &rhs, value< mbits > &result)
template<unsigned fbits, unsigned divbits>
void module_divide (const value< fbits > &lhs, const value< fbits > &rhs, value< divbits > &result)
template<unsigned fbits>
value< fbits > operator+ (const value< fbits > &lhs, const value< fbits > &rhs)
template<unsigned fbits>
value< fbits > operator- (const value< fbits > &lhs, const value< fbits > &rhs)
template<unsigned fbits>
value< fbits > operator* (const value< fbits > &lhs, const value< fbits > &rhs)
template<unsigned fbits>
value< fbits > operator/ (const value< fbits > &lhs, const value< fbits > &rhs)
template<unsigned fbits>
value< fbits > sqrt (const value< fbits > &a)
template<typename Uint, typename Real>
BIT_CAST_CONSTEXPR int _extractExponent (Real v) noexcept
template<typename Uint, typename Real>
Uint _extractFraction (Real v) noexcept
template<typename Uint, typename Real>
Uint _extractSignificand (Real v) noexcept

Variables

constexpr bool _trace_value_conversion = false
constexpr bool _trace_value_add = false
constexpr bool _trace_value_sub = false
constexpr bool _trace_value_mul = false
constexpr bool _trace_value_div = false

Function Documentation

◆ _extractExponent()

template<typename Uint, typename Real>
BIT_CAST_CONSTEXPR int sw::universal::internal::_extractExponent ( Real v)
noexcept

◆ _extractFraction()

template<typename Uint, typename Real>
Uint sw::universal::internal::_extractFraction ( Real v)
noexcept

◆ _extractSignificand()

template<typename Uint, typename Real>
Uint sw::universal::internal::_extractSignificand ( Real v)
noexcept

◆ abs() [1/2]

template<unsigned fbits>
value< fbits > sw::universal::internal::abs ( const value< fbits > & v)

◆ abs() [2/2]

template<unsigned nfbits>
value< nfbits > sw::universal::internal::abs ( const value< nfbits > & v)

Magnitude of a scientific notation value (equivalent to turning the sign bit off).

◆ accumulate()

template<unsigned src_size, unsigned tgt_size>
bool sw::universal::internal::accumulate ( const bitblock< src_size > & addend,
bitblock< tgt_size > & accumulator )

◆ add_signed_magnitude()

template<unsigned nbits>
bool sw::universal::internal::add_signed_magnitude ( bitblock< nbits > a,
bitblock< nbits > b,
bitblock< nbits > & sum )

◆ add_unsigned()

template<unsigned nbits>
bool sw::universal::internal::add_unsigned ( bitblock< nbits > a,
bitblock< nbits > b,
bitblock< nbits+1 > & sum )

◆ anyAfter()

template<unsigned nbits>
bool sw::universal::internal::anyAfter ( const bitblock< nbits > & bits,
int msb )

◆ convert_to_bitblock()

template<unsigned nbits, class Type>
bitblock< nbits > sw::universal::internal::convert_to_bitblock ( Type number)

◆ convert_to_string()

template<unsigned nfbits>
std::string sw::universal::internal::convert_to_string ( std::ios_base::fmtflags flags,
const value< nfbits > & v,
std::streamsize precision = 0 )
inline

◆ copy_integer_fraction()

template<unsigned nbits>
bitblock< nbits > sw::universal::internal::copy_integer_fraction ( unsigned long long _fraction_without_hidden_bit)

◆ copy_into()

template<unsigned src_size, unsigned tgt_size>
void sw::universal::internal::copy_into ( const bitblock< src_size > & src,
unsigned shift,
bitblock< tgt_size > & tgt )

◆ copy_slice_into()

template<unsigned src_size, unsigned tgt_size>
void sw::universal::internal::copy_slice_into ( bitblock< src_size > & src,
bitblock< tgt_size > & tgt,
unsigned begin = 0,
unsigned end = src_size,
unsigned shift = 0 )

◆ decrement_bitset()

template<unsigned nbits>
bool sw::universal::internal::decrement_bitset ( bitblock< nbits > & number)

◆ divide_with_fraction()

template<unsigned operand_size, unsigned result_size>
bool sw::universal::internal::divide_with_fraction ( const bitblock< operand_size > & a,
const bitblock< operand_size > & b,
bitblock< result_size > & result )

◆ extract_23b_fraction()

template<unsigned nbits>
bitblock< nbits > sw::universal::internal::extract_23b_fraction ( uint32_t _23b_fraction_without_hidden_bit)

◆ extract_52b_fraction()

template<unsigned nbits>
bitblock< nbits > sw::universal::internal::extract_52b_fraction ( uint64_t _52b_fraction_without_hidden_bit)

◆ extract_63b_fraction()

template<unsigned nbits>
bitblock< nbits > sw::universal::internal::extract_63b_fraction ( uint64_t _63b_fraction_without_hidden_bit)

◆ extract_long_double_fraction()

template<unsigned nbits>
bitblock< nbits > sw::universal::internal::extract_long_double_fraction ( uint128 & _112b_fraction_without_hidden_bit)

◆ findMostSignificantBit()

template<unsigned nbits>
int sw::universal::internal::findMostSignificantBit ( const bitblock< nbits > & bits)

◆ fixed_subset()

template<unsigned from, unsigned to, unsigned src_size>
bitblock< to - from > sw::universal::internal::fixed_subset ( const bitblock< src_size > & src)

◆ flip_sign_bit()

template<unsigned nbits>
bitblock< nbits > sw::universal::internal::flip_sign_bit ( bitblock< nbits > number)

◆ increment_bitset()

template<unsigned nbits>
bool sw::universal::internal::increment_bitset ( bitblock< nbits > & number)

◆ increment_unsigned()

template<unsigned nbits>
bool sw::universal::internal::increment_unsigned ( bitblock< nbits > & number,
unsigned nrBits = nbits - 1 )

◆ integer_divide_unsigned()

template<unsigned operand_size>
void sw::universal::internal::integer_divide_unsigned ( const bitblock< operand_size > & a,
const bitblock< operand_size > & b,
bitblock< 2 *operand_size > & result )

◆ module_add()

template<unsigned fbits, unsigned abits>
void sw::universal::internal::module_add ( const value< fbits > & lhs,
const value< fbits > & rhs,
value< abits+1 > & result )

◆ module_divide()

template<unsigned fbits, unsigned divbits>
void sw::universal::internal::module_divide ( const value< fbits > & lhs,
const value< fbits > & rhs,
value< divbits > & result )

◆ module_multiply()

template<unsigned fbits, unsigned mbits>
void sw::universal::internal::module_multiply ( const value< fbits > & lhs,
const value< fbits > & rhs,
value< mbits > & result )

◆ module_subtract()

template<unsigned fbits, unsigned abits>
void sw::universal::internal::module_subtract ( const value< fbits > & lhs,
const value< fbits > & rhs,
value< abits+1 > & result )

◆ module_subtract_BROKEN()

template<unsigned fbits, unsigned abits>
void sw::universal::internal::module_subtract_BROKEN ( const value< fbits > & lhs,
const value< fbits > & rhs,
value< abits+1 > & result )

◆ multiply_unsigned()

template<unsigned operand_size>
void sw::universal::internal::multiply_unsigned ( const bitblock< operand_size > & a,
const bitblock< operand_size > & b,
bitblock< 2 *operand_size > & result )

◆ ones_complement()

template<unsigned nbits>
bitblock< nbits > sw::universal::internal::ones_complement ( bitblock< nbits > number)

◆ operator!=()

template<unsigned nfbits>
bool sw::universal::internal::operator!= ( const value< nfbits > & lhs,
const value< nfbits > & rhs )
inline

◆ operator*()

template<unsigned fbits>
value< fbits > sw::universal::internal::operator* ( const value< fbits > & lhs,
const value< fbits > & rhs )

◆ operator+()

template<unsigned fbits>
value< fbits > sw::universal::internal::operator+ ( const value< fbits > & lhs,
const value< fbits > & rhs )

◆ operator-()

template<unsigned fbits>
value< fbits > sw::universal::internal::operator- ( const value< fbits > & lhs,
const value< fbits > & rhs )

◆ operator/()

template<unsigned fbits>
value< fbits > sw::universal::internal::operator/ ( const value< fbits > & lhs,
const value< fbits > & rhs )

◆ operator<() [1/2]

template<unsigned nbits>
bool sw::universal::internal::operator< ( const bitblock< nbits > & lhs,
const bitblock< nbits > & rhs )

◆ operator<() [2/2]

template<unsigned nfbits>
bool sw::universal::internal::operator< ( const value< nfbits > & lhs,
const value< nfbits > & rhs )
inline

◆ operator<<()

template<unsigned nfbits>
std::ostream & sw::universal::internal::operator<< ( std::ostream & ostr,
const value< nfbits > & v )
inline

◆ operator<=() [1/2]

template<unsigned nbits>
bool sw::universal::internal::operator<= ( const bitblock< nbits > & lhs,
const bitblock< nbits > & rhs )

◆ operator<=() [2/2]

template<unsigned nfbits>
bool sw::universal::internal::operator<= ( const value< nfbits > & lhs,
const value< nfbits > & rhs )
inline

◆ operator==() [1/2]

template<unsigned nbits>
bool sw::universal::internal::operator== ( const bitblock< nbits > & lhs,
const bitblock< nbits > & rhs )

◆ operator==() [2/2]

template<unsigned nfbits>
bool sw::universal::internal::operator== ( const value< nfbits > & lhs,
const value< nfbits > & rhs )
inline

◆ operator>() [1/2]

template<unsigned nbits>
bool sw::universal::internal::operator> ( const bitblock< nbits > & lhs,
const bitblock< nbits > & rhs )

◆ operator>() [2/2]

template<unsigned nfbits>
bool sw::universal::internal::operator> ( const value< nfbits > & lhs,
const value< nfbits > & rhs )
inline

◆ operator>=() [1/2]

template<unsigned nbits>
bool sw::universal::internal::operator>= ( const bitblock< nbits > & lhs,
const bitblock< nbits > & rhs )

◆ operator>=() [2/2]

template<unsigned nfbits>
bool sw::universal::internal::operator>= ( const value< nfbits > & lhs,
const value< nfbits > & rhs )
inline

◆ operator>>()

template<unsigned nfbits>
std::istream & sw::universal::internal::operator>> ( std::istream & istr,
const value< nfbits > & v )
inline

◆ round()

template<unsigned tgt_size, unsigned src_size>
bitblock< tgt_size > sw::universal::internal::round ( const bitblock< src_size > & src,
unsigned n )

Round off n last bits of bitset src.

Round to nearest resulting in potentially smaller bitset. Doesn't return carry bit in case of overflow while rounding up! TODO: Check whether we need carry or we require an extra bit for this case.

◆ sign_magnitude_to_string()

template<unsigned nbits>
std::string sw::universal::internal::sign_magnitude_to_string ( bitblock< nbits > bits)

◆ sqrt()

template<unsigned fbits>
value< fbits > sw::universal::internal::sqrt ( const value< fbits > & a)

◆ subtract()

template<unsigned src_size, unsigned tgt_size>
bool sw::universal::internal::subtract ( bitblock< tgt_size > & accumulator,
const bitblock< src_size > & subtractand )

◆ subtract_signed_magnitude()

template<unsigned nbits>
bool sw::universal::internal::subtract_signed_magnitude ( bitblock< nbits > a,
bitblock< nbits > b,
bitblock< nbits > & diff )

◆ subtract_unsigned()

template<unsigned nbits>
bool sw::universal::internal::subtract_unsigned ( bitblock< nbits > a,
bitblock< nbits > b,
bitblock< nbits+1 > & dif )

◆ sum_special_cases()

template<unsigned fbits, unsigned abits>
bool sw::universal::internal::sum_special_cases ( const value< fbits > & lhs,
const value< fbits > & rhs,
value< abits+1 > & result )

◆ to_binary()

template<unsigned nbits>
std::string sw::universal::internal::to_binary ( const bitblock< nbits > & a,
bool nibbleMarker = true )
inline

◆ to_bit_string()

template<unsigned nbits>
std::string sw::universal::internal::to_bit_string ( bitblock< nbits > bits,
bool separator = true )

◆ to_hex()

template<unsigned nbits>
std::string sw::universal::internal::to_hex ( bitblock< nbits > bits,
bool nibbleMarker = false,
bool hexPrefix = true )

◆ to_triple()

template<unsigned fbits>
std::string sw::universal::internal::to_triple ( const value< fbits > & v,
bool nibbleMarker = true )
inline

◆ truncate()

template<unsigned src_size, unsigned tgt_size>
void sw::universal::internal::truncate ( bitblock< src_size > & src,
bitblock< tgt_size > & tgt )

◆ twos_complement()

template<unsigned nbits>
bitblock< nbits > sw::universal::internal::twos_complement ( bitblock< nbits > number)

◆ twosComplementLessThan()

template<unsigned nbits>
bool sw::universal::internal::twosComplementLessThan ( const bitblock< nbits > & lhs,
const bitblock< nbits > & rhs )

◆ widen_value()

template<unsigned tgtbits, unsigned srcbits>
value< tgtbits > sw::universal::internal::widen_value ( const value< srcbits > & v)

Variable Documentation

◆ _trace_value_add

bool sw::universal::internal::_trace_value_add = false
constexpr

◆ _trace_value_conversion

bool sw::universal::internal::_trace_value_conversion = false
constexpr

◆ _trace_value_div

bool sw::universal::internal::_trace_value_div = false
constexpr

◆ _trace_value_mul

bool sw::universal::internal::_trace_value_mul = false
constexpr

◆ _trace_value_sub

bool sw::universal::internal::_trace_value_sub = false
constexpr