100 m_mant(
min_mant), m_wp(), m_sign(), m_state(), m_msw(), m_lsw(),
107 m_msw(), m_lsw(), m_r_flag(false)
126 m_state(), m_msw(), m_lsw(), m_r_flag(false)
140 m_mant(
min_mant), m_wp(), m_sign(), m_state(), m_msw(), m_lsw(),
169 m_mant(
min_mant), m_wp(), m_sign(), m_state(), m_msw(), m_lsw(),
194 m_mant(
min_mant), m_wp(0), m_sign(), m_state(normal), m_msw(0),
195 m_lsw(0), m_r_flag(false)
201 m_sign =
id.negative() ? -1 : 1;
207 }
else if (
id.is_subnormal()) {
208 m_mant[0] =
id.mantissa1();
209 m_mant[1] =
id.mantissa0();
212 m_mant[0] =
id.mantissa1();
219 m_mant(
min_mant), m_wp(), m_sign(), m_state(), m_msw(), m_lsw(),
242 m_mant(
min_mant), m_wp(), m_sign(), m_state(), m_msw(), m_lsw(),
259 m_mant(
min_mant), m_wp(), m_sign(), m_state(), m_msw(), m_lsw(),
265 int words =
n_word(
a.length());
273 for (
int i = 0; i < a2.
length(); ++i) {
276 m_mant[x.wi()] |= 1 << x.bi();
281 for (
int i = 0; i <
a.length(); ++i) {
284 m_mant[x.wi()] |= 1 << x.bi();
294 m_mant(
min_mant), m_wp(), m_sign(), m_state(), m_msw(), m_lsw(),
300 int words =
n_word(
a.length());
306 for (
int i = 0; i <
a.length(); ++i) {
309 m_mant[x.wi()] |= 1 << x.bi();
319 m_mant(
a.m_mant), m_wp(
a.m_wp), m_sign(
a.m_sign), m_state(
a.m_state),
320 m_msw(
a.m_msw), m_lsw(
a.m_lsw), m_r_flag(false)
339scfx_rep::operator
new(std::size_t size)
341 const int ALLOC_SIZE = 1024;
344 return ::operator
new(size);
348 for (
int i = 0; i < ALLOC_SIZE - 1; i++)
360scfx_rep::operator
delete(
void *ptr, std::size_t size)
363 ::operator
delete(ptr);
379#define SCFX_FAIL_IF_(cnd) \
382 m_state = not_a_number; \
462 s = (
const char *)s2 + 4;
475 bool based_point =
false;
503 for (
const char *e = end + 2; *e; ++e)
505 exponent = std::atoi(end + 1);
511 bool mant_is_neg =
false;
538 int_digits += bit_offset;
539 frac_digits -= bit_offset;
548 for (; s < end; s++) {
575 int_digits += bit_offset;
576 frac_digits -= bit_offset;
585 for (; s < end; s++) {
587 case '7':
case '6':
case '5':
case '4':
588 case '3':
case '2':
case '1':
607 int length = int_digits + frac_digits;
613 for (; s < end; s++) {
615 case '9':
case '8':
case '7':
case '6':
case '5':
616 case '4':
case '3':
case '2':
case '1':
case '0':
619 for (
int i = 0; carry && i <
m_mant.
size(); i++) {
635 int denominator = frac_digits - exponent;
657 int_digits += bit_offset;
658 frac_digits -= bit_offset;
667 for (; s < end; s ++) {
669 case 'f':
case 'e':
case 'd':
case 'c':
case 'b':
case 'a':
673 case 'F':
case 'E':
case 'D':
case 'C':
case 'B':
case 'A':
677 case '9':
case '8':
case '7':
case '6':
case '5':
678 case '4':
case '3':
case '2':
case '1':
765 unsigned int guard = 0;
774 }
else if (shift < 0) {
799 m1 = m1 >> subnormal_shift |
801 m0 = m0 >> subnormal_shift;
846 while (shift < 64 && m_msw >= idx && idx >=
m_lsw) {
852 return m_sign > 0 ? result : -result;
883 for (i = int_part.
m_lsw; i <= int_part.
m_msw && i < int_part.
m_wp; i++)
889 for (i = frac_part.
m_msw;
890 i >= frac_part.
m_lsw && i >= frac_part.
m_wp; i--)
893 if (frac_part.
m_msw == frac_part.
size() - 1)
903 int_digits = (int)std::ceil(int_wl * std::log10(2.));
905 int len = s.length();
906 s.append(int_digits);
908 bool zero_digits = (frac_part.
is_zero() && fmt !=
SC_F);
910 for (i = int_digits +
len - 1; i >=
len; i--) {
912 s[i] =
static_cast<char>(
'0' +
remainder);
923 s.discard(int_zeros);
939 bool zero_digits = (int_digits == 0 && fmt !=
SC_F);
943 frac_zeros = (int)std::floor(frac_wl * std::log10(2.));
948 if (frac_part.
m_msw == frac_part.
size() - 1)
951 frac_digits = frac_zeros;
953 for (i = 0; i < frac_zeros; i++)
970 s +=
static_cast<char>(
'0' + n);
979 if (frac_digits == 0)
981 else if (int_digits == 0)
994 bool numrep_is_sm = (numrep == SC_BIN_SM ||
995 numrep == SC_OCT_SM ||
1018 if (w_prefix != 0) {
1027 msb = params->
iwl() - 1;
1028 lsb = params->
iwl() - params->
wl();
1031 (numrep == SC_BIN_US ||
1032 numrep == SC_OCT_US ||
1033 numrep == SC_HEX_US) &&
1038 (numrep == SC_BIN ||
1041 numrep == SC_CSD)) {
1051 while (
b.get_bit(msb) ==
b.get_bit(msb - 1))
1054 if (numrep == SC_BIN_US ||
1055 numrep == SC_OCT_US ||
1056 numrep == SC_HEX_US) {
1084 "unexpected sc_numrep");
1088 msb = (int)std::ceil(
double(msb + 1) / step) * step - 1;
1090 lsb = (int)std::floor(
double(lsb) / step) * step;
1095 int sign = (
b.is_neg()) ? (1 << step) - 1 : 0;
1096 for (
int i = (msb + 1) / step; i < 0; i++) {
1098 s +=
static_cast<char>(sign +
'0');
1100 s +=
static_cast<char>(sign +
'a' - 10);
1108 for (
int j = step - 1; j >= 0; --j) {
1109 value +=
static_cast<int>(
b.get_bit(i)) << j;
1113 s +=
static_cast<char>(value +
'0');
1115 s +=
static_cast<char>(value +
'a' - 10);
1120 if (lsb > 0 && fmt == SC_F) {
1121 for (
int i = lsb / step; i > 0; i--)
1125 if (s[s.length() - 1] ==
'.')
1135 if (numrep == SC_CSD)
1152 (numrep == SC_BIN_US ||
1153 numrep == SC_OCT_US ||
1154 numrep == SC_HEX_US)) {
1156 }
else if (numrep == SC_DEC || numrep == SC_NOBASE) {
1177 unsigned int carry = 0;
1190 }
while (++index < size);
1192 return (carry ? 1 : 0);
1211 }
while (++index < size);
1213 return (carry ? 1 : 0);
1246 int len_mant = lhs.
size();
1247 int new_wp = lhs.
m_wp;
1249 align(lhs, rhs, new_wp, len_mant, lhs_mant, rhs_mant);
1255 result.
m_wp = new_wp;
1269 }
else if (cmp == -1) {
1279 result.
round(max_wl);
1299 int size = b_msw - b_lsw;
1300 int a_index = a_msw - size;
1301 int b_index = b_msw - size;
1304 word x =
a[a_index];
1305 word y =
b[b_index];
1322 return (carry ? 1 : 0);
1355 int len_mant = lhs.
size();
1356 int new_wp = lhs.
m_wp;
1358 align(lhs, rhs, new_wp, len_mant, lhs_mant, rhs_mant);
1364 result.
m_wp = new_wp;
1378 }
else if (cmp == -1) {
1388 result.
round(max_wl);
1403#if defined(SC_BOOST_BIG_ENDIAN)
1406#elif defined(SC_BOOST_LITTLE_ENDIAN)
1413#if defined(SC_BOOST_BIG_ENDIAN)
1414static const int half_word_incr = -1;
1415#elif defined(SC_BOOST_LITTLE_ENDIAN)
1416static const int half_word_incr = 1;
1455 result.
m_wp = new_wp;
1456 result.
m_sign = new_sign;
1469 for (i1 = 0; i1 * half_word_incr < len_lhs; i1 += half_word_incr) {
1475 for (i2 = 0; i2 * half_word_incr < len_rhs; i2 += half_word_incr) {
1476 ls.
l += v1 * s2[i2];
1477 ls.
s.
l = ls.
s.u + ((t[i2] += ls.
s.
l) < ls.
s.
l);
1482 t += half_word_incr;
1486 result.
round(max_wl);
1534 int msb_res = msb_lhs - msb_rhs;
1559 for (counter = div_wl; counter && !
remainder.is_zero(); counter--) {
1613 m_wp -= shift_words;
1643 m_wp += shift_words;
1660 word a_word =
a.m_mant[
a.m_msw];
1661 word b_word =
b.m_mant[
b.m_msw];
1663 if (a_word == 0 || b_word == 0) {
1672 int a_msw =
a.m_msw -
a.m_wp;
1673 int b_msw =
b.m_msw -
b.m_wp;
1685 while (a_i >=
a.m_lsw && b_i >=
b.m_lsw) {
1686 a_word =
a.m_mant[a_i];
1687 b_word =
b.m_mant[b_i];
1688 if (a_word > b_word)
1690 if (a_word < b_word)
1697 while (a_i >=
a.m_lsw) {
1698 a_zero = a_zero && (
a.m_mant[a_i] == 0);
1703 while (b_i >=
b.m_lsw) {
1704 b_zero = b_zero && (
b.m_mant[b_i] == 0);
1710 if (!a_zero && b_zero)
1713 if (a_zero && !b_zero)
1730 if (
a.is_nan() ||
b.is_nan()) {
1734 if (
a.is_inf() ||
b.is_inf()) {
1737 if (
b.is_inf() && !
b.is_neg()) {
1743 if (
b.is_inf() &&
b.is_neg()) {
1759 if (
a.is_zero() &&
b.is_zero()) {
1764 if (
a.m_sign !=
b.m_sign) {
1786 if (x.wi() >=
size())
1792 q_flag = (qb || ! qz);
1795 switch (params.
q_mode()) {
1825 if ((qb && !qz) || (qb && qz &&
q_odd(x)))
1867 if (x.wi() >=
size())
1886 if (params.
o_mode() == SC_SAT_SYM)
1887 under = (!zero_left || bit_at);
1889 under = (!zero_left || (zero_left && bit_at && ! zero_right));
1891 over = (! zero_left || bit_at);
1897 over = (!zero_left);
1900 o_flag = (under || over);
1907 x.wi(x.wi() - x2.
wi());
1911 switch (params.
o_mode()) {
1914 int n_bits = params.
n_bits();
1921 }
else if (n_bits < params.
wl()) {
1927 o_set(x, x3, enc, under);
1969 int n_bits = params.
n_bits();
1982 }
else if (n_bits == 1) {
1988 }
else if (n_bits < params.
wl()) {
2054 bool need_lhs =
true;
2055 bool need_rhs =
true;
2058 int lower_bound_lhs = lhs.
m_lsw - lhs.
m_wp;
2059 int upper_bound_lhs = lhs.
m_msw - lhs.
m_wp;
2060 int lower_bound_rhs = rhs.
m_lsw - rhs.
m_wp;
2061 int upper_bound_rhs = rhs.
m_msw - rhs.
m_wp;
2063 int lower_bound =
sc_min(lower_bound_lhs, lower_bound_rhs);
2064 int upper_bound =
sc_max(upper_bound_lhs, upper_bound_rhs);
2066 new_wp = -lower_bound;
2069 if (new_wp != lhs.
m_wp || len_mant != lhs.
size()) {
2070 lhs_mant = lhs.
resize(len_mant, new_wp);
2074 if (new_wp != rhs.
m_wp || len_mant != rhs.
size()) {
2075 rhs_mant = rhs.
resize(len_mant, new_wp);
2105 int size =
sc_min(lhs_size, rhs_size);
2107 int lhs_index = lhs.
m_msw;
2108 int rhs_index = rhs.
m_msw;
2113 i < size && lhs.
m_mant[lhs_index] == rhs.
m_mant[rhs_index];
2120 if (lhs_size == rhs_size) {
2124 if (lhs_size < rhs_size) {
2146#if defined(SC_BOOST_BIG_ENDIAN)
2148#elif defined(SC_BOOST_LITTLE_ENDIAN)
2157#if defined(SC_BOOST_BIG_ENDIAN)
2158 for (
int i = 0, end = (
m_msw -
m_wp + 1) * 2; i < end; i++) {
2159#elif defined(SC_BOOST_LITTLE_ENDIAN)
2160 for (
int i = 0, end = -(
m_msw -
m_wp + 1) * 2; i > end; i--) {
2197 mant8[0] = (
m_mant[0] << 3);
2198 mant2[0] = (
m_mant[0] << 1);
2237 int shift = new_wp -
m_wp;
2240 (*result)[j + shift] =
m_mant[j];
2254 m_mant[i >> 5] |= 1 << (i & 31);
2266 m_mant[i >> 5] |= 1 << (i & 31);
2270 m_mant[i >> 5] |= 1 << (i & 31);
2274 m_mant[i >> 5] |= 1 << (i & 31);
2287 m_mant[i >> 5] |= 1 << (i & 31);
2291 m_mant[i >> 5] |= 1 << (i & 31);
2295 m_mant[i >> 5] |= 1 << (i & 31);
2299 m_mant[i >> 5] |= 1 << (i & 31);
2318 "shift_left overflow");
2320 for (
int i =
size() - 1; i > 0; i--) {
2344 for (
int i = 0; i <
size() - 1; i++) {
2367 if (x.wi() >=
size())
2375 bool result = (
m_mant[x.wi()] & (1 << x.bi())) != 0;
2397 if (x.wi() >=
size()) {
2402 }
else if (x.wi() < 0) {
2409 m_mant[x.wi()] |= 1 << x.bi();
2411 if (i == params.
iwl() - 1)
2436 if (x.wi() >=
size()) {
2441 }
else if (x.wi() < 0) {
2447 m_mant[x.wi()] &= ~(1 << x.bi());
2449 if (i == params.
iwl() - 1)
2473 for (
int k = 0; k < bv.
length(); ++k) {
2494 for (
int k = 0; k < bv.
length(); ++k) {
2495 if (bv[k].to_bool())
2528 os <<
"scfx_rep" << ::std::endl;
2529 os <<
"(" << ::std::endl;
2531 os <<
"mant =" << ::std::endl;
2532 for (
int i =
size() - 1; i >= 0; i--) {
2534 std::sprintf(buf,
" %d: %10u (%8x)", i,
2536 os << buf << ::std::endl;
2539 os <<
"wp = " <<
m_wp << ::std::endl;
2540 os <<
"sign = " <<
m_sign << ::std::endl;
2551 os <<
"not_a_number";
2558 os <<
"msw = " <<
m_msw << ::std::endl;
2559 os <<
"lsw = " <<
m_lsw << ::std::endl;
2561 os <<
")" << ::std::endl;
2624 if (wl_effective <= wl)
2632 if (wl_effective <= wl)
half_word * half_addr(int=0) const
bool get_slice(int, int, const scfx_params &, sc_bv_base &) const
void cast(const scfx_params &, bool &, bool &)
void q_clear(const scfx_index &)
bool set_slice(int, int, const scfx_params &, const sc_bv_base &)
const scfx_index calc_indices(int) const
bool o_zero_right(const scfx_index &) const
bool o_zero_left(const scfx_index &) const
void o_set_low(const scfx_index &, sc_enc)
void o_set_high(const scfx_index &, const scfx_index &, sc_enc, int=1)
bool o_bit_at(const scfx_index &) const
void o_set(const scfx_index &, const scfx_index &, sc_enc, bool)
void from_string(const char *, int)
bool q_zero(const scfx_index &) const
bool clear(int, const scfx_params &)
unsigned int divide_by_ten()
void o_extend(const scfx_index &, sc_enc)
bool q_odd(const scfx_index &) const
void o_invert(const scfx_index &)
void quantization(const scfx_params &, bool &)
void dump(::std::ostream &) const
friend scfx_rep * div_scfx_rep(const scfx_rep &, const scfx_rep &, int)
void print(::std::ostream &) const
void overflow(const scfx_params &, bool &)
void resize_to(int, int=0)
void q_incr(const scfx_index &)
bool set(int, const scfx_params &)
const char * to_string(sc_numrep, int, sc_fmt, const scfx_params *=0) const
scfx_mant * resize(int, int) const
void get_type(int &, int &, sc_enc &) const
bool q_bit(const scfx_index &) const
const char SC_ID_WRAP_SM_NOT_DEFINED_[]
const char SC_ID_ASSERTION_FAILED_[]
static void print_other(scfx_string &s, const scfx_ieee_double &id, sc_numrep numrep, int w_prefix, sc_fmt fmt, const scfx_params *params)
static int add_mants(int size, scfx_mant &result, const scfx_mant &a, const scfx_mant &b)
void complement(scfx_mant &target, const scfx_mant &source, int size)
bool scfx_is_inf(const char *s)
bool scfx_is_digit(char c, sc_numrep numrep)
const int SCFX_IEEE_DOUBLE_E_MIN
void multiply(scfx_rep &result, const scfx_rep &lhs, const scfx_rep &rhs, int max_wl)
scfx_rep * add_scfx_rep(const scfx_rep &lhs, const scfx_rep &rhs, int max_wl)
void scfx_print_inf(scfx_string &s, bool negative)
int scfx_parse_sign(const char *&s, bool &sign_char)
bool scfx_is_nan(const char *s)
static scfx_rep_node * list
void scfx_print_prefix(scfx_string &s, sc_numrep numrep)
sc_numrep scfx_parse_prefix(const char *&s)
void scfx_csd2tc(scfx_string &csd)
void scfx_print_exp(scfx_string &s, int exp)
const int SCFX_IEEE_DOUBLE_E_MAX
static scfx_pow10 pow10_fx
int scfx_find_lsb(unsigned long x)
const T sc_min(const T &a, const T &b)
int cmp_scfx_rep(const scfx_rep &a, const scfx_rep &b)
int scfx_to_digit(char c, sc_numrep numrep)
int compare_msw_ff(const scfx_rep &lhs, const scfx_rep &rhs)
static int sub_mants(int size, scfx_mant &result, const scfx_mant &a, const scfx_mant &b)
const T sc_max(const T &a, const T &b)
scfx_rep * neg_scfx_rep(const scfx_rep &)
scfx_rep * div_scfx_rep(const scfx_rep &lhs, const scfx_rep &rhs, int div_wl)
const unsigned int SCFX_IEEE_DOUBLE_M_SIZE
scfx_rep * sub_scfx_rep(const scfx_rep &lhs, const scfx_rep &rhs, int max_wl)
double scfx_pow2(int exp)
void align(const scfx_rep &lhs, const scfx_rep &rhs, int &new_wp, int &len_mant, scfx_mant_ref &lhs_mant, scfx_mant_ref &rhs_mant)
void inc(scfx_mant &mant)
int compare_abs(const scfx_rep &a, const scfx_rep &b)
void scfx_print_nan(scfx_string &s)
int scfx_find_msb(unsigned long x)
static void print_dec(scfx_string &s, scfx_ieee_double id, int w_prefix, sc_fmt fmt)
static const int mantissa0_size
void scfx_tc2csd(scfx_string &s, int w_prefix)
static int sub_with_index(scfx_mant &a, int a_msw, int, const scfx_mant &b, int b_msw, int b_lsw)
bool scfx_exp_start(const char *s)
#define SC_ERROR_IF_(cnd, id)
#define SC_ASSERT_(cnd, msg)
#define SCFX_FAIL_IF_(cnd)
#define SC_REPORT_FATAL(msg_type, msg)
char data[sizeof(scfx_rep)]
struct sc_dt::word_short::@375 s