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!");
virtual void print() const
Print restrictions.
static void set_output_mode(output_mode o)
Set output mode to OUTPUT_FIX, OUTPUT_FIX_SHIFT, OUTPUT_FLOAT or OUTPUT_FLOAT_SHIFT....
fixrep apply_o_mode(fixrep x) const
Handle overflows using overflow mode omode and make call to statistics object (if any)
fixrep scale_and_apply_modes(double x) const
Convert from double to fixrep using shift and quantization mode qmode, then call limit()
int n_unused_bits
Number of unused (MSB) bits (help variable to speed up calculations)
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)
fixrep min
Minimum allowed value (help variable to speed up calculations)
void init()
Calculate help variables min, max and n_unused_bits.
e_mode emode
Sign encoding mode.
Stat * stat_ptr
Pointer to statistics object.
fixrep max
Maximum allowed value (help variable to speed up calculations)
int shift
Accumulated bitshift (positive means left-shifted, negative means right-shifted)
q_mode qmode
Quantization mode.
o_mode omode
Overflow mode.
virtual void sample(const double s, const bool overflow=false)
Register a sample and flag for overflow.
Definitions of a base class for fixed-point data types.
#define it_error(s)
Abort unconditionally.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
const int MAX_WORDLEN
Max word length.
const double DOUBLE_POW2[128]
Table for fast multiplication by 2^(n-64)
const uint64_t UINT64_POW2[64]
Table for fast multiplication or division by 2^n.
q_mode
Quantization modes (aligned with SystemC)
int64_t fixrep
Representation for fixed-point data types.
@ TRN_ZERO
Truncation to zero.
@ RND
Rounding to plus infinity.
@ RND_INF
Rounding to infinity.
@ RND_CONV
Convergent rounding with half-way value rounded to even value.
@ RND_MIN_INF
Rounding to minus infinity.
@ RND_ZERO
Rounding to zero.
@ RND_CONV_ODD
Convergent rounding with half-way value rounded to odd value (not defined in SystemC)
@ OUTPUT_FIX
Output fixed-point representation only.
@ OUTPUT_FLOAT
Output floating-point value.
@ OUTPUT_FIX_SHIFT
Output fixed-point representation followed by <shift> (default)
@ OUTPUT_FLOAT_SHIFT
Output floating-point value followed by <<shift.
Error handling functions - header file.
ITPP_EXPORT double round(double x)
Round to nearest integer, return result in double.