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::blocksignificand< _nbits, bt > Class Template Reference

a block-based floating-point significand for add/sub in 2's complement of the form ##h.fffff for mul in sign-magnitude form expanded to 0'00001.fffff for div in sign-magnitude form expanded to 00000'00001'fffff More...

#include <blocksignificand.hpp>

Public Types

typedef bt BlockType

Public Member Functions

constexpr blocksignificand () noexcept
template<size_t... I>
constexpr blocksignificand (const uint64_t raw, int radixPoint, std::index_sequence< I... >) noexcept
constexpr blocksignificand (const uint64_t raw, int radixPoint) noexcept
constexpr blocksignificand (const blocksignificand &) noexcept=default
constexpr blocksignificand (blocksignificand &&) noexcept=default
constexpr blocksignificand & operator= (const blocksignificand &) noexcept=default
constexpr blocksignificand & operator= (blocksignificand &&) noexcept=default
constexpr operator float () const noexcept
 explicit conversion operators
constexpr operator double () const noexcept
constexpr blocksignificand operator~ () const noexcept
 prefix operators
constexpr bool anyAfter (unsigned bitIndex) const noexcept
 logic operators
constexpr void increment () noexcept
 arithmetic operators
constexpr void add (const blocksignificand &lhs, const blocksignificand &rhs) noexcept
 add two fractions of the form 00h.fffff, that is, radix point at nbits-3 In this encoding, all valid values are encapsulated
constexpr void sub (const blocksignificand &lhs, const blocksignificand &rhs) noexcept
constexpr void mul (const blocksignificand &lhs, const blocksignificand &rhs) noexcept
constexpr void div (const blocksignificand &lhs, const blocksignificand &rhs) noexcept
constexpr blocksignificand & operator<<= (int bitsToShift) noexcept
constexpr blocksignificand & operator>>= (int bitsToShift) noexcept
constexpr void clear () noexcept
constexpr void setzero () noexcept
constexpr void setradix (int radix) noexcept
constexpr void setbit (unsigned i, bool v=true) noexcept
constexpr void setblock (unsigned b, const bt &block) noexcept
constexpr void setbits (uint64_t value) noexcept
constexpr blocksignificand & flip () noexcept
constexpr blocksignificand & twosComplement () noexcept
constexpr bool iszero () const noexcept
constexpr int radix () const noexcept
constexpr bool isodd () const noexcept
constexpr bool iseven () const noexcept
constexpr bool sign () const noexcept
constexpr bool isneg () const noexcept
constexpr bool test (unsigned bitIndex) const noexcept
constexpr bool at (unsigned bitIndex) const noexcept
constexpr bool checkCarry () const noexcept
constexpr uint8_t nibble (unsigned n) const noexcept
constexpr bt block (unsigned b) const noexcept
constexpr blocksignificand fraction () const noexcept
constexpr uint64_t fraction_ull () const noexcept
constexpr bool unsigned_less (const blocksignificand &rhs) const noexcept
template<size_t... I>
constexpr uint64_t significand_ull (std::index_sequence< I... >={}) const noexcept
constexpr int msb () const noexcept
constexpr float to_float () const noexcept
constexpr double to_double (bool twosComplement=true) const noexcept
constexpr bool roundingDirection (unsigned targetLsb) const noexcept
constexpr bool any (unsigned msb) const noexcept

Public Attributes

int radixPoint
BitEncoding encoding
bt _block [nrBlocks]

Static Public Attributes

