42 if (o ==
"OUTPUT_FIX")
44 else if (o ==
"OUTPUT_FIX_SHIFT")
46 else if (o ==
"OUTPUT_FLOAT")
48 else if (o ==
"OUTPUT_FLOAT_SHIFT")
51 it_error(
"Fix_Base::set_output_mode: Illegal output mode!");
56 std::cout <<
"shift = " <<
shift << std::endl
57 <<
"wordlen = " <<
wordlen << std::endl
58 <<
"int(emode) = " << int(
emode) << std::endl
59 <<
"int(omode) = " << int(
omode) << std::endl
60 <<
"int(qmode) = " << int(
qmode) << std::endl
61 <<
"stat_ptr = " <<
stat_ptr << std::endl
62 <<
"min = " <<
min << std::endl
63 <<
"max = " <<
max << std::endl
81 it_error(
"Fix_Base::init: Illegal sign encoding mode!");
91 bool overflow =
false;
103 it_error(
"Fix_Base::apply_o_mode: Illegal overflow mode!");
107 else if (ret >
max) {
117 it_error(
"Fix_Base::apply_o_mode: Illegal overflow mode!");
154 if (scaled_value ==
std::floor(scaled_value) + 0.5)
160 if (scaled_value ==
std::floor(scaled_value) + 0.5)
161 if (scaled_value < 0)
175 it_error(
"Fix_Base::scale_and_apply_modes: Illegal quantization mode!");
184 it_assert_debug(n >= 0,
"Fix_Base::rshift_and_apply_q_mode: n cannot be negative!");
194 ret = ((x >> (n - 1)) + 1) >> 1;
200 if ((x & (
fixrep(1) << (n - 1))) && ((x < 0) || (x & ((
fixrep(1) << (n - 1)) - 1))))
209 if ((x & (
fixrep(1) << (n - 1))) && (x & ((
fixrep(1) << (n - 1)) - 1)))
218 if ((x & (
fixrep(1) << (n - 1))) && ((x >= 0) || (x & ((
fixrep(1) << (n - 1)) - 1))))
227 if ((x & (
fixrep(1) << (n - 1))) && ((x & (
fixrep(1) << n)) || (x & ((
fixrep(1) << (n - 1)) - 1))))
236 if ((x & (
fixrep(1) << (n - 1))) && (!(x & (
fixrep(1) << n)) || (x & ((
fixrep(1) << (n - 1)) - 1))))
249 if ((x < 0) && (x & ((
fixrep(1) << n) - 1)))
255 it_error(
"Fix_Base::rshift_and_apply_q_mode: Illegal quantization mode!");
Definitions of a base class for fixed-point data types.
static void set_output_mode(output_mode o)
Set output mode to OUTPUT_FIX, OUTPUT_FIX_SHIFT, OUTPUT_FLOAT or OUTPUT_FLOAT_SHIFT. Static member function.
fixrep scale_and_apply_modes(double x) const
Convert from double to fixrep using shift and quantization mode qmode, then call limit() ...
Rounding to minus infinity.
vec floor(const vec &x)
Round to nearest lower integer.
Output floating-point value.
const uint64_t UINT64_POW2[64]
Table for fast multiplication or division by 2^n.
fixrep apply_o_mode(fixrep x) const
Handle overflows using overflow mode omode and make call to statistics object (if any) ...
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) ...
Stat * stat_ptr
Pointer to statistics object.
virtual void sample(const double s, const bool overflow=false)
Register a sample and flag for overflow.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
void init()
Calculate help variables min, max and n_unused_bits.
e_mode emode
Sign encoding mode.
ITPP_EXPORT double round(double x)
Round to nearest integer, return result in double.
const double DOUBLE_POW2[128]
Table for fast multiplication by 2^(n-64)
Output fixed-point representation only.
Rounding to plus infinity.
Convergent rounding with half-way value rounded to odd value (not defined in SystemC) ...
q_mode qmode
Quantization mode.
fixrep min
Minimum allowed value (help variable to speed up calculations)
int n_unused_bits
Number of unused (MSB) bits (help variable to speed up calculations)
o_mode omode
Overflow mode.
const int MAX_WORDLEN
Max word length.
int shift
Accumulated bitshift (positive means left-shifted, negative means right-shifted)
Error handling functions - header file.
Output floating-point value followed by <<shift.
#define it_error(s)
Abort unconditionally.
int64_t fixrep
Representation for fixed-point data types.
Output fixed-point representation followed by <shift> (default)
Convergent rounding with half-way value rounded to even value.
q_mode
Quantization modes (aligned with SystemC)
virtual void print() const
Print restrictions.
vec ceil(const vec &x)
Round to nearest upper integer.
fixrep max
Maximum allowed value (help variable to speed up calculations)