86 "is_valid_base( sc_numrep base ) : " 87 "bases SC_CSD, or ending in _US and _SM are " 91 std::stringstream msg;
92 msg <<
"is_valid_base( sc_numrep base ) : base = " << base <<
108 #define CASE_ENUM2STR(Value) case Value: return #Value 160 case '0': s =
SC_POS; state = 1;
return 0;
161 case '+': s =
SC_POS; state = 2;
return 1;
162 case '-': s =
SC_NEG; state = 2;
return 1;
169 case 'x':
case 'X': b =
SC_HEX; state = 3;
return 2;
170 case 'd':
case 'D': b =
SC_DEC; state = 3;
return 2;
171 case 'o':
case 'O': b =
SC_OCT; state = 3;
return 2;
172 case 'b':
case 'B': b =
SC_BIN; state = 3;
return 2;
178 case '0': state = 1;
return 0;
218 if (state == STATE_FINISH)
235 static const char msg[] =
236 "get_base_and_sign( const char* v, small_type&, small_type& ) : " 237 "v = \"\" is not valid";
270 "character string is zero");
275 "character string is empty");
284 src_n = strlen(src_p);
287 src_p = &src_p[delta_n];
290 for (word_i = 0; word_i < dst_n; word_i++)
293 for (word_i = 0; word_i < dst_n; word_i++)
303 for (word_i=0; word_i < dst_n; word_i++) {
311 for (src_i = 0; src_i < src_n; src_i++) {
314 switch (src_p[src_i]) {
316 case 'x': ctrl = ctrl | 1; data = data | 1;
break;
317 case '1': data = data | 1;
break;
319 case 'z': ctrl = ctrl | 1;
break;
323 std::stringstream msg;
324 msg <<
"character string '" << src_p <<
334 ctrl_p[word_i] = ctrl;
335 data_p[word_i] =
data;
345 switch (src_p[src_i++]) {
347 case 'x': ctrl = ctrl | 1; data = data | 1;
break;
348 case '1': data = data | 1;
break;
350 case 'z': ctrl = ctrl | 1;
break;
354 std::stringstream msg;
355 msg <<
"character string '" << src_p <<
365 ctrl_p[word_i] = ctrl;
366 data_p[word_i] =
data;
399 "character string is zero");
404 "character string is empty");
411 src_n = strlen(src_p);
412 delta_n = src_n - (dst_n*8);
414 src_p = &src_p[delta_n];
417 for (word_i = 0; word_i < dst_n; word_i++)
420 for (word_i = 0; word_i < dst_n; word_i++)
430 for (word_i = 0; word_i < dst_n; word_i++) {
438 for (src_i = 0; src_i < src_n; src_i++) {
441 switch (src_p[src_i]) {
443 case 'x': ctrl = ctrl | 15; data = data | 15;
break;
445 case 'f': data = data | 15;
break;
447 case 'e': data = data | 14;
break;
449 case 'd': data = data | 13;
break;
451 case 'c': data = data | 12;
break;
453 case 'b': data = data | 11;
break;
455 case 'a': data = data | 10;
break;
456 case '9': data = data | 9;
break;
457 case '8': data = data | 8;
break;
458 case '7': data = data | 7;
break;
459 case '6': data = data | 6;
break;
460 case '5': data = data | 5;
break;
461 case '4': data = data | 4;
break;
462 case '3': data = data | 3;
break;
463 case '2': data = data | 2;
break;
464 case '1': data = data | 1;
break;
467 case 'z': ctrl = ctrl | 15;
break;
470 std::stringstream msg;
471 msg <<
"character string '" << src_p <<
481 ctrl_p[word_i] = ctrl;
482 data_p[word_i] =
data;
489 for (digit_i = 0; digit_i < 8; digit_i++) {
492 switch (src_p[src_i++]) {
494 case 'x': ctrl = ctrl | 15; data = data | 15;
break;
496 case 'f': data = data | 15;
break;
498 case 'e': data = data | 14;
break;
500 case 'd': data = data | 13;
break;
502 case 'c': data = data | 12;
break;
504 case 'b': data = data | 11;
break;
506 case 'a': data = data | 10;
break;
507 case '9': data = data | 9;
break;
508 case '8': data = data | 8;
break;
509 case '7': data = data | 7;
break;
510 case '6': data = data | 6;
break;
511 case '5': data = data | 5;
break;
512 case '4': data = data | 4;
break;
513 case '3': data = data | 3;
break;
514 case '2': data = data | 2;
break;
515 case '1': data = data | 1;
break;
518 case 'z': ctrl = ctrl | 15;
break;
521 std::stringstream msg;
522 msg <<
"character string '" << src_p <<
"' is not valid";
531 ctrl_p[word_i] = ctrl;
532 data_p[word_i] =
data;
549 sc_assert((unb > 0) && (und > 0) && (u != NULL));
562 std::stringstream msg;
563 msg <<
"vec_from_str( int, int, sc_digit*, const char*, " <<
564 "sc_numrep base ) : base = " << base <<
565 " does not match the default base";
575 for (; (c = *
v); ++
v) {
580 val = toupper(c) -
'A' + 10;
585 std::stringstream msg;
586 msg <<
"vec_from_str( int, int, sc_digit*, const char*, " <<
587 "sc_numrep base ) : '" << *v <<
"' is not a valid " <<
588 "digit in base " <<
b;
600 std::stringstream msg;
601 msg <<
"vec_from_str( int, int, sc_digit*, const char*, " <<
602 "sc_numrep base ) : '" << *v <<
"' is not a valid " <<
603 "digit in base " <<
b;
638 carry += (*u++) + (*v++);
644 while (carry && (u < uend)) {
666 sc_assert((ulen > 0) && (ubegin != NULL));
679 carry += (*u) + (*v++);
685 while (carry && (u < uend)) {
694 "vec_add_on( int, sc_digit*, int, const " 696 "result of addition is wrapped around");
712 sc_assert((ulen > 0) && (ubegin != NULL));
724 carry += (*u) + (*v++);
732 "vec_add_on2( int, sc_digit*, int, const " 734 "result of addition is wrapped around");
757 while (carry && (u < uend)) {
782 while (v && (i < ulen)) {
791 "vec_add_small_on( int, sc_digit*, unsigned " 793 "result of addition is wrapped around");
824 while (borrow && (u < uend)) {
846 sc_assert((ulen > 0) && (ubegin != NULL));
865 while (borrow && (u < uend)) {
883 sc_assert((ulen > 0) && (ubegin != NULL));
902 "vec_sub_on2( int, sc_digit*, int, const " 904 "result of subtraction is wrapped around");
926 while (borrow && (u < uend)) {
950 for (
int i = 0;
i < ulen; ++
i) {
1023 #ifdef DEBUG_SYSTEMC 1025 sc_assert((vlen > 0) && (vbegin != NULL));
1029 #define prod_h carry 1031 const sc_digit *vend = (vbegin + vlen);
1038 #ifdef DEBUG_SYSTEMC 1052 #ifdef DEBUG_SYSTEMC 1054 sc_assert(v_h == (v_h & HALF_DIGIT_MASK));
1058 prod_h = u_h * v_l + u_l * v_h +
1073 #ifdef DEBUG_SYSTEMC 1079 #define prod_h carry 1085 #ifdef DEBUG_SYSTEMC 1103 #ifdef DEBUG_SYSTEMC 1108 #define prod_h carry 1110 for (
int i = 0;
i < ulen; ++
i) {
1111 #ifdef DEBUG_SYSTEMC 1122 #ifdef DEBUG_SYSTEMC 1125 "vec_mul_small_on( int, sc_digit*, unsigned " 1127 "result of multiplication is wrapped around");
1138 #ifdef DEBUG_SYSTEMC 1171 while ((--xlen >= 0) && (! x[xlen]))
1179 while ((--ylen >= 0) && (! y[ylen]))
1183 #ifdef DEBUG_SYSTEMC 1199 for (
int k = (xlen - ylen);
k >= 0; --
k) {
1207 qk = ((x[k2] << DOUBLE_BITS_PER_BYTE) +
1220 for (
int i = 0;
i < ylen; ++
i) {
1223 xk[
i] = (
uchar)(diff & BYTE_MASK);
1244 for (
int i = 0;
i < ylen; ++
i) {
1245 carry += xk[
i] + y[
i];
1246 xk[
i] = (
uchar)(carry & BYTE_MASK);
1262 #ifndef SC_MAX_NBITS 1299 #ifdef DEBUG_SYSTEMC 1312 while (ubegin < u) {
1315 #ifdef DEBUG_SYSTEMC 1335 #ifdef DEBUG_SYSTEMC 1360 while ((--xlen >= 0) && (!x[xlen]))
1368 while ((--ylen >= 0) && (!y[ylen]))
1372 #ifdef DEBUG_SYSTEMC 1388 for (
int k = xlen - ylen;
k >= 0; --
k) {
1396 qk = ((x[k2] << DOUBLE_BITS_PER_BYTE) +
1409 for (
int i = 0;
i < ylen; ++
i) {
1412 xk[
i] = (
uchar)(diff & BYTE_MASK);
1430 for (
int i = 0;
i < ylen; ++
i) {
1431 carry += xk[
i] + y[
i];
1432 xk[
i] = (
uchar)(carry & BYTE_MASK);
1446 #ifndef SC_MAX_NBITS 1460 #ifdef DEBUG_SYSTEMC 1472 while (ubegin < u) {
1474 #ifdef DEBUG_SYSTEMC 1489 #ifdef DEBUG_SYSTEMC 1499 while (ubegin < u) {
1501 #ifdef DEBUG_SYSTEMC 1519 #ifdef DEBUG_SYSTEMC 1533 int d = u[right_digit] >> nsr;
1535 if (left_digit != right_digit) {
1536 if (left_digit < ulen)
1537 d |= u[left_digit] << (BITS_PER_DIGIT - nsr);
1554 #ifdef DEBUG_SYSTEMC 1567 for (
int i = ulen - 2;
i >= 0; --
i) {
1571 while (viter < vend) {
1574 carry = vval >> nsr;
1589 #ifdef DEBUG_SYSTEMC 1599 if (nsl % BITS_PER_DIGIT == 0) {
1609 for (
int j = ulen - 1;
j >= nd; --
j)
1622 int nsr = BITS_PER_DIGIT - nsl;
1627 while (uiter < uend) {
1629 (*uiter++) = (((uval & mask) << nsl) | carry);
1630 carry = uval >> nsr;
1642 #ifdef DEBUG_SYSTEMC 1653 if (nsr % BITS_PER_DIGIT == 0) {
1663 for (
int j = 0;
j < (ulen - nd); ++
j)
1667 for (
int j = ulen -
sc_min( nd, ulen );
j < ulen; ++
j)
1681 int nsl = BITS_PER_DIGIT - nsr;
1686 while (ubegin < uiter) {
1688 (*uiter) = (uval >> nsr) | carry;
1689 carry = (uval &
mask) << nsl;
1699 #ifdef DEBUG_SYSTEMC 1700 sc_assert((unb > 0) && (und > 0) && (ud != NULL));
1701 sc_assert((0 <= r) && (r <= l) && (l < unb));
1705 std::stringstream msg;
1706 msg <<
"vec_reverse( int, int, sc_digit*, int l, int r ) : " <<
1707 "l = " << l <<
" < r = " << r <<
" is not valid",
1728 for (
int i = l,
j = r;
i >=
r; --
i, ++
j) {
1735 #ifndef SC_MAX_NBITS 1741 void test_bound_failed(
int nb)
1743 std::stringstream msg;
1744 msg <<
"test_bound( int nb ) : " 1745 "nb = " << nb <<
" > SC_MAX_NBITS = " << SC_MAX_NBITS <<
1749 #endif // SC_MAX_NBITS sc_digit vec_rem_on_small(int ulen, sc_digit *u, sc_digit v)
void vec_sub_on2(int ulen, sc_digit *ubegin, int vlen, const sc_digit *v)
const char SC_ID_WITHOUT_MESSAGE_[]
const char SC_ID_CONVERSION_FAILED_[]
const char SC_ID_VALUE_NOT_VALID_[]
const char * get_base_and_sign(const char *v, small_type &b, small_type &s)
void vec_rem_large(int ulen, const sc_digit *u, int vlen, const sc_digit *v, sc_digit *w)
void vec_add_small(int ulen, const sc_digit *u, sc_digit v, sc_digit *w)
sc_digit one_and_zeros(int n)
void vec_add(int ulen, const sc_digit *u, int vlen, const sc_digit *v, sc_digit *w)
void vec_copy(int n, sc_digit *u, const sc_digit *v)
sc_digit low_half(sc_digit d)
void vec_add_on(int ulen, sc_digit *ubegin, int vlen, const sc_digit *v)
void vec_add_small_on(int ulen, sc_digit *u, sc_digit v)
void vec_shift_left(int ulen, sc_digit *u, int nsl)
sc_digit one_and_ones(int n)
const T sc_max(const T &a, const T &b)
void vec_div_large(int ulen, const sc_digit *u, int vlen, const sc_digit *v, sc_digit *w)
static void is_valid_base(sc_numrep base)
const T sc_min(const T &a, const T &b)
#define SC_REPORT_WARNING(msg_type, msg)
void vec_mul_small(int ulen, const sc_digit *u, sc_digit v, sc_digit *w)
small_type fsm_move(char c, small_type &b, small_type &s, small_type &state)
void vec_zero(int from, int ulen, sc_digit *u)
void vec_from_char(int ulen, const uchar *u, int vlen, sc_digit *v)
void vec_sub(int ulen, const sc_digit *u, int vlen, const sc_digit *v, sc_digit *w)
void vec_sub_small_on(int ulen, sc_digit *u, sc_digit v)
sc_digit vec_rem_small(int ulen, const sc_digit *u, sc_digit v)
int vec_to_char(int ulen, const sc_digit *u, int vlen, uchar *v)
const char SC_ID_OUT_OF_BOUNDS_[]
void vec_add_on2(int ulen, sc_digit *ubegin, int, const sc_digit *v)
#define CASE_ENUM2STR(Value)
small_type convert_signed_SM_to_2C_to_SM(small_type s, int nb, int nd, sc_digit *d)
sc_digit high_half_masked(sc_digit d)
void vec_mul_small_on(int ulen, sc_digit *u, sc_digit v)
#define LOG2_BITS_PER_BYTE
sc_digit high_half(sc_digit d)
#define SC_REPORT_ERROR(msg_type, msg)
void vec_div_small(int ulen, const sc_digit *u, sc_digit v, sc_digit *q)
void parse_hex_bits(const char *src_p, int dst_n, sc_digit *data_p, sc_digit *ctrl_p)
sc_concref_r< sc_bitref_r< T1 >, sc_bitref_r< T2 > > concat(sc_bitref_r< T1 >, sc_bitref_r< T2 >)
void parse_binary_bits(const char *src_p, int dst_n, sc_digit *data_p, sc_digit *ctrl_p)
void vec_sub_small(int ulen, const sc_digit *u, sc_digit v, sc_digit *w)
void vec_sub_on(int ulen, sc_digit *ubegin, int vlen, const sc_digit *v)
small_type vec_from_str(int unb, int und, sc_digit *u, const char *v, sc_numrep base)
void vec_reverse(int unb, int und, sc_digit *ud, int l, int r)
static const small_type NB_DEFAULT_BASE
void vec_mul(int ulen, const sc_digit *u, int vlen, const sc_digit *vbegin, sc_digit *wbegin)
void vec_shift_right(int ulen, sc_digit *u, int nsr, sc_digit fill)
const std::string to_string(sc_enc enc)