static constexpr unsigned nbits = _nbits
static constexpr unsigned bitsInByte = 8
static constexpr unsigned bitsInBlock = sizeof(bt) * bitsInByte
static constexpr unsigned nrBlocks = 1ull + ((nbits - 1ull) / bitsInBlock)
static constexpr uint64_t storageMask = (0xFFFF'FFFF'FFFF'FFFFull >> (64 - bitsInBlock))
static constexpr uint64_t maxRightShift = ((64 - nbits + 3) > 62) ? 63 : (64 - nbits + 3)
static constexpr uint64_t fmask = (64 - nbits + 3) > 63 ? 0ull : (0xFFFF'FFFF'FFFF'FFFFull >> maxRightShift)
static constexpr unsigned MSU = nrBlocks - 1
static constexpr bt ALL_ONES = bt(~0)
static constexpr bt MSU_MASK = (ALL_ONES >> (nrBlocks * bitsInBlock - nbits))
static constexpr bt OVERFLOW_BIT = ~(MSU_MASK >> 1) & MSU_MASK

Protected Member Functions

constexpr void to_limbs (std::uint32_t *limbs) const noexcept
constexpr void from_limbs (const std::uint32_t *limbs) noexcept

Static Protected Attributes

static constexpr unsigned nrLimbs = (nbits + 31u) / 32u

Friends

constexpr bool operator== (const blocksignificand &lhs, const blocksignificand &rhs) noexcept
constexpr bool operator!= (const blocksignificand &lhs, const blocksignificand &rhs) noexcept
constexpr bool operator< (const blocksignificand &lhs, const blocksignificand &rhs) noexcept
constexpr bool operator<= (const blocksignificand &lhs, const blocksignificand &rhs) noexcept
constexpr bool operator> (const blocksignificand &lhs, const blocksignificand &rhs) noexcept
constexpr bool operator>= (const blocksignificand &lhs, const blocksignificand &rhs) noexcept
constexpr blocksignificand operator<< (const blocksignificand &a, const long b) noexcept
constexpr blocksignificand operator>> (const blocksignificand &a, const long b) noexcept

Detailed Description

template<unsigned _nbits, typename bt>
class sw::universal::blocksignificand< _nbits, bt >

a block-based floating-point significand for add/sub in 2's complement of the form ##h.fffff for mul in sign-magnitude form expanded to 0'00001.fffff for div in sign-magnitude form expanded to 00000'00001'fffff

The bits behave like a binary integer; blocktriple supplies the radix point and encoding interpretation for the current arithmetic path.

NOTE: don't set a default blocktype as this makes the integration more brittle as blocktriple uses the blocksignificand as storage class and needs to interact with the client number system, which also is blocked. Using the same blocktype simplifies the copying of exponent and fraction bits from and to the client.

Template Parameters
bt

Member Typedef Documentation

◆ BlockType

template<unsigned _nbits, typename bt>
typedef bt sw::universal::blocksignificand< _nbits, bt >::BlockType

Constructor & Destructor Documentation

◆ blocksignificand() [1/5]

template<unsigned _nbits, typename bt>
sw::universal::blocksignificand< _nbits, bt >::blocksignificand ( )
inlineconstexprnoexcept

◆ blocksignificand() [2/5]

template<unsigned _nbits, typename bt>
template<size_t... I>
sw::universal::blocksignificand< _nbits, bt >::blocksignificand ( const uint64_t raw,
int radixPoint,
std::index_sequence< I... >  )
inlineconstexprnoexcept

◆ blocksignificand() [3/5]

template<unsigned _nbits, typename bt>
sw::universal::blocksignificand< _nbits, bt >::blocksignificand ( const uint64_t raw,
int radixPoint )
inlineconstexprnoexcept

◆ blocksignificand() [4/5]

template<unsigned _nbits, typename bt>
sw::universal::blocksignificand< _nbits, bt >::blocksignificand ( const blocksignificand< _nbits, bt > & )
constexprdefaultnoexcept

◆ blocksignificand() [5/5]

template<unsigned _nbits, typename bt>
sw::universal::blocksignificand< _nbits, bt >::blocksignificand ( blocksignificand< _nbits, bt > && )
constexprdefaultnoexcept

Member Function Documentation

◆ add()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::add ( const blocksignificand< _nbits, bt > & lhs,
const blocksignificand< _nbits, bt > & rhs )
inlineconstexprnoexcept

add two fractions of the form 00h.fffff, that is, radix point at nbits-3 In this encoding, all valid values are encapsulated

Parameters
lhsnbits of fraction in the form 00h.ffff
rhsnbits of fraction in the form 00h.ffff

◆ any()

template<unsigned _nbits, typename bt>
bool sw::universal::blocksignificand< _nbits, bt >::any ( unsigned msb) const
inlineconstexprnoexcept

◆ anyAfter()

template<unsigned _nbits, typename bt>
bool sw::universal::blocksignificand< _nbits, bt >::anyAfter ( unsigned bitIndex) const
inlineconstexprnoexcept

logic operators

◆ at()

template<unsigned _nbits, typename bt>
bool sw::universal::blocksignificand< _nbits, bt >::at ( unsigned bitIndex) const
inlineconstexprnoexcept

◆ block()

template<unsigned _nbits, typename bt>
bt sw::universal::blocksignificand< _nbits, bt >::block ( unsigned b) const
inlineconstexprnoexcept

◆ checkCarry()

template<unsigned _nbits, typename bt>
bool sw::universal::blocksignificand< _nbits, bt >::checkCarry ( ) const
inlineconstexprnoexcept

◆ clear()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::clear ( )
inlineconstexprnoexcept

◆ div()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::div ( const blocksignificand< _nbits, bt > & lhs,
const blocksignificand< _nbits, bt > & rhs )
inlineconstexprnoexcept

◆ flip()

template<unsigned _nbits, typename bt>
blocksignificand & sw::universal::blocksignificand< _nbits, bt >::flip ( )
inlineconstexprnoexcept

◆ fraction()

template<unsigned _nbits, typename bt>
blocksignificand sw::universal::blocksignificand< _nbits, bt >::fraction ( ) const
inlineconstexprnoexcept

◆ fraction_ull()

template<unsigned _nbits, typename bt>
uint64_t sw::universal::blocksignificand< _nbits, bt >::fraction_ull ( ) const
inlineconstexprnoexcept

◆ from_limbs()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::from_limbs ( const std::uint32_t * limbs)
inlineconstexprprotectednoexcept

◆ increment()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::increment ( )
inlineconstexprnoexcept

arithmetic operators

increment the value by one

◆ iseven()

template<unsigned _nbits, typename bt>
bool sw::universal::blocksignificand< _nbits, bt >::iseven ( ) const
inlineconstexprnoexcept

◆ isneg()

template<unsigned _nbits, typename bt>
bool sw::universal::blocksignificand< _nbits, bt >::isneg ( ) const
inlineconstexprnoexcept

◆ isodd()

template<unsigned _nbits, typename bt>
bool sw::universal::blocksignificand< _nbits, bt >::isodd ( ) const
inlineconstexprnoexcept

◆ iszero()

template<unsigned _nbits, typename bt>
bool sw::universal::blocksignificand< _nbits, bt >::iszero ( ) const
inlineconstexprnoexcept

◆ msb()

template<unsigned _nbits, typename bt>
int sw::universal::blocksignificand< _nbits, bt >::msb ( ) const
inlineconstexprnoexcept

◆ mul()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::mul ( const blocksignificand< _nbits, bt > & lhs,
const blocksignificand< _nbits, bt > & rhs )
inlineconstexprnoexcept

◆ nibble()

template<unsigned _nbits, typename bt>
uint8_t sw::universal::blocksignificand< _nbits, bt >::nibble ( unsigned n) const
inlineconstexprnoexcept

◆ operator double()

template<unsigned _nbits, typename bt>
sw::universal::blocksignificand< _nbits, bt >::operator double ( ) const
inlineexplicitconstexprnoexcept

◆ operator float()

template<unsigned _nbits, typename bt>
sw::universal::blocksignificand< _nbits, bt >::operator float ( ) const
inlineexplicitconstexprnoexcept

explicit conversion operators

◆ operator<<=()

template<unsigned _nbits, typename bt>
blocksignificand & sw::universal::blocksignificand< _nbits, bt >::operator<<= ( int bitsToShift)
inlineconstexprnoexcept

◆ operator=() [1/2]

template<unsigned _nbits, typename bt>
blocksignificand & sw::universal::blocksignificand< _nbits, bt >::operator= ( blocksignificand< _nbits, bt > && )
constexprdefaultnoexcept

◆ operator=() [2/2]

template<unsigned _nbits, typename bt>
blocksignificand & sw::universal::blocksignificand< _nbits, bt >::operator= ( const blocksignificand< _nbits, bt > & )
constexprdefaultnoexcept

◆ operator>>=()

template<unsigned _nbits, typename bt>
blocksignificand & sw::universal::blocksignificand< _nbits, bt >::operator>>= ( int bitsToShift)
inlineconstexprnoexcept

◆ operator~()

template<unsigned _nbits, typename bt>
blocksignificand sw::universal::blocksignificand< _nbits, bt >::operator~ ( ) const
inlineconstexprnoexcept

prefix operators

◆ radix()

template<unsigned _nbits, typename bt>
int sw::universal::blocksignificand< _nbits, bt >::radix ( ) const
inlineconstexprnoexcept

◆ roundingDirection()

template<unsigned _nbits, typename bt>
bool sw::universal::blocksignificand< _nbits, bt >::roundingDirection ( unsigned targetLsb) const
inlineconstexprnoexcept

◆ setbit()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::setbit ( unsigned i,
bool v = true )
inlineconstexprnoexcept

◆ setbits()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::setbits ( uint64_t value)
inlineconstexprnoexcept

◆ setblock()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::setblock ( unsigned b,
const bt & block )
inlineconstexprnoexcept

◆ setradix()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::setradix ( int radix)
inlineconstexprnoexcept

◆ setzero()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::setzero ( )
inlineconstexprnoexcept

◆ sign()

template<unsigned _nbits, typename bt>
bool sw::universal::blocksignificand< _nbits, bt >::sign ( ) const
inlineconstexprnoexcept

◆ significand_ull()

template<unsigned _nbits, typename bt>
template<size_t... I>
uint64_t sw::universal::blocksignificand< _nbits, bt >::significand_ull ( std::index_sequence< I... > = {}) const
inlineconstexprnoexcept

◆ sub()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::sub ( const blocksignificand< _nbits, bt > & lhs,
const blocksignificand< _nbits, bt > & rhs )
inlineconstexprnoexcept

◆ test()

template<unsigned _nbits, typename bt>
bool sw::universal::blocksignificand< _nbits, bt >::test ( unsigned bitIndex) const
inlineconstexprnoexcept

◆ to_double()

template<unsigned _nbits, typename bt>
double sw::universal::blocksignificand< _nbits, bt >::to_double ( bool twosComplement = true) const
inlineconstexprnoexcept

◆ to_float()

template<unsigned _nbits, typename bt>
float sw::universal::blocksignificand< _nbits, bt >::to_float ( ) const
inlineconstexprnoexcept

◆ to_limbs()

template<unsigned _nbits, typename bt>
void sw::universal::blocksignificand< _nbits, bt >::to_limbs ( std::uint32_t * limbs) const
inlineconstexprprotectednoexcept

◆ twosComplement()

template<unsigned _nbits, typename bt>
blocksignificand & sw::universal::blocksignificand< _nbits, bt >::twosComplement ( )
inlineconstexprnoexcept

◆ unsigned_less()

template<unsigned _nbits, typename bt>
bool sw::universal::blocksignificand< _nbits, bt >::unsigned_less ( const blocksignificand< _nbits, bt > & rhs) const
inlineconstexprnoexcept

◆ operator!=

template<unsigned _nbits, typename bt>
bool operator!= ( const blocksignificand< _nbits, bt > & lhs,
const blocksignificand< _nbits, bt > & rhs )
friend

◆ operator<

template<unsigned _nbits, typename bt>
bool operator< ( const blocksignificand< _nbits, bt > & lhs,
const blocksignificand< _nbits, bt > & rhs )
friend

◆ operator<<

template<unsigned _nbits, typename bt>
blocksignificand operator<< ( const blocksignificand< _nbits, bt > & a,
const long b )
friend

◆ operator<=

template<unsigned _nbits, typename bt>
bool operator<= ( const blocksignificand< _nbits, bt > & lhs,
const blocksignificand< _nbits, bt > & rhs )
friend

◆ operator==

template<unsigned _nbits, typename bt>
bool operator== ( const blocksignificand< _nbits, bt > & lhs,
const blocksignificand< _nbits, bt > & rhs )
friend

◆ operator>

template<unsigned _nbits, typename bt>
bool operator> ( const blocksignificand< _nbits, bt > & lhs,
const blocksignificand< _nbits, bt > & rhs )
friend

◆ operator>=

template<unsigned _nbits, typename bt>
bool operator>= ( const blocksignificand< _nbits, bt > & lhs,
const blocksignificand< _nbits, bt > & rhs )
friend

◆ operator>>

template<unsigned _nbits, typename bt>
blocksignificand operator>> ( const blocksignificand< _nbits, bt > & a,
const long b )
friend

Member Data Documentation

◆ _block

template<unsigned _nbits, typename bt>
bt sw::universal::blocksignificand< _nbits, bt >::_block[nrBlocks]

◆ ALL_ONES

template<unsigned _nbits, typename bt>
bt sw::universal::blocksignificand< _nbits, bt >::ALL_ONES = bt(~0)
staticconstexpr

◆ bitsInBlock

template<unsigned _nbits, typename bt>
unsigned sw::universal::blocksignificand< _nbits, bt >::bitsInBlock = sizeof(bt) * bitsInByte
staticconstexpr

◆ bitsInByte

template<unsigned _nbits, typename bt>
unsigned sw::universal::blocksignificand< _nbits, bt >::bitsInByte = 8
staticconstexpr

◆ encoding

template<unsigned _nbits, typename bt>
BitEncoding sw::universal::blocksignificand< _nbits, bt >::encoding

◆ fmask

template<unsigned _nbits, typename bt>
uint64_t sw::universal::blocksignificand< _nbits, bt >::fmask = (64 - nbits + 3) > 63 ? 0ull : (0xFFFF'FFFF'FFFF'FFFFull >> maxRightShift)
staticconstexpr

◆ maxRightShift

template<unsigned _nbits, typename bt>
uint64_t sw::universal::blocksignificand< _nbits, bt >::maxRightShift = ((64 - nbits + 3) > 62) ? 63 : (64 - nbits + 3)
staticconstexpr

◆ MSU

template<unsigned _nbits, typename bt>
unsigned sw::universal::blocksignificand< _nbits, bt >::MSU = nrBlocks - 1
staticconstexpr

◆ MSU_MASK

template<unsigned _nbits, typename bt>
bt sw::universal::blocksignificand< _nbits, bt >::MSU_MASK = (ALL_ONES >> (nrBlocks * bitsInBlock - nbits))
staticconstexpr

◆ nbits

template<unsigned _nbits, typename bt>
unsigned sw::universal::blocksignificand< _nbits, bt >::nbits = _nbits
staticconstexpr

◆ nrBlocks

template<unsigned _nbits, typename bt>
unsigned sw::universal::blocksignificand< _nbits, bt >::nrBlocks = 1ull + ((nbits - 1ull) / bitsInBlock)
staticconstexpr

◆ nrLimbs

template<unsigned _nbits, typename bt>
unsigned sw::universal::blocksignificand< _nbits, bt >::nrLimbs = (nbits + 31u) / 32u
staticconstexprprotected

◆ OVERFLOW_BIT

template<unsigned _nbits, typename bt>
bt sw::universal::blocksignificand< _nbits, bt >::OVERFLOW_BIT = ~(MSU_MASK >> 1) & MSU_MASK
staticconstexpr

◆ radixPoint

template<unsigned _nbits, typename bt>
int sw::universal::blocksignificand< _nbits, bt >::radixPoint

◆ storageMask

template<unsigned _nbits, typename bt>
uint64_t sw::universal::blocksignificand< _nbits, bt >::storageMask = (0xFFFF'FFFF'FFFF'FFFFull >> (64 - bitsInBlock))
staticconstexpr

The documentation for this class was generated from the following file:
  • /home/runner/work/universal/universal/include/sw/universal/internal/blocksignificand/blocksignificand.hpp