fix_base.h
Go to the documentation of this file.
#ifndef FIX_BASE_H
#define FIX_BASE_H
#include <itpp/base/ittypes.h>
#include <itpp/stat/misc_stat.h>
#include <itpp/itexports.h>
namespace itpp
{
typedef int64_t fixrep;
const int MAX_WORDLEN = 64;
const uint64_t UINT64_POW2[64] = {
uint64_t(1), uint64_t(1) << 1, uint64_t(1) << 2, uint64_t(1) << 3, uint64_t(1) << 4,
uint64_t(1) << 5, uint64_t(1) << 6, uint64_t(1) << 7, uint64_t(1) << 8, uint64_t(1) << 9,
uint64_t(1) << 10, uint64_t(1) << 11, uint64_t(1) << 12, uint64_t(1) << 13, uint64_t(1) << 14,
uint64_t(1) << 15, uint64_t(1) << 16, uint64_t(1) << 17, uint64_t(1) << 18, uint64_t(1) << 19,
uint64_t(1) << 20, uint64_t(1) << 21, uint64_t(1) << 22, uint64_t(1) << 23, uint64_t(1) << 24,
uint64_t(1) << 25, uint64_t(1) << 26, uint64_t(1) << 27, uint64_t(1) << 28, uint64_t(1) << 29,
uint64_t(1) << 30, uint64_t(1) << 31, uint64_t(1) << 32, uint64_t(1) << 33, uint64_t(1) << 34,
uint64_t(1) << 35, uint64_t(1) << 36, uint64_t(1) << 37, uint64_t(1) << 38, uint64_t(1) << 39,
uint64_t(1) << 40, uint64_t(1) << 41, uint64_t(1) << 42, uint64_t(1) << 43, uint64_t(1) << 44,
uint64_t(1) << 45, uint64_t(1) << 46, uint64_t(1) << 47, uint64_t(1) << 48, uint64_t(1) << 49,
uint64_t(1) << 50, uint64_t(1) << 51, uint64_t(1) << 52, uint64_t(1) << 53, uint64_t(1) << 54,
uint64_t(1) << 55, uint64_t(1) << 56, uint64_t(1) << 57, uint64_t(1) << 58, uint64_t(1) << 59,
uint64_t(1) << 60, uint64_t(1) << 61, uint64_t(1) << 62, uint64_t(1) << 63
};
const double DOUBLE_POW2[128] = {
0.5 / UINT64_POW2[63], 1.0 / UINT64_POW2[63], 1.0 / UINT64_POW2[62], 1.0 / UINT64_POW2[61],
1.0 / UINT64_POW2[60], 1.0 / UINT64_POW2[59], 1.0 / UINT64_POW2[58], 1.0 / UINT64_POW2[57],
1.0 / UINT64_POW2[56], 1.0 / UINT64_POW2[55], 1.0 / UINT64_POW2[54], 1.0 / UINT64_POW2[53],
1.0 / UINT64_POW2[52], 1.0 / UINT64_POW2[51], 1.0 / UINT64_POW2[50], 1.0 / UINT64_POW2[49],
1.0 / UINT64_POW2[48], 1.0 / UINT64_POW2[47], 1.0 / UINT64_POW2[46], 1.0 / UINT64_POW2[45],
1.0 / UINT64_POW2[44], 1.0 / UINT64_POW2[43], 1.0 / UINT64_POW2[42], 1.0 / UINT64_POW2[41],
1.0 / UINT64_POW2[40], 1.0 / UINT64_POW2[39], 1.0 / UINT64_POW2[38], 1.0 / UINT64_POW2[37],
1.0 / UINT64_POW2[36], 1.0 / UINT64_POW2[35], 1.0 / UINT64_POW2[34], 1.0 / UINT64_POW2[33],
1.0 / UINT64_POW2[32], 1.0 / UINT64_POW2[31], 1.0 / UINT64_POW2[30], 1.0 / UINT64_POW2[29],
1.0 / UINT64_POW2[28], 1.0 / UINT64_POW2[27], 1.0 / UINT64_POW2[26], 1.0 / UINT64_POW2[25],
1.0 / UINT64_POW2[24], 1.0 / UINT64_POW2[23], 1.0 / UINT64_POW2[22], 1.0 / UINT64_POW2[21],
1.0 / UINT64_POW2[20], 1.0 / UINT64_POW2[19], 1.0 / UINT64_POW2[18], 1.0 / UINT64_POW2[17],
1.0 / UINT64_POW2[16], 1.0 / UINT64_POW2[15], 1.0 / UINT64_POW2[14], 1.0 / UINT64_POW2[13],
1.0 / UINT64_POW2[12], 1.0 / UINT64_POW2[11], 1.0 / UINT64_POW2[10], 1.0 / UINT64_POW2[9],
1.0 / UINT64_POW2[8], 1.0 / UINT64_POW2[7], 1.0 / UINT64_POW2[6], 1.0 / UINT64_POW2[5],
1.0 / UINT64_POW2[4], 1.0 / UINT64_POW2[3], 1.0 / UINT64_POW2[2], 1.0 / UINT64_POW2[1],
1.0, 1.0*UINT64_POW2[1], 1.0*UINT64_POW2[2], 1.0*UINT64_POW2[3],
1.0*UINT64_POW2[4], 1.0*UINT64_POW2[5], 1.0*UINT64_POW2[6], 1.0*UINT64_POW2[7],
1.0*UINT64_POW2[8], 1.0*UINT64_POW2[9], 1.0*UINT64_POW2[10], 1.0*UINT64_POW2[11],
1.0*UINT64_POW2[12], 1.0*UINT64_POW2[13], 1.0*UINT64_POW2[14], 1.0*UINT64_POW2[15],
1.0*UINT64_POW2[16], 1.0*UINT64_POW2[17], 1.0*UINT64_POW2[18], 1.0*UINT64_POW2[19],
1.0*UINT64_POW2[20], 1.0*UINT64_POW2[21], 1.0*UINT64_POW2[22], 1.0*UINT64_POW2[23],
1.0*UINT64_POW2[24], 1.0*UINT64_POW2[25], 1.0*UINT64_POW2[26], 1.0*UINT64_POW2[27],
1.0*UINT64_POW2[28], 1.0*UINT64_POW2[29], 1.0*UINT64_POW2[30], 1.0*UINT64_POW2[31],
1.0*UINT64_POW2[32], 1.0*UINT64_POW2[33], 1.0*UINT64_POW2[34], 1.0*UINT64_POW2[35],
1.0*UINT64_POW2[36], 1.0*UINT64_POW2[37], 1.0*UINT64_POW2[38], 1.0*UINT64_POW2[39],
1.0*UINT64_POW2[40], 1.0*UINT64_POW2[41], 1.0*UINT64_POW2[42], 1.0*UINT64_POW2[43],
1.0*UINT64_POW2[44], 1.0*UINT64_POW2[45], 1.0*UINT64_POW2[46], 1.0*UINT64_POW2[47],
1.0*UINT64_POW2[48], 1.0*UINT64_POW2[49], 1.0*UINT64_POW2[50], 1.0*UINT64_POW2[51],
1.0*UINT64_POW2[52], 1.0*UINT64_POW2[53], 1.0*UINT64_POW2[54], 1.0*UINT64_POW2[55],
1.0*UINT64_POW2[56], 1.0*UINT64_POW2[57], 1.0*UINT64_POW2[58], 1.0*UINT64_POW2[59],
1.0*UINT64_POW2[60], 1.0*UINT64_POW2[61], 1.0*UINT64_POW2[62], 1.0*UINT64_POW2[63]
};
enum e_mode {
TC,
US
};
enum o_mode {
SAT,
SAT_ZERO,
SAT_SYM,
WRAP,
WRAP_SM
};
enum q_mode {
RND,
RND_ZERO,
RND_MIN_INF,
RND_INF,
RND_CONV,
RND_CONV_ODD,
TRN,
TRN_ZERO
};
enum output_mode {
OUTPUT_FIX,
OUTPUT_FIX_SHIFT,
OUTPUT_FLOAT,
OUTPUT_FLOAT_SHIFT
};
class ITPP_EXPORT Fix_Base
{
public:
explicit Fix_Base(int s = 0, int w = MAX_WORDLEN, e_mode e = TC, o_mode o = WRAP, q_mode q = TRN, Stat *ptr = 0)
: shift(s), wordlen(w), emode(e), omode(o), qmode(q), stat_ptr(ptr) {init();}
Fix_Base(const Fix_Base &x)
: shift(x.shift), wordlen(MAX_WORDLEN), emode(TC), omode(WRAP), qmode(TRN), stat_ptr(0) {init();}
virtual ~Fix_Base() {}
void set_shift(int s) {shift = s;}
static void set_output_mode(output_mode o) {outputmode = o;}
static void set_output_mode(std::string o);
int get_shift() const {return shift;}
int get_wordlen() const {return wordlen;}
e_mode get_e_mode() const {return emode;}
o_mode get_o_mode() const {return omode;}
q_mode get_q_mode() const {return qmode;}
output_mode get_output_mode() const {return outputmode;}
fixrep get_max() const {return max;}
fixrep get_min() const {return min;}
virtual void print() const;
protected:
int shift;
int wordlen;
e_mode emode;
o_mode omode;
q_mode qmode;
Stat *stat_ptr;
fixrep min;
fixrep max;
int n_unused_bits;
void init();
fixrep apply_o_mode(fixrep x) const;
fixrep scale_and_apply_modes(double x) const {return scale_and_apply_modes(x, qmode);}
fixrep scale_and_apply_modes(double x, q_mode q) const;
fixrep rshift_and_apply_q_mode(fixrep x, int n) const {return rshift_and_apply_q_mode(x, n, qmode);}
fixrep rshift_and_apply_q_mode(fixrep x, int n, q_mode q) const;
private:
static output_mode outputmode;
};
inline std::ostream &operator<<(std::ostream &os, const output_mode &o)
{
Fix_Base::set_output_mode(o);
return os;
}
} // namespace itpp
#endif // #ifndef FIX_BASE_H
itpp::Array
General array class.
Definition array.h:105
itpp::Fix_Base
Base class for fixed-point data types.
Definition fix_base.h:982
itpp::Fix_Base::get_e_mode
e_mode get_e_mode() const
Get sign encoding mode.
Definition fix_base.h:1005
itpp::Fix_Base::get_q_mode
q_mode get_q_mode() const
Get quantization mode.
Definition fix_base.h:1009
itpp::Fix_Base::get_max
fixrep get_max() const
Get maximum value of data representation.
Definition fix_base.h:1013
itpp::Fix_Base::set_output_mode
static void set_output_mode(output_mode o)
Set output mode to OUTPUT_FIX, OUTPUT_FIX_SHIFT, OUTPUT_FLOAT or OUTPUT_FLOAT_SHIFT....
Definition fix_base.h:996
itpp::Fix_Base::Fix_Base
Fix_Base(int s=0, int w=MAX_WORDLEN, e_mode e=TC, o_mode o=WRAP, q_mode q=TRN, Stat *ptr=0)
Default constructor.
Definition fix_base.h:985
itpp::Fix_Base::get_wordlen
int get_wordlen() const
Get word length.
Definition fix_base.h:1003
itpp::Fix_Base::~Fix_Base
virtual ~Fix_Base()
Destructor.
Definition fix_base.h:991
itpp::Fix_Base::scale_and_apply_modes
fixrep scale_and_apply_modes(double x) const
Convert from double to fixrep using shift and quantization mode qmode, then call limit()
Definition fix_base.h:1044
itpp::Fix_Base::n_unused_bits
int n_unused_bits
Number of unused (MSB) bits (help variable to speed up calculations)
Definition fix_base.h:1037
itpp::Fix_Base::rshift_and_apply_q_mode
fixrep rshift_and_apply_q_mode(fixrep x, int n) const
Right shift n bits using quantization mode qmode and make call to statistics object (if any)
Definition fix_base.h:1048
itpp::Fix_Base::wordlen
int wordlen
Word length.
Definition fix_base.h:1023
itpp::Fix_Base::get_output_mode
output_mode get_output_mode() const
Get output mode.
Definition fix_base.h:1011
itpp::Fix_Base::get_min
fixrep get_min() const
Get minimum value of data representation.
Definition fix_base.h:1015
itpp::Fix_Base::set_shift
void set_shift(int s)
Set shift (without shifting)
Definition fix_base.h:994
itpp::Fix_Base::min
fixrep min
Minimum allowed value (help variable to speed up calculations)
Definition fix_base.h:1033
itpp::Fix_Base::emode
e_mode emode
Sign encoding mode.
Definition fix_base.h:1025
itpp::Fix_Base::stat_ptr
Stat * stat_ptr
Pointer to statistics object.
Definition fix_base.h:1031
itpp::Fix_Base::max
fixrep max
Maximum allowed value (help variable to speed up calculations)
Definition fix_base.h:1035
itpp::Fix_Base::get_shift
int get_shift() const
Get shift.
Definition fix_base.h:1001
itpp::Fix_Base::shift
int shift
Accumulated bitshift (positive means left-shifted, negative means right-shifted)
Definition fix_base.h:1021
itpp::Fix_Base::qmode
q_mode qmode
Quantization mode.
Definition fix_base.h:1029
itpp::Fix_Base::omode
o_mode omode
Overflow mode.
Definition fix_base.h:1027
itpp::Fix_Base::get_o_mode
o_mode get_o_mode() const
Get overflow mode.
Definition fix_base.h:1007
itpp::Fix_Base::Fix_Base
Fix_Base(const Fix_Base &x)
Copy constructor.
Definition fix_base.h:988
itpp::Stat
A class for sampling a signal and calculating statistics.
Definition misc_stat.h:49
itpp::MAX_WORDLEN
const int MAX_WORDLEN
Max word length.
Definition fix_base.h:886
itpp::o_mode
o_mode
Overflow modes (aligned with SystemC)
Definition fix_base.h:948
itpp::DOUBLE_POW2
const double DOUBLE_POW2[128]
Table for fast multiplication by 2^(n-64)
Definition fix_base.h:906
itpp::e_mode
e_mode
Sign encoding modes (aligned with SystemC)
Definition fix_base.h:942
itpp::UINT64_POW2
const uint64_t UINT64_POW2[64]
Table for fast multiplication or division by 2^n.
Definition fix_base.h:889
itpp::q_mode
q_mode
Quantization modes (aligned with SystemC)
Definition fix_base.h:957
itpp::output_mode
output_mode
Output modes.
Definition fix_base.h:969
itpp::fixrep
int64_t fixrep
Representation for fixed-point data types.
Definition fix_base.h:884
itpp::SAT_ZERO
@ SAT_ZERO
Saturation to zero (Not implemented)
Definition fix_base.h:950
itpp::SAT
@ SAT
Saturation.
Definition fix_base.h:949
itpp::WRAP_SM
@ WRAP_SM
Sign magnitued wrap-around (Not implemented)
Definition fix_base.h:953
itpp::WRAP
@ WRAP
Wrap-around.
Definition fix_base.h:952
itpp::SAT_SYM
@ SAT_SYM
Symmetrical saturation (Not implemented)
Definition fix_base.h:951
itpp::US
@ US
Unsigned.
Definition fix_base.h:944
itpp::TC
@ TC
Two's complement.
Definition fix_base.h:943
itpp::TRN
@ TRN
Truncation.
Definition fix_base.h:964
itpp::TRN_ZERO
@ TRN_ZERO
Truncation to zero.
Definition fix_base.h:965
itpp::RND
@ RND
Rounding to plus infinity.
Definition fix_base.h:958
itpp::RND_INF
@ RND_INF
Rounding to infinity.
Definition fix_base.h:961
itpp::RND_CONV
@ RND_CONV
Convergent rounding with half-way value rounded to even value.
Definition fix_base.h:962
itpp::RND_MIN_INF
@ RND_MIN_INF
Rounding to minus infinity.
Definition fix_base.h:960
itpp::RND_ZERO
@ RND_ZERO
Rounding to zero.
Definition fix_base.h:959
itpp::RND_CONV_ODD
@ RND_CONV_ODD
Convergent rounding with half-way value rounded to odd value (not defined in SystemC)
Definition fix_base.h:963
itpp::OUTPUT_FIX
@ OUTPUT_FIX
Output fixed-point representation only.
Definition fix_base.h:970
itpp::OUTPUT_FLOAT
@ OUTPUT_FLOAT
Output floating-point value.
Definition fix_base.h:972
itpp::OUTPUT_FIX_SHIFT
@ OUTPUT_FIX_SHIFT
Output fixed-point representation followed by <shift> (default)
Definition fix_base.h:971
itpp::OUTPUT_FLOAT_SHIFT
@ OUTPUT_FLOAT_SHIFT
Output floating-point value followed by <<shift.
Definition fix_base.h:973
itpp::min
T min(const Vec< T > &in)
Minimum value of vector.
Definition min_max.h:125
itpp::max
T max(const Vec< T > &v)
Maximum value of vector.
Definition min_max.h:45
ittypes.h
IT++ type definitions.
misc_stat.h
Miscellaneous statistics functions and classes - header file.
itpp
itpp namespace
Definition itmex.h:37
itpp::operator<<
std::ostream & operator<<(std::ostream &output, const bin &inbin)
Output stream of bin.
Definition binary.cpp:36

Generated on Mon Jun 10 2024 11:49:23 for IT++ by Doxygen 1.9.8