00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #include <ctype.h>
00054 #include <math.h>
00055
00056 #include "sysc/kernel/sc_cmnhdr.h"
00057 #include "sysc/kernel/sc_macros.h"
00058 #include "sysc/datatypes/int/sc_signed.h"
00059 #include "sysc/datatypes/int/sc_unsigned.h"
00060 #include "sysc/datatypes/int/sc_int_base.h"
00061 #include "sysc/datatypes/int/sc_uint_base.h"
00062 #include "sysc/datatypes/int/sc_int_ids.h"
00063 #include "sysc/datatypes/bit/sc_bv_base.h"
00064 #include "sysc/datatypes/bit/sc_lv_base.h"
00065 #include "sysc/datatypes/misc/sc_concatref.h"
00066 #include "sysc/datatypes/fx/sc_fix.h"
00067 #include "sysc/datatypes/fx/scfx_other_defs.h"
00068
00069
00070 namespace sc_dt
00071 {
00072
00073
00074
00075 sc_core::sc_vpool<sc_signed_bitref> sc_signed_bitref::m_pool(9);
00076 sc_core::sc_vpool<sc_signed_subref> sc_signed_subref::m_pool(9);
00077
00078
00079
00080
00081
00082 void
00083 sc_signed::invalid_index( int i ) const
00084 {
00085 char msg[BUFSIZ];
00086 std::sprintf( msg,
00087 "sc_bigint bit selection: index = %d violates "
00088 "0 <= index <= %d", i, nbits - 1 );
00089 SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, msg );
00090 }
00091
00092 void
00093 sc_signed::invalid_range( int l, int r ) const
00094 {
00095 char msg[BUFSIZ];
00096 std::sprintf( msg,
00097 "sc_bigint part selection: left = %d, right = %d \n"
00098 " violates either (0 <= left <= %d) or (0 <= right <= %d)",
00099 l, r, nbits-1, nbits-1 );
00100 SC_REPORT_ERROR( sc_core::SC_ID_OUT_OF_BOUNDS_, msg );
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 bool sc_signed::concat_get_ctrl( sc_digit* dst_p, int low_i ) const
00118 {
00119 int dst_i;
00120 int end_i;
00121 int left_shift;
00122 sc_digit mask;
00123
00124
00125
00126
00127 dst_i = low_i / BITS_PER_DIGIT;
00128 end_i = (low_i + nbits - 1) / BITS_PER_DIGIT;
00129 left_shift = low_i % BITS_PER_DIGIT;
00130
00131
00132
00133
00134 mask = ~(-1 << left_shift);
00135 dst_p[dst_i] = ( dst_p[dst_i] & ~mask );
00136 dst_i++;
00137
00138 for ( ; dst_i <= end_i; dst_i++ ) dst_p[dst_i] = 0;
00139
00140 return false;
00141 }
00142
00143 bool sc_signed::concat_get_data( sc_digit* dst_p, int low_i ) const
00144 {
00145 sc_digit carry;
00146 int dst_i;
00147 int end_i;
00148 int high_i;
00149 int left_shift;
00150 sc_digit left_word;
00151 sc_digit mask;
00152 bool result;
00153 int right_shift;
00154 sc_digit right_word;
00155 int src_i;
00156
00157
00158
00159
00160
00161 dst_i = low_i / BITS_PER_DIGIT;
00162 high_i = low_i + nbits - 1;
00163 end_i = high_i / BITS_PER_DIGIT;
00164 left_shift = low_i % BITS_PER_DIGIT;
00165
00166 switch ( sgn )
00167 {
00168
00169
00170 case SC_POS:
00171
00172 result = true;
00173
00174
00175
00176 if ( dst_i == end_i )
00177 {
00178 mask = ~(-1 << nbits) << left_shift;
00179 dst_p[dst_i] = ( dst_p[dst_i] & ~mask ) |
00180 ((digit[0] << left_shift) & mask);
00181 }
00182
00183
00184
00185
00186 else if ( left_shift == 0 )
00187 {
00188 carry = 1;
00189 for ( src_i = 0; dst_i < end_i; dst_i++, src_i++ )
00190 {
00191 dst_p[dst_i] = digit[src_i];
00192 }
00193 high_i = high_i % BITS_PER_DIGIT;
00194 mask = ~(-2 << high_i) & DIGIT_MASK;
00195 dst_p[dst_i] = digit[src_i] & mask;
00196 }
00197
00198
00199
00200
00201 else
00202 {
00203 high_i = high_i % BITS_PER_DIGIT;
00204 right_shift = BITS_PER_DIGIT - left_shift;
00205 mask = ~(-1 << left_shift);
00206 right_word = digit[0];
00207 dst_p[dst_i] = (dst_p[dst_i] & mask) |
00208 ((right_word << left_shift) & DIGIT_MASK);
00209 for ( src_i = 1, dst_i++; dst_i < end_i; dst_i++, src_i++ )
00210 {
00211 left_word = digit[src_i];
00212 dst_p[dst_i] = ((left_word << left_shift)&DIGIT_MASK) |
00213 (right_word >> right_shift);
00214 right_word = left_word;
00215 }
00216 left_word = digit[src_i];
00217 mask = ~(-2 << high_i) & DIGIT_MASK;
00218 dst_p[dst_i] = ((left_word << left_shift) |
00219 (right_word >> right_shift)) & mask;
00220 }
00221 break;
00222
00223
00224
00225
00226 case SC_NEG:
00227
00228
00229
00230 result = true;
00231 if ( dst_i == end_i )
00232 {
00233 mask = ~(-1 << nbits) << left_shift;
00234 right_word = (digit[0] ^ DIGIT_MASK) + 1;
00235 dst_p[dst_i] = ( dst_p[dst_i] & ~mask ) |
00236 ((right_word << left_shift) & mask);
00237 }
00238
00239
00240
00241
00242 else if ( left_shift == 0 )
00243 {
00244 carry = 1;
00245 for ( src_i = 0; dst_i < end_i; dst_i++, src_i++ )
00246 {
00247 right_word = (digit[src_i] ^ DIGIT_MASK) + carry;
00248 dst_p[dst_i] = right_word & DIGIT_MASK;
00249 carry = right_word >> BITS_PER_DIGIT;
00250 }
00251 high_i = high_i % BITS_PER_DIGIT;
00252 mask = (~(-2 << high_i)) & DIGIT_MASK;
00253 right_word = (digit[src_i] ^ DIGIT_MASK) + carry;
00254 dst_p[dst_i] = right_word & mask;
00255 }
00256
00257
00258
00259
00260 else
00261 {
00262 high_i = high_i % BITS_PER_DIGIT;
00263 right_shift = BITS_PER_DIGIT - left_shift;
00264 mask = ~(-1 << left_shift);
00265 carry = 1;
00266 right_word = (digit[0] ^ DIGIT_MASK) + carry;
00267 dst_p[dst_i] = (dst_p[dst_i] & mask) |
00268 ((right_word << left_shift) & DIGIT_MASK);
00269 carry = right_word >> BITS_PER_DIGIT;
00270 for ( src_i = 1, dst_i++; dst_i < end_i; dst_i++, src_i++ )
00271 {
00272 left_word = (digit[src_i] ^ DIGIT_MASK) + carry;
00273 dst_p[dst_i] = ((left_word << left_shift)&DIGIT_MASK) |
00274 (right_word >> right_shift);
00275 carry = left_word >> BITS_PER_DIGIT;
00276 right_word = left_word & DIGIT_MASK;
00277 }
00278 left_word = (digit[src_i] ^ DIGIT_MASK) + carry;
00279 mask = ~(-2 << high_i) & DIGIT_MASK;
00280 dst_p[dst_i] = ((left_word << left_shift) |
00281 (right_word >> right_shift)) & mask;
00282 }
00283 break;
00284
00285
00286
00287
00288 default:
00289 result = false;
00290
00291
00292
00293
00294 if ( dst_i == end_i )
00295 {
00296 mask = ~(-1 << nbits) << left_shift;
00297 dst_p[dst_i] = dst_p[dst_i] & ~mask;
00298 }
00299
00300
00301
00302
00303 else if ( left_shift == 0 )
00304 {
00305 carry = 1;
00306 for ( src_i = 0; dst_i < end_i; dst_i++, src_i++ )
00307 {
00308 dst_p[dst_i] = 0;
00309 }
00310 high_i = high_i % BITS_PER_DIGIT;
00311 mask = ~(-2 << high_i) & DIGIT_MASK;
00312 dst_p[dst_i] = 0;
00313 }
00314
00315
00316
00317
00318 else
00319 {
00320 high_i = high_i % BITS_PER_DIGIT;
00321 right_shift = BITS_PER_DIGIT - left_shift;
00322 mask = ~(-1 << left_shift);
00323 dst_p[dst_i] = (dst_p[dst_i] & mask);
00324 for ( dst_i++; dst_i <= end_i; dst_i++ )
00325 {
00326 dst_p[dst_i] = 0;
00327 }
00328 }
00329 break;
00330 }
00331 return result;
00332 }
00333
00334
00335
00336 uint64 sc_signed::concat_get_uint64() const
00337 {
00338 uint64 result;
00339
00340 switch ( sgn )
00341 {
00342 case SC_POS:
00343 result = 0;
00344 if ( ndigits > 2 )
00345 result = digit[2];
00346 if ( ndigits > 1 )
00347 result = (result << BITS_PER_DIGIT) | digit[1];
00348 result = (result << BITS_PER_DIGIT) | digit[0];
00349 break;
00350 case SC_NEG:
00351 result = 0;
00352 if ( ndigits > 2 )
00353 result = digit[2];
00354 if ( ndigits > 1 )
00355 result = (result << BITS_PER_DIGIT) | digit[1];
00356 result = (result << BITS_PER_DIGIT) | digit[0];
00357 result = -result;
00358 if ( nbits < 64 )
00359 {
00360 uint64 mask = ~0;
00361 result = result & ~(mask << nbits);
00362 }
00363 break;
00364 default:
00365 result = 0;
00366 break;
00367 }
00368 return result;
00369 }
00370
00371
00372 void sc_signed::concat_set(int64 src, int low_i)
00373 {
00374 *this = (low_i < 64) ? src >> low_i : src >> 63;
00375 }
00376
00377 void sc_signed::concat_set(const sc_signed& src, int low_i)
00378 {
00379 if ( low_i < src.length() )
00380 *this = src >> low_i;
00381 else
00382 *this = (src<0) ? (int_type)-1 : 0;
00383 }
00384
00385 void sc_signed::concat_set(const sc_unsigned& src, int low_i)
00386 {
00387 if ( low_i < src.length() )
00388 *this = src >> low_i;
00389 else
00390 *this = 0;
00391 }
00392
00393 void sc_signed::concat_set(uint64 src, int low_i)
00394 {
00395 *this = (low_i < 64) ? src >> low_i : 0;
00396 }
00397
00398
00399
00400
00401
00402 bool sc_signed::and_reduce() const
00403 {
00404 sc_digit current;
00405 int i;
00406
00407 if ( sgn == SC_NEG )
00408 {
00409 current = (1 << BITS_PER_DIGIT);
00410 for ( i = 0; i < ndigits-1; i++ )
00411 {
00412 current = (current >> BITS_PER_DIGIT) + (digit[i]^DIGIT_MASK);
00413 if ( (current & DIGIT_MASK) != DIGIT_MASK ) return false;
00414 }
00415 current = (current >> BITS_PER_DIGIT) + (digit[i]^DIGIT_MASK);
00416 if ( (current & ~(-1 << (nbits % BITS_PER_DIGIT))) ==
00417 (sc_digit) ~(-1 << (nbits % BITS_PER_DIGIT)) )
00418 return true;
00419 }
00420 return false;
00421 }
00422
00423 bool sc_signed::or_reduce() const
00424 {
00425 return sgn == SC_ZERO ? false : true;
00426 }
00427
00428 bool sc_signed::xor_reduce() const
00429 {
00430 int i;
00431 int odd;
00432
00433 odd = 0;
00434 for ( i = 0; i < nbits; i++ )
00435 if ( test(i) ) odd = ~odd;
00436 return odd ? true : false;
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 const sc_signed&
00448 sc_signed::operator = ( const char* a )
00449 {
00450 if( a == 0 ) {
00451 SC_REPORT_ERROR( sc_core::SC_ID_CONVERSION_FAILED_,
00452 "character string is zero" );
00453 }
00454 if( *a == 0 ) {
00455 SC_REPORT_ERROR( sc_core::SC_ID_CONVERSION_FAILED_,
00456 "character string is empty" );
00457 }
00458 try {
00459 int len = length();
00460 sc_fix aa( a, len, len, SC_TRN, SC_WRAP, 0, SC_ON );
00461 return this->operator = ( aa );
00462 } catch( sc_core::sc_report ) {
00463 char msg[BUFSIZ];
00464 std::sprintf( msg, "character string '%s' is not valid", a );
00465 SC_REPORT_ERROR( sc_core::SC_ID_CONVERSION_FAILED_, msg );
00466
00467 }
00468 return *this;
00469 }
00470
00471 const sc_signed&
00472 sc_signed::operator=(int64 v)
00473 {
00474 sgn = get_sign(v);
00475
00476 if (sgn == SC_ZERO)
00477 vec_zero(ndigits, digit);
00478 else {
00479 from_uint(ndigits, digit, (uint64) v);
00480 if (nbits <= (int)BITS_PER_INT64)
00481 convert_SM_to_2C_to_SM();
00482 }
00483 return *this;
00484 }
00485
00486 const sc_signed&
00487 sc_signed::operator=(uint64 v)
00488 {
00489 sgn = get_sign(v);
00490 if (sgn == SC_ZERO)
00491 vec_zero(ndigits, digit);
00492 else {
00493 from_uint(ndigits, digit, v);
00494 if (nbits <= (int)BITS_PER_INT64)
00495 convert_SM_to_2C_to_SM();
00496 }
00497 return *this;
00498 }
00499
00500 const sc_signed&
00501 sc_signed::operator=(long v)
00502 {
00503 sgn = get_sign(v);
00504
00505 if (sgn == SC_ZERO)
00506 vec_zero(ndigits, digit);
00507 else {
00508 from_uint(ndigits, digit, (unsigned long) v);
00509 if (nbits <= (int)BITS_PER_LONG)
00510 convert_SM_to_2C_to_SM();
00511 }
00512 return *this;
00513 }
00514
00515 const sc_signed&
00516 sc_signed::operator=(unsigned long v)
00517 {
00518 sgn = get_sign(v);
00519 if (sgn == SC_ZERO)
00520 vec_zero(ndigits, digit);
00521 else {
00522 from_uint(ndigits, digit, v);
00523 if (nbits <= (int)BITS_PER_LONG)
00524 convert_SM_to_2C_to_SM();
00525 }
00526 return *this;
00527 }
00528
00529 const sc_signed&
00530 sc_signed::operator=(double v)
00531 {
00532 is_bad_double(v);
00533 if (v < 0) {
00534 v = -v;
00535 sgn = SC_NEG;
00536 }
00537 else
00538 sgn = SC_POS;
00539 register int i = 0;
00540 while (floor(v) && (i < ndigits)) {
00541 #ifndef WIN32
00542 digit[i++] = (sc_digit) floor(remainder(v, DIGIT_RADIX));
00543 #else
00544 digit[i++] = (sc_digit) floor(fmod(v, DIGIT_RADIX));
00545 #endif
00546 v /= DIGIT_RADIX;
00547 }
00548 vec_zero(i, ndigits, digit);
00549 convert_SM_to_2C_to_SM();
00550 return *this;
00551 }
00552
00553
00554
00555
00556 const sc_signed&
00557 sc_signed::operator = ( const sc_bv_base& v )
00558 {
00559 int minlen = sc_min( nbits, v.length() );
00560 int i = 0;
00561 for( ; i < minlen; ++ i ) {
00562 safe_set( i, v.get_bit( i ), digit );
00563 }
00564 for( ; i < nbits; ++ i ) {
00565 safe_set( i, 0, digit );
00566 }
00567 convert_2C_to_SM();
00568 return *this;
00569 }
00570
00571 const sc_signed&
00572 sc_signed::operator = ( const sc_lv_base& v )
00573 {
00574 int minlen = sc_min( nbits, v.length() );
00575 int i = 0;
00576 for( ; i < minlen; ++ i ) {
00577 safe_set( i, sc_logic( v.get_bit( i ) ).to_bool(), digit );
00578 }
00579 for( ; i < nbits; ++ i ) {
00580 safe_set( i, 0, digit );
00581 }
00582 convert_2C_to_SM();
00583 return *this;
00584 }
00585
00586
00587
00588
00589 const std::string
00590 sc_signed::to_string( sc_numrep numrep ) const
00591 {
00592 int len = length();
00593 sc_fix aa( *this, len, len, SC_TRN, SC_WRAP, 0, SC_ON );
00594 return aa.to_string( numrep );
00595 }
00596
00597 const std::string
00598 sc_signed::to_string( sc_numrep numrep, bool w_prefix ) const
00599 {
00600 int len = length();
00601 sc_fix aa( *this, len, len, SC_TRN, SC_WRAP, 0, SC_ON );
00602 return aa.to_string( numrep, w_prefix );
00603 }
00604
00605
00606
00607
00608
00609
00610 const sc_signed&
00611 sc_signed::operator = (const sc_int_base& v)
00612 { return operator=((int64) v); }
00613
00614
00615 sc_signed
00616 operator + ( const sc_unsigned& u, const sc_int_base& v )
00617 { return operator + ( u, SCAST<int64>( v ) ); }
00618
00619 sc_signed
00620 operator + ( const sc_int_base& u, const sc_unsigned& v )
00621 { return operator + ( SCAST<int64>( u ), v ); }
00622
00623 sc_signed
00624 operator + (const sc_signed& u, const sc_int_base& v)
00625 { return operator+(u, (int64) v); }
00626
00627 sc_signed
00628 operator + (const sc_int_base& u, const sc_signed& v)
00629 { return operator+((int64) u, v); }
00630
00631 const sc_signed&
00632 sc_signed::operator += (const sc_int_base& v)
00633 { return operator+=((int64) v); }
00634
00635
00636 sc_signed
00637 operator - (const sc_unsigned& u, const sc_int_base& v)
00638 { return operator-(u, (int64) v); }
00639
00640 sc_signed
00641 operator - (const sc_int_base& u, const sc_unsigned& v)
00642 { return operator-((int64) u, v); }
00643
00644 sc_signed
00645 operator-(const sc_signed& u, const sc_int_base& v)
00646 { return operator-(u, (int64) v); }
00647
00648 sc_signed
00649 operator - (const sc_int_base& u, const sc_signed& v)
00650 { return operator-((int64) u, v); }
00651
00652 const sc_signed&
00653 sc_signed::operator -= (const sc_int_base& v)
00654 { return operator-=((int64) v); }
00655
00656
00657 sc_signed
00658 operator * ( const sc_unsigned& u, const sc_int_base& v )
00659 { return operator * ( u, SCAST<int64>( v ) ); }
00660
00661 sc_signed
00662 operator * ( const sc_int_base& u, const sc_unsigned& v )
00663 { return operator * ( SCAST<int64>( u ), v ); }
00664
00665 sc_signed
00666 operator * (const sc_signed& u, const sc_int_base& v)
00667 { return operator*(u, (int64) v); }
00668
00669 sc_signed
00670 operator * (const sc_int_base& u, const sc_signed& v)
00671 { return operator*((int64) u, v); }
00672
00673 const sc_signed&
00674 sc_signed::operator *= (const sc_int_base& v)
00675 { return operator*=((int64) v); }
00676
00677
00678 sc_signed
00679 operator / ( const sc_unsigned& u, const sc_int_base& v )
00680 { return operator / ( u, SCAST<int64>( v ) ); }
00681
00682 sc_signed
00683 operator / ( const sc_int_base& u, const sc_unsigned& v )
00684 { return operator / ( SCAST<int64>( u ), v ); }
00685
00686 sc_signed
00687 operator / (const sc_signed& u, const sc_int_base& v)
00688 { return operator/(u, (int64) v); }
00689
00690 sc_signed
00691 operator / (const sc_int_base& u, const sc_signed& v)
00692 { return operator/((int64) u, v); }
00693
00694 const sc_signed&
00695 sc_signed::operator /= (const sc_int_base& v)
00696 { return operator/=((int64) v); }
00697
00698
00699 sc_signed
00700 operator % ( const sc_unsigned& u, const sc_int_base& v )
00701 { return operator % ( u, SCAST<int64>( v ) ); }
00702
00703 sc_signed
00704 operator % ( const sc_int_base& u, const sc_unsigned& v )
00705 { return operator % ( SCAST<int64>( u ), v ); }
00706
00707 sc_signed
00708 operator % (const sc_signed& u, const sc_int_base& v)
00709 { return operator%(u, (int64) v); }
00710
00711 sc_signed
00712 operator % (const sc_int_base& u, const sc_signed& v)
00713 { return operator%((int64) u, v); }
00714
00715 const sc_signed&
00716 sc_signed::operator %= (const sc_int_base& v)
00717 { return operator%=((int64) v); }
00718
00719
00720 sc_signed
00721 operator & ( const sc_unsigned& u, const sc_int_base& v )
00722 { return operator & ( u, SCAST<int64>( v ) ); }
00723
00724 sc_signed
00725 operator & ( const sc_int_base& u, const sc_unsigned& v )
00726 { return operator & ( SCAST<int64>( u ), v ); }
00727
00728 sc_signed
00729 operator & (const sc_signed& u, const sc_int_base& v)
00730 { return operator&(u, (int64) v); }
00731
00732 sc_signed
00733 operator & (const sc_int_base& u, const sc_signed& v)
00734 { return operator&((int64) u, v); }
00735
00736 const sc_signed&
00737 sc_signed::operator &= (const sc_int_base& v)
00738 { return operator&=((int64) v); }
00739
00740
00741 sc_signed
00742 operator | ( const sc_unsigned& u, const sc_int_base& v )
00743 { return operator | ( u, SCAST<int64>( v ) ); }
00744
00745 sc_signed
00746 operator | ( const sc_int_base& u, const sc_unsigned& v )
00747 { return operator | ( SCAST<int64>( u ), v ); }
00748
00749 sc_signed
00750 operator | (const sc_signed& u, const sc_int_base& v)
00751 { return operator|(u, (int64) v); }
00752
00753 sc_signed
00754 operator | (const sc_int_base& u, const sc_signed& v)
00755 { return operator|((int64) u, v); }
00756
00757 const sc_signed&
00758 sc_signed::operator |= (const sc_int_base& v)
00759 { return operator|=((int64) v); }
00760
00761
00762 sc_signed
00763 operator ^ ( const sc_unsigned& u, const sc_int_base& v )
00764 { return operator ^ ( u, SCAST<int64>( v ) ); }
00765
00766 sc_signed
00767 operator ^ ( const sc_int_base& u, const sc_unsigned& v )
00768 { return operator ^ ( SCAST<int64>( u ), v ); }
00769
00770 sc_signed
00771 operator ^ (const sc_signed& u, const sc_int_base& v)
00772 { return operator^(u, (int64) v); }
00773
00774 sc_signed
00775 operator ^ (const sc_int_base& u, const sc_signed& v)
00776 { return operator^((int64) u, v); }
00777
00778 const sc_signed&
00779 sc_signed::operator ^= (const sc_int_base& v)
00780 { return operator^=((int64) v); }
00781
00782
00783 sc_signed
00784 operator << (const sc_signed& u, const sc_int_base& v)
00785 { return operator<<(u, (int64) v); }
00786
00787 const sc_signed&
00788 sc_signed::operator <<= (const sc_int_base& v)
00789 { return operator<<=((int64) v); }
00790
00791
00792 sc_signed
00793 operator >> (const sc_signed& u, const sc_int_base& v)
00794 { return operator>>(u, (int64) v); }
00795
00796 const sc_signed&
00797 sc_signed::operator >>= (const sc_int_base& v)
00798 { return operator>>=((int64) v); }
00799
00800
00801 bool
00802 operator == (const sc_signed& u, const sc_int_base& v)
00803 { return operator==(u, (int64) v); }
00804
00805 bool
00806 operator == (const sc_int_base& u, const sc_signed& v)
00807 { return operator==((int64) u, v); }
00808
00809
00810 bool
00811 operator != (const sc_signed& u, const sc_int_base& v)
00812 { return operator!=(u, (int64) v); }
00813
00814 bool
00815 operator != (const sc_int_base& u, const sc_signed& v)
00816 { return operator!=((int64) u, v); }
00817
00818
00819 bool
00820 operator < (const sc_signed& u, const sc_int_base& v)
00821 { return operator<(u, (int64) v); }
00822
00823 bool
00824 operator < (const sc_int_base& u, const sc_signed& v)
00825 { return operator<((int64) u, v); }
00826
00827
00828 bool
00829 operator <= (const sc_signed& u, const sc_int_base& v)
00830 { return operator<=(u, (int64) v); }
00831
00832 bool
00833 operator <= (const sc_int_base& u, const sc_signed& v)
00834 { return operator<=((int64) u, v); }
00835
00836
00837 bool
00838 operator > (const sc_signed& u, const sc_int_base& v)
00839 { return operator>(u, (int64) v); }
00840
00841 bool
00842 operator > (const sc_int_base& u, const sc_signed& v)
00843 { return operator>((int64) u, v); }
00844
00845
00846 bool
00847 operator >= (const sc_signed& u, const sc_int_base& v)
00848 { return operator>=(u, (int64) v); }
00849
00850 bool
00851 operator >= (const sc_int_base& u, const sc_signed& v)
00852 { return operator>=((int64) u, v); }
00853
00854
00855
00856
00857
00858
00859 const sc_signed&
00860 sc_signed::operator = (const sc_uint_base& v)
00861 { return operator=((uint64) v); }
00862
00863
00864 sc_signed
00865 operator + (const sc_signed& u, const sc_uint_base& v)
00866 { return operator+(u, (uint64) v); }
00867
00868 sc_signed
00869 operator + (const sc_uint_base& u, const sc_signed& v)
00870 { return operator+((uint64) u, v); }
00871
00872 const sc_signed&
00873 sc_signed::operator += (const sc_uint_base& v)
00874 { return operator+=((uint64) v); }
00875
00876
00877 sc_signed
00878 operator - (const sc_unsigned& u, const sc_uint_base& v)
00879 { return operator-(u, (uint64) v); }
00880
00881 sc_signed
00882 operator - (const sc_uint_base& u, const sc_unsigned& v)
00883 { return operator-((uint64) u, v); }
00884
00885 sc_signed
00886 operator - (const sc_signed& u, const sc_uint_base& v)
00887 { return operator-(u, (uint64) v); }
00888
00889 sc_signed
00890 operator - (const sc_uint_base& u, const sc_signed& v)
00891 { return operator-((uint64) u, v); }
00892
00893 const sc_signed&
00894 sc_signed::operator -= (const sc_uint_base& v)
00895 { return operator-=((uint64) v); }
00896
00897
00898 sc_signed
00899 operator * (const sc_signed& u, const sc_uint_base& v)
00900 { return operator*(u, (uint64) v); }
00901
00902 sc_signed
00903 operator * (const sc_uint_base& u, const sc_signed& v)
00904 { return operator*((uint64) u, v); }
00905
00906 const sc_signed&
00907 sc_signed::operator *= (const sc_uint_base& v)
00908 { return operator*=((uint64) v); }
00909
00910
00911 sc_signed
00912 operator / (const sc_signed& u, const sc_uint_base& v)
00913 { return operator/(u, (uint64) v); }
00914
00915 sc_signed
00916 operator / (const sc_uint_base& u, const sc_signed& v)
00917 { return operator/((uint64) u, v); }
00918
00919 const sc_signed&
00920 sc_signed::operator /= (const sc_uint_base& v)
00921 { return operator/=((uint64) v); }
00922
00923
00924 sc_signed
00925 operator % (const sc_signed& u, const sc_uint_base& v)
00926 { return operator%(u, (uint64) v); }
00927
00928 sc_signed
00929 operator % (const sc_uint_base& u, const sc_signed& v)
00930 { return operator%((uint64) u, v); }
00931
00932 const sc_signed&
00933 sc_signed::operator %= (const sc_uint_base& v)
00934 { return operator%=((uint64) v); }
00935
00936
00937 sc_signed
00938 operator & (const sc_signed& u, const sc_uint_base& v)
00939 { return operator&(u, (uint64) v); }
00940
00941 sc_signed
00942 operator & (const sc_uint_base& u, const sc_signed& v)
00943 { return operator&((uint64) u, v); }
00944
00945 const sc_signed&
00946 sc_signed::operator &= (const sc_uint_base& v)
00947 { return operator&=((uint64) v); }
00948
00949
00950 sc_signed
00951 operator | (const sc_signed& u, const sc_uint_base& v)
00952 { return operator|(u, (uint64) v); }
00953
00954 sc_signed
00955 operator | (const sc_uint_base& u, const sc_signed& v)
00956 { return operator|((uint64) u, v); }
00957
00958 const sc_signed&
00959 sc_signed::operator |= (const sc_uint_base& v)
00960 { return operator|=((uint64) v); }
00961
00962
00963 sc_signed
00964 operator ^ (const sc_signed& u, const sc_uint_base& v)
00965 { return operator^(u, (uint64) v); }
00966
00967 sc_signed
00968 operator ^ (const sc_uint_base& u, const sc_signed& v)
00969 { return operator^((uint64) u, v); }
00970
00971 const sc_signed&
00972 sc_signed::operator ^= (const sc_uint_base& v)
00973 { return operator^=((uint64) v); }
00974
00975
00976 sc_signed
00977 operator << (const sc_signed& u, const sc_uint_base& v)
00978 { return operator<<(u, (uint64) v); }
00979
00980 const sc_signed&
00981 sc_signed::operator <<= (const sc_uint_base& v)
00982 { return operator<<=((uint64) v); }
00983
00984
00985 sc_signed
00986 operator >> (const sc_signed& u, const sc_uint_base& v)
00987 { return operator>>(u, (uint64) v); }
00988
00989 const sc_signed&
00990 sc_signed::operator >>= (const sc_uint_base& v)
00991 { return operator>>=((uint64) v); }
00992
00993
00994 bool
00995 operator == (const sc_signed& u, const sc_uint_base& v)
00996 { return operator==(u, (uint64) v); }
00997
00998 bool
00999 operator == (const sc_uint_base& u, const sc_signed& v)
01000 { return operator==((uint64) u, v); }
01001
01002
01003 bool
01004 operator != (const sc_signed& u, const sc_uint_base& v)
01005 { return operator!=(u, (uint64) v); }
01006
01007 bool
01008 operator != (const sc_uint_base& u, const sc_signed& v)
01009 { return operator!=((uint64) u, v); }
01010
01011
01012 bool
01013 operator < (const sc_signed& u, const sc_uint_base& v)
01014 { return operator<(u, (uint64) v); }
01015
01016 bool
01017 operator < (const sc_uint_base& u, const sc_signed& v)
01018 { return operator<((uint64) u, v); }
01019
01020
01021 bool
01022 operator <= (const sc_signed& u, const sc_uint_base& v)
01023 { return operator<=(u, (uint64) v); }
01024
01025 bool
01026 operator <= (const sc_uint_base& u, const sc_signed& v)
01027 { return operator<=((uint64) u, v); }
01028
01029
01030 bool
01031 operator > (const sc_signed& u, const sc_uint_base& v)
01032 { return operator>(u, (uint64) v); }
01033
01034 bool
01035 operator > (const sc_uint_base& u, const sc_signed& v)
01036 { return operator>((uint64) u, v); }
01037
01038
01039 bool
01040 operator >= (const sc_signed& u, const sc_uint_base& v)
01041 { return operator>=(u, (uint64) v); }
01042
01043 bool
01044 operator >= (const sc_uint_base& u, const sc_signed& v)
01045 { return operator>=((uint64) u, v); }
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059 #define CONVERT_LONG(u) \
01060 small_type u ## s = get_sign(u); \
01061 sc_digit u ## d[DIGITS_PER_ULONG]; \
01062 from_uint(DIGITS_PER_ULONG, u ## d, (unsigned long) u);
01063
01064 #define CONVERT_LONG_2(u) \
01065 sc_digit u ## d[DIGITS_PER_ULONG]; \
01066 from_uint(DIGITS_PER_ULONG, u ## d, (unsigned long) u);
01067
01068 #define CONVERT_INT(u) \
01069 small_type u ## s = get_sign(u); \
01070 sc_digit u ## d[DIGITS_PER_UINT]; \
01071 from_uint(DIGITS_PER_UINT, u ## d, (unsigned int) u);
01072
01073 #define CONVERT_INT_2(u) \
01074 sc_digit u ## d[DIGITS_PER_UINT]; \
01075 from_uint(DIGITS_PER_UINT, u ## d, (unsigned int) u);
01076
01077 #define CONVERT_INT64(u) \
01078 small_type u ## s = get_sign(u); \
01079 sc_digit u ## d[DIGITS_PER_UINT64]; \
01080 from_uint(DIGITS_PER_UINT64, u ## d, (uint64) u);
01081
01082 #define CONVERT_INT64_2(u) \
01083 sc_digit u ## d[DIGITS_PER_UINT64]; \
01084 from_uint(DIGITS_PER_UINT64, u ## d, (uint64) u);
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106 sc_signed
01107 operator+(const sc_unsigned& u, const sc_signed& v)
01108 {
01109
01110 if (u.sgn == SC_ZERO)
01111 return sc_signed(v);
01112
01113 if (v.sgn == SC_ZERO)
01114 return sc_signed(u);
01115
01116
01117 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01118 v.sgn, v.nbits, v.ndigits, v.digit);
01119
01120 }
01121
01122
01123 sc_signed
01124 operator+(const sc_signed& u, const sc_unsigned& v)
01125 {
01126
01127 if (u.sgn == SC_ZERO)
01128 return sc_signed(v);
01129
01130 if (v.sgn == SC_ZERO)
01131 return sc_signed(u);
01132
01133
01134 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01135 v.sgn, v.nbits, v.ndigits, v.digit);
01136
01137 }
01138
01139
01140 sc_signed
01141 operator+(const sc_signed& u, const sc_signed& v)
01142 {
01143
01144 if (u.sgn == SC_ZERO)
01145 return sc_signed(v);
01146
01147 if (v.sgn == SC_ZERO)
01148 return sc_signed(u);
01149
01150
01151 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01152 v.sgn, v.nbits, v.ndigits, v.digit);
01153
01154 }
01155
01156
01157 sc_signed
01158 operator+(const sc_signed &u, int64 v)
01159 {
01160
01161 if (v == 0)
01162 return sc_signed(u);
01163
01164 CONVERT_INT64(v);
01165
01166 if (u.sgn == SC_ZERO)
01167 return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
01168
01169
01170 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01171 vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
01172
01173 }
01174
01175
01176 sc_signed
01177 operator+(int64 u, const sc_signed &v)
01178 {
01179
01180 if (u == 0)
01181 return sc_signed(v);
01182
01183 CONVERT_INT64(u);
01184
01185 if (v.sgn == SC_ZERO)
01186 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
01187
01188
01189
01190 return add_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
01191 v.sgn, v.nbits, v.ndigits, v.digit);
01192
01193 }
01194
01195
01196 sc_signed
01197 operator+(const sc_unsigned &u, int64 v)
01198 {
01199
01200 if (v == 0)
01201 return sc_signed(u);
01202
01203 CONVERT_INT64(v);
01204
01205 if (u.sgn == SC_ZERO)
01206 return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
01207
01208
01209 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01210 vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
01211
01212 }
01213
01214
01215 sc_signed
01216 operator+(int64 u, const sc_unsigned &v)
01217 {
01218
01219 if (u == 0)
01220 return sc_signed(v);
01221
01222 CONVERT_INT64(u);
01223
01224 if (v.sgn == SC_ZERO)
01225 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
01226
01227
01228
01229 return add_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
01230 v.sgn, v.nbits, v.ndigits, v.digit);
01231
01232 }
01233
01234
01235 sc_signed
01236 operator+(const sc_signed &u, uint64 v)
01237 {
01238
01239 if (v == 0)
01240 return sc_signed(u);
01241
01242 CONVERT_INT64(v);
01243
01244 if (u.sgn == SC_ZERO)
01245 return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
01246
01247
01248 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01249 vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
01250
01251 }
01252
01253
01254 sc_signed
01255 operator+(uint64 u, const sc_signed &v)
01256 {
01257
01258 if (u == 0)
01259 return sc_signed(v);
01260
01261 CONVERT_INT64(u);
01262
01263 if (v.sgn == SC_ZERO)
01264 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
01265
01266
01267
01268 return add_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
01269 v.sgn, v.nbits, v.ndigits, v.digit);
01270
01271 }
01272
01273
01274 sc_signed
01275 operator+(const sc_signed &u, long v)
01276 {
01277
01278 if (v == 0)
01279 return sc_signed(u);
01280
01281 CONVERT_LONG(v);
01282
01283 if (u.sgn == SC_ZERO)
01284 return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
01285
01286
01287 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01288 vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
01289
01290 }
01291
01292
01293 sc_signed
01294 operator+(long u, const sc_signed &v)
01295 {
01296
01297 if (u == 0)
01298 return sc_signed(v);
01299
01300 CONVERT_LONG(u);
01301
01302 if (v.sgn == SC_ZERO)
01303 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
01304
01305
01306 return add_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
01307 v.sgn, v.nbits, v.ndigits, v.digit);
01308
01309 }
01310
01311
01312 sc_signed
01313 operator+(const sc_unsigned &u, long v)
01314 {
01315
01316 if (v == 0)
01317 return sc_signed(u);
01318
01319 CONVERT_LONG(v);
01320
01321 if (u.sgn == SC_ZERO)
01322 return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
01323
01324
01325 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01326 vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
01327
01328 }
01329
01330
01331 sc_signed
01332 operator+(long u, const sc_unsigned &v)
01333 {
01334
01335 if (u == 0)
01336 return sc_signed(v);
01337
01338 CONVERT_LONG(u);
01339
01340 if (v.sgn == SC_ZERO)
01341 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
01342
01343
01344 return add_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
01345 v.sgn, v.nbits, v.ndigits, v.digit);
01346
01347 }
01348
01349
01350 sc_signed
01351 operator+(const sc_signed &u, unsigned long v)
01352 {
01353
01354 if (v == 0)
01355 return sc_signed(u);
01356
01357 CONVERT_LONG(v);
01358
01359 if (u.sgn == SC_ZERO)
01360 return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
01361
01362
01363 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01364 vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
01365
01366 }
01367
01368
01369 sc_signed
01370 operator+(unsigned long u, const sc_signed &v)
01371 {
01372
01373 if (u == 0)
01374 return sc_signed(v);
01375
01376 CONVERT_LONG(u);
01377
01378 if (v.sgn == SC_ZERO)
01379 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
01380
01381
01382 return add_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
01383 v.sgn, v.nbits, v.ndigits, v.digit);
01384
01385 }
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409 sc_signed
01410 operator-(const sc_unsigned& u, const sc_unsigned& v)
01411 {
01412
01413 if (v.sgn == SC_ZERO)
01414 return sc_signed(u);
01415
01416 if (u.sgn == SC_ZERO)
01417 return sc_signed(v, -v.sgn);
01418
01419
01420 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01421 -v.sgn, v.nbits, v.ndigits, v.digit);
01422
01423 }
01424
01425
01426 sc_signed
01427 operator-(const sc_unsigned& u, const sc_signed& v)
01428 {
01429
01430 if (v.sgn == SC_ZERO)
01431 return sc_signed(u);
01432
01433 if (u.sgn == SC_ZERO)
01434 return sc_signed(v, -v.sgn);
01435
01436
01437 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01438 -v.sgn, v.nbits, v.ndigits, v.digit);
01439
01440 }
01441
01442
01443 sc_signed
01444 operator-(const sc_signed& u, const sc_unsigned& v)
01445 {
01446
01447 if (v.sgn == SC_ZERO)
01448 return sc_signed(u);
01449
01450 if (u.sgn == SC_ZERO)
01451 return sc_signed(v, -v.sgn);
01452
01453
01454 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01455 -v.sgn, v.nbits, v.ndigits, v.digit);
01456
01457 }
01458
01459
01460 sc_signed
01461 operator-(const sc_signed& u, const sc_signed& v)
01462 {
01463
01464 if (v.sgn == SC_ZERO)
01465 return sc_signed(u);
01466
01467 if (u.sgn == SC_ZERO)
01468 return sc_signed(v, -v.sgn);
01469
01470
01471 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01472 -v.sgn, v.nbits, v.ndigits, v.digit);
01473
01474 }
01475
01476
01477 sc_signed
01478 operator-(const sc_signed &u, int64 v)
01479 {
01480
01481 if (v == 0)
01482 return sc_signed(u);
01483
01484 CONVERT_INT64(v);
01485
01486 if (u.sgn == SC_ZERO)
01487 return sc_signed(-vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
01488
01489
01490 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01491 -vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
01492
01493 }
01494
01495
01496 sc_signed
01497 operator-(int64 u, const sc_signed& v)
01498 {
01499
01500 if (u == 0)
01501 return sc_signed(v, -v.sgn);
01502
01503 CONVERT_INT64(u);
01504
01505 if (v.sgn == SC_ZERO)
01506 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
01507
01508
01509
01510 return add_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
01511 -v.sgn, v.nbits, v.ndigits, v.digit);
01512
01513 }
01514
01515
01516 sc_signed
01517 operator-(const sc_unsigned &u, int64 v)
01518 {
01519
01520 if (v == 0)
01521 return sc_signed(u);
01522
01523 CONVERT_INT64(v);
01524
01525 if (u.sgn == SC_ZERO)
01526 return sc_signed(-vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
01527
01528
01529 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01530 -vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
01531
01532 }
01533
01534
01535 sc_signed
01536 operator-(int64 u, const sc_unsigned& v)
01537 {
01538
01539 if (u == 0)
01540 return sc_signed(v, -v.sgn);
01541
01542 CONVERT_INT64(u);
01543
01544 if (v.sgn == SC_ZERO)
01545 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
01546
01547
01548
01549 return add_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
01550 -v.sgn, v.nbits, v.ndigits, v.digit);
01551
01552 }
01553
01554
01555 sc_signed
01556 operator-(const sc_signed &u, uint64 v)
01557 {
01558
01559 if (v == 0)
01560 return sc_signed(u);
01561
01562 CONVERT_INT64(v);
01563
01564 if (u.sgn == SC_ZERO)
01565 return sc_signed(-vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
01566
01567
01568
01569 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01570 -vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
01571
01572 }
01573
01574
01575 sc_signed
01576 operator-(uint64 u, const sc_signed& v)
01577 {
01578
01579 if (u == 0)
01580 return sc_signed(v, -v.sgn);
01581
01582 CONVERT_INT64(u);
01583
01584 if (v.sgn == SC_ZERO)
01585 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
01586
01587
01588 return add_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
01589 -v.sgn, v.nbits, v.ndigits, v.digit);
01590
01591 }
01592
01593
01594 sc_signed
01595 operator-(const sc_unsigned &u, uint64 v)
01596 {
01597
01598 if (v == 0)
01599 return sc_signed(u);
01600
01601 CONVERT_INT64(v);
01602
01603 if (u.sgn == SC_ZERO)
01604 return sc_signed(-vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
01605
01606
01607
01608 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01609 -vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
01610
01611 }
01612
01613
01614 sc_signed
01615 operator-(uint64 u, const sc_unsigned& v)
01616 {
01617
01618 if (u == 0)
01619 return sc_signed(v, -v.sgn);
01620
01621 CONVERT_INT64(u);
01622
01623 if (v.sgn == SC_ZERO)
01624 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
01625
01626
01627 return add_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
01628 -v.sgn, v.nbits, v.ndigits, v.digit);
01629
01630 }
01631
01632
01633 sc_signed
01634 operator-(const sc_signed &u, long v)
01635 {
01636
01637 if (v == 0)
01638 return sc_signed(u);
01639
01640 CONVERT_LONG(v);
01641
01642 if (u.sgn == SC_ZERO)
01643 return sc_signed(-vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
01644
01645
01646 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01647 -vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
01648
01649 }
01650
01651
01652 sc_signed
01653 operator-(long u, const sc_signed& v)
01654 {
01655
01656 if (u == 0)
01657 return sc_signed(v, -v.sgn);
01658
01659 CONVERT_LONG(u);
01660
01661 if (v.sgn == SC_ZERO)
01662 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
01663
01664
01665 return add_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
01666 -v.sgn, v.nbits, v.ndigits, v.digit);
01667
01668 }
01669
01670
01671 sc_signed
01672 operator-(const sc_unsigned &u, long v)
01673 {
01674
01675 if (v == 0)
01676 return sc_signed(u);
01677
01678 CONVERT_LONG(v);
01679
01680 if (u.sgn == SC_ZERO)
01681 return sc_signed(-vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
01682
01683
01684 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01685 -vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
01686
01687 }
01688
01689
01690 sc_signed
01691 operator-(long u, const sc_unsigned& v)
01692 {
01693
01694 if (u == 0)
01695 return sc_signed(v, -v.sgn);
01696
01697 CONVERT_LONG(u);
01698
01699 if (v.sgn == SC_ZERO)
01700 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
01701
01702
01703 return add_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
01704 -v.sgn, v.nbits, v.ndigits, v.digit);
01705
01706 }
01707
01708
01709 sc_signed
01710 operator-(const sc_signed &u, unsigned long v)
01711 {
01712
01713 if (v == 0)
01714 return sc_signed(u);
01715
01716 CONVERT_LONG(v);
01717
01718 if (u.sgn == SC_ZERO)
01719 return sc_signed(-vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
01720
01721
01722 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01723 -vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
01724
01725 }
01726
01727
01728 sc_signed
01729 operator-(unsigned long u, const sc_signed& v)
01730 {
01731 if (u == 0)
01732 return sc_signed(v, -v.sgn);
01733
01734 CONVERT_LONG(u);
01735
01736 if (v.sgn == SC_ZERO)
01737 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
01738
01739
01740 return add_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
01741 -v.sgn, v.nbits, v.ndigits, v.digit);
01742
01743 }
01744
01745
01746 sc_signed
01747 operator-(const sc_unsigned &u, unsigned long v)
01748 {
01749
01750 if (v == 0)
01751 return sc_signed(u);
01752
01753 CONVERT_LONG(v);
01754
01755 if (u.sgn == SC_ZERO)
01756 return sc_signed(-vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
01757
01758
01759 return add_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
01760 -vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
01761
01762 }
01763
01764
01765 sc_signed
01766 operator-(unsigned long u, const sc_unsigned& v)
01767 {
01768 if (u == 0)
01769 return sc_signed(v, -v.sgn);
01770
01771 CONVERT_LONG(u);
01772
01773 if (v.sgn == SC_ZERO)
01774 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
01775
01776
01777 return add_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
01778 -v.sgn, v.nbits, v.ndigits, v.digit);
01779
01780 }
01781
01782
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795
01796 sc_signed
01797 operator*(const sc_unsigned& u, const sc_signed& v)
01798 {
01799
01800 small_type s = mul_signs(u.sgn, v.sgn);
01801
01802 if (s == SC_ZERO)
01803 return sc_signed();
01804
01805
01806 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit,
01807 v.nbits, v.ndigits, v.digit);
01808
01809 }
01810
01811
01812 sc_signed
01813 operator*(const sc_signed& u, const sc_unsigned& v)
01814 {
01815
01816 small_type s = mul_signs(u.sgn, v.sgn);
01817
01818 if (s == SC_ZERO)
01819 return sc_signed();
01820
01821
01822 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit,
01823 v.nbits, v.ndigits, v.digit);
01824
01825 }
01826
01827
01828 sc_signed
01829 operator*(const sc_signed& u, const sc_signed& v)
01830 {
01831
01832 small_type s = mul_signs(u.sgn, v.sgn);
01833
01834 if (s == SC_ZERO)
01835 return sc_signed();
01836
01837
01838 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit,
01839 v.nbits, v.ndigits, v.digit);
01840
01841 }
01842
01843
01844 sc_signed
01845 operator*(const sc_signed& u, int64 v)
01846 {
01847
01848 small_type s = mul_signs(u.sgn, get_sign(v));
01849
01850 if (s == SC_ZERO)
01851 return sc_signed();
01852
01853 CONVERT_INT64_2(v);
01854
01855
01856 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit,
01857 BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
01858
01859 }
01860
01861
01862 sc_signed
01863 operator*(int64 u, const sc_signed& v)
01864 {
01865
01866 small_type s = mul_signs(v.sgn, get_sign(u));
01867
01868 if (s == SC_ZERO)
01869 return sc_signed();
01870
01871 CONVERT_INT64_2(u);
01872
01873
01874 return mul_signed_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
01875 v.nbits, v.ndigits, v.digit);
01876
01877 }
01878
01879
01880 sc_signed
01881 operator*(const sc_unsigned& u, int64 v)
01882 {
01883
01884 small_type s = mul_signs(u.sgn, get_sign(v));
01885
01886 if (s == SC_ZERO)
01887 return sc_signed();
01888
01889 CONVERT_INT64_2(v);
01890
01891
01892 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit,
01893 BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
01894
01895 }
01896
01897
01898 sc_signed
01899 operator*(int64 u, const sc_unsigned& v)
01900 {
01901
01902 small_type s = mul_signs(v.sgn, get_sign(u));
01903
01904 if (s == SC_ZERO)
01905 return sc_signed();
01906
01907 CONVERT_INT64_2(u);
01908
01909
01910 return mul_signed_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
01911 v.nbits, v.ndigits, v.digit);
01912
01913 }
01914
01915
01916 sc_signed
01917 operator*(const sc_signed& u, uint64 v)
01918 {
01919
01920 small_type s = mul_signs(u.sgn, get_sign(v));
01921
01922 if (s == SC_ZERO)
01923 return sc_signed();
01924
01925 CONVERT_INT64_2(v);
01926
01927
01928 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit,
01929 BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
01930
01931 }
01932
01933
01934 sc_signed
01935 operator*(uint64 u, const sc_signed& v)
01936 {
01937
01938 small_type s = mul_signs(v.sgn, get_sign(u));
01939
01940 if (s == SC_ZERO)
01941 return sc_signed();
01942
01943 CONVERT_INT64_2(u);
01944
01945
01946 return mul_signed_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
01947 v.nbits, v.ndigits, v.digit);
01948
01949 }
01950
01951
01952 sc_signed
01953 operator*(const sc_signed& u, long v)
01954 {
01955
01956 small_type s = mul_signs(u.sgn, get_sign(v));
01957
01958 if (s == SC_ZERO)
01959 return sc_signed();
01960
01961 CONVERT_LONG_2(v);
01962
01963
01964 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit,
01965 BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
01966
01967 }
01968
01969
01970 sc_signed
01971 operator*(long u, const sc_signed& v)
01972 {
01973
01974 small_type s = mul_signs(v.sgn, get_sign(u));
01975
01976 if (s == SC_ZERO)
01977 return sc_signed();
01978
01979 CONVERT_LONG_2(u);
01980
01981
01982 return mul_signed_friend(s, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
01983 v.nbits, v.ndigits, v.digit);
01984
01985 }
01986
01987
01988 sc_signed
01989 operator*(const sc_unsigned& u, long v)
01990 {
01991
01992 small_type s = mul_signs(u.sgn, get_sign(v));
01993
01994 if (s == SC_ZERO)
01995 return sc_signed();
01996
01997 CONVERT_LONG_2(v);
01998
01999
02000 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit,
02001 BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
02002
02003 }
02004
02005
02006 sc_signed
02007 operator*(long u, const sc_unsigned& v)
02008 {
02009
02010 small_type s = mul_signs(v.sgn, get_sign(u));
02011
02012 if (s == SC_ZERO)
02013 return sc_signed();
02014
02015 CONVERT_LONG_2(u);
02016
02017
02018 return mul_signed_friend(s, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
02019 v.nbits, v.ndigits, v.digit);
02020
02021 }
02022
02023
02024 sc_signed
02025 operator*(const sc_signed& u, unsigned long v)
02026 {
02027
02028 small_type s = mul_signs(u.sgn, get_sign(v));
02029
02030 if (s == SC_ZERO)
02031 return sc_signed();
02032
02033 CONVERT_LONG_2(v);
02034
02035
02036 return mul_signed_friend(s, u.nbits, u.ndigits, u.digit,
02037 BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
02038
02039 }
02040
02041 sc_signed
02042 operator*(unsigned long u, const sc_signed& v)
02043 {
02044
02045 small_type s = mul_signs(v.sgn, get_sign(u));
02046
02047 if (s == SC_ZERO)
02048 return sc_signed();
02049
02050 CONVERT_LONG_2(u);
02051
02052
02053 return mul_signed_friend(s, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
02054 v.nbits, v.ndigits, v.digit);
02055
02056 }
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068
02069
02070
02071
02072
02073
02074 sc_signed
02075 operator/(const sc_unsigned& u, const sc_signed& v)
02076 {
02077
02078 small_type s = mul_signs(u.sgn, v.sgn);
02079
02080 if (s == SC_ZERO) {
02081 div_by_zero(v.sgn);
02082 return sc_signed();
02083 }
02084
02085
02086 return div_signed_friend(s, u.nbits, u.ndigits, u.digit,
02087 v.nbits, v.ndigits, v.digit);
02088
02089 }
02090
02091
02092 sc_signed
02093 operator/(const sc_signed& u, const sc_unsigned& v)
02094 {
02095
02096 small_type s = mul_signs(u.sgn, v.sgn);
02097
02098 if (s == SC_ZERO) {
02099 div_by_zero(v.sgn);
02100 return sc_signed();
02101 }
02102
02103
02104 return div_signed_friend(s, u.nbits, u.ndigits, u.digit,
02105 v.nbits, v.ndigits, v.digit);
02106
02107 }
02108
02109
02110 sc_signed
02111 operator/(const sc_signed& u, const sc_signed& v)
02112 {
02113
02114 small_type s = mul_signs(u.sgn, v.sgn);
02115
02116 if (s == SC_ZERO) {
02117 div_by_zero(v.sgn);
02118 return sc_signed();
02119 }
02120
02121
02122 return div_signed_friend(s, u.nbits, u.ndigits, u.digit,
02123 v.nbits, v.ndigits, v.digit);
02124
02125 }
02126
02127
02128 sc_signed
02129 operator/(const sc_signed& u, int64 v)
02130 {
02131
02132 small_type s = mul_signs(u.sgn, get_sign(v));
02133
02134 if (s == SC_ZERO) {
02135 div_by_zero(v);
02136 return sc_signed();
02137 }
02138
02139 CONVERT_INT64_2(v);
02140
02141
02142 return div_signed_friend(s, u.nbits, u.ndigits, u.digit,
02143 BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
02144
02145 }
02146
02147
02148 sc_signed
02149 operator/(int64 u, const sc_signed& v)
02150 {
02151
02152 small_type s = mul_signs(v.sgn, get_sign(u));
02153
02154 if (s == SC_ZERO) {
02155 div_by_zero(v.sgn);
02156 return sc_signed();
02157 }
02158
02159 CONVERT_INT64_2(u);
02160
02161
02162 return div_signed_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
02163 v.nbits, v.ndigits, v.digit);
02164
02165 }
02166
02167
02168 sc_signed
02169 operator/(const sc_unsigned& u, int64 v)
02170 {
02171
02172 small_type s = mul_signs(u.sgn, get_sign(v));
02173
02174 if (s == SC_ZERO) {
02175 div_by_zero(v);
02176 return sc_signed();
02177 }
02178
02179 CONVERT_INT64_2(v);
02180
02181
02182 return div_signed_friend(s, u.nbits, u.ndigits, u.digit,
02183 BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
02184
02185 }
02186
02187
02188 sc_signed
02189 operator/(int64 u, const sc_unsigned& v)
02190 {
02191
02192 small_type s = mul_signs(v.sgn, get_sign(u));
02193
02194 if (s == SC_ZERO) {
02195 div_by_zero(v.sgn);
02196 return sc_signed();
02197 }
02198
02199 CONVERT_INT64_2(u);
02200
02201
02202 return div_signed_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
02203 v.nbits, v.ndigits, v.digit);
02204
02205 }
02206
02207
02208 sc_signed
02209 operator/(const sc_signed& u, uint64 v)
02210 {
02211
02212 small_type s = mul_signs(u.sgn, get_sign(v));
02213
02214 if (s == SC_ZERO) {
02215 div_by_zero(v);
02216 return sc_signed();
02217 }
02218
02219 CONVERT_INT64_2(v);
02220
02221
02222 return div_signed_friend(s, u.nbits, u.ndigits, u.digit,
02223 BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
02224
02225 }
02226
02227
02228 sc_signed
02229 operator/(uint64 u, const sc_signed& v)
02230 {
02231
02232 small_type s = mul_signs(v.sgn, get_sign(u));
02233
02234 if (s == SC_ZERO) {
02235 div_by_zero(v.sgn);
02236 return sc_signed();
02237
02238 }
02239
02240 CONVERT_INT64_2(u);
02241
02242
02243 return div_signed_friend(s, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
02244 v.nbits, v.ndigits, v.digit);
02245
02246 }
02247
02248
02249 sc_signed
02250 operator/(const sc_signed& u, long v)
02251 {
02252
02253 small_type s = mul_signs(u.sgn, get_sign(v));
02254
02255 if (s == SC_ZERO) {
02256 div_by_zero(v);
02257 return sc_signed();
02258 }
02259
02260 CONVERT_LONG_2(v);
02261
02262
02263 return div_signed_friend(s, u.nbits, u.ndigits, u.digit,
02264 BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
02265
02266 }
02267
02268
02269 sc_signed
02270 operator/(long u, const sc_signed& v)
02271 {
02272
02273 small_type s = mul_signs(v.sgn, get_sign(u));
02274
02275 if (s == SC_ZERO) {
02276 div_by_zero(v.sgn);
02277 return sc_signed();
02278 }
02279
02280 CONVERT_LONG_2(u);
02281
02282
02283 return div_signed_friend(s, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
02284 v.nbits, v.ndigits, v.digit);
02285
02286 }
02287
02288
02289 sc_signed
02290 operator/(const sc_unsigned& u, long v)
02291 {
02292
02293 small_type s = mul_signs(u.sgn, get_sign(v));
02294
02295 if (s == SC_ZERO) {
02296 div_by_zero(v);
02297 return sc_signed();
02298 }
02299
02300 CONVERT_LONG_2(v);
02301
02302
02303 return div_signed_friend(s, u.nbits, u.ndigits, u.digit,
02304 BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
02305
02306 }
02307
02308
02309 sc_signed
02310 operator/(long u, const sc_unsigned& v)
02311 {
02312
02313 small_type s = mul_signs(v.sgn, get_sign(u));
02314
02315 if (s == SC_ZERO) {
02316 div_by_zero(v.sgn);
02317 return sc_signed();
02318 }
02319
02320 CONVERT_LONG_2(u);
02321
02322
02323 return div_signed_friend(s, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
02324 v.nbits, v.ndigits, v.digit);
02325
02326 }
02327
02328
02329 sc_signed
02330 operator/(const sc_signed& u, unsigned long v)
02331 {
02332
02333 small_type s = mul_signs(u.sgn, get_sign(v));
02334
02335 if (s == SC_ZERO) {
02336 div_by_zero(v);
02337 return sc_signed();
02338 }
02339
02340 CONVERT_LONG_2(v);
02341
02342
02343 return div_signed_friend(s, u.nbits, u.ndigits, u.digit,
02344 BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
02345
02346 }
02347
02348
02349 sc_signed
02350 operator/(unsigned long u, const sc_signed& v)
02351 {
02352
02353 small_type s = mul_signs(v.sgn, get_sign(u));
02354
02355 if (s == SC_ZERO) {
02356 div_by_zero(v.sgn);
02357 return sc_signed();
02358
02359 }
02360
02361 CONVERT_LONG_2(u);
02362
02363
02364 return div_signed_friend(s, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
02365 v.nbits, v.ndigits, v.digit);
02366
02367 }
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380
02381
02382
02383
02384
02385 sc_signed
02386 operator%(const sc_unsigned& u, const sc_signed& v)
02387 {
02388
02389 if ((u.sgn == SC_ZERO) || (v.sgn == SC_ZERO)) {
02390 div_by_zero(v.sgn);
02391 return sc_signed();
02392 }
02393
02394
02395 return mod_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02396 v.nbits, v.ndigits, v.digit);
02397 }
02398
02399
02400 sc_signed
02401 operator%(const sc_signed& u, const sc_unsigned& v)
02402 {
02403
02404 if ((u.sgn == SC_ZERO) || (v.sgn == SC_ZERO)) {
02405 div_by_zero(v.sgn);
02406 return sc_signed();
02407 }
02408
02409
02410 return mod_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02411 v.nbits, v.ndigits, v.digit);
02412 }
02413
02414
02415 sc_signed
02416 operator%(const sc_signed& u, const sc_signed& v)
02417 {
02418
02419 if ((u.sgn == SC_ZERO) || (v.sgn == SC_ZERO)) {
02420 div_by_zero(v.sgn);
02421 return sc_signed();
02422 }
02423
02424
02425 return mod_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02426 v.nbits, v.ndigits, v.digit);
02427 }
02428
02429
02430 sc_signed
02431 operator%(const sc_signed& u, int64 v)
02432 {
02433
02434 small_type vs = get_sign(v);
02435
02436 if ((u.sgn == SC_ZERO) || (vs == SC_ZERO)) {
02437 div_by_zero(v);
02438 return sc_signed();
02439 }
02440
02441 CONVERT_INT64_2(v);
02442
02443
02444 return mod_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02445 BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
02446
02447 }
02448
02449
02450 sc_signed
02451 operator%(int64 u, const sc_signed& v)
02452 {
02453
02454 small_type us = get_sign(u);
02455
02456 if ((us == SC_ZERO) || (v.sgn == SC_ZERO)) {
02457 div_by_zero(v.sgn);
02458 return sc_signed();
02459 }
02460
02461 CONVERT_INT64_2(u);
02462
02463
02464 return mod_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
02465 v.nbits, v.ndigits, v.digit);
02466
02467 }
02468
02469
02470 sc_signed
02471 operator%(const sc_unsigned& u, int64 v)
02472 {
02473
02474 small_type vs = get_sign(v);
02475
02476 if ((u.sgn == SC_ZERO) || (vs == SC_ZERO)) {
02477 div_by_zero(v);
02478 return sc_signed();
02479 }
02480
02481 CONVERT_INT64_2(v);
02482
02483
02484 return mod_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02485 BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
02486
02487 }
02488
02489
02490 sc_signed
02491 operator%(int64 u, const sc_unsigned& v)
02492 {
02493
02494 small_type us = get_sign(u);
02495
02496 if ((us == SC_ZERO) || (v.sgn == SC_ZERO)) {
02497 div_by_zero(v.sgn);
02498 return sc_signed();
02499 }
02500
02501 CONVERT_INT64_2(u);
02502
02503
02504 return mod_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
02505 v.nbits, v.ndigits, v.digit);
02506
02507 }
02508
02509
02510 sc_signed
02511 operator%(const sc_signed& u, uint64 v)
02512 {
02513
02514 if ((u.sgn == SC_ZERO) || (v == 0)) {
02515 div_by_zero(v);
02516 return sc_signed();
02517 }
02518
02519 CONVERT_INT64_2(v);
02520
02521
02522 return mod_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02523 BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
02524
02525 }
02526
02527
02528 sc_signed
02529 operator%(uint64 u, const sc_signed& v)
02530 {
02531
02532 if ((u == 0) || (v.sgn == SC_ZERO)) {
02533 div_by_zero(v.sgn);
02534 return sc_signed();
02535 }
02536
02537 CONVERT_INT64(u);
02538
02539
02540 return mod_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
02541 v.nbits, v.ndigits, v.digit);
02542
02543 }
02544
02545
02546 sc_signed
02547 operator%(const sc_signed& u, long v)
02548 {
02549
02550 small_type vs = get_sign(v);
02551
02552 if ((u.sgn == SC_ZERO) || (vs == SC_ZERO)) {
02553 div_by_zero(v);
02554 return sc_signed();
02555 }
02556
02557 CONVERT_LONG_2(v);
02558
02559
02560 return mod_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02561 BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
02562 }
02563
02564
02565 sc_signed
02566 operator%(long u, const sc_signed& v)
02567 {
02568
02569 small_type us = get_sign(u);
02570
02571 if ((us == SC_ZERO) || (v.sgn == SC_ZERO)) {
02572 div_by_zero(v.sgn);
02573 return sc_signed();
02574 }
02575
02576 CONVERT_LONG_2(u);
02577
02578
02579 return mod_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
02580 v.nbits, v.ndigits, v.digit);
02581
02582 }
02583
02584
02585 sc_signed
02586 operator%(const sc_unsigned& u, long v)
02587 {
02588
02589 small_type vs = get_sign(v);
02590
02591 if ((u.sgn == SC_ZERO) || (vs == SC_ZERO)) {
02592 div_by_zero(v);
02593 return sc_signed();
02594 }
02595
02596 CONVERT_LONG_2(v);
02597
02598
02599 return mod_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02600 BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
02601 }
02602
02603
02604 sc_signed
02605 operator%(long u, const sc_unsigned& v)
02606 {
02607
02608 small_type us = get_sign(u);
02609
02610 if ((us == SC_ZERO) || (v.sgn == SC_ZERO)) {
02611 div_by_zero(v.sgn);
02612 return sc_signed();
02613 }
02614
02615 CONVERT_LONG_2(u);
02616
02617
02618 return mod_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
02619 v.nbits, v.ndigits, v.digit);
02620
02621 }
02622
02623
02624 sc_signed
02625 operator%(const sc_signed& u, unsigned long v)
02626 {
02627
02628 if ((u.sgn == SC_ZERO) || (v == 0)) {
02629 div_by_zero(v);
02630 return sc_signed();
02631 }
02632
02633 CONVERT_LONG_2(v);
02634
02635
02636 return mod_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02637 BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
02638
02639 }
02640
02641
02642 sc_signed
02643 operator%(unsigned long u, const sc_signed& v)
02644 {
02645
02646 if ((u == 0) || (v.sgn == SC_ZERO)) {
02647 div_by_zero(v.sgn);
02648 return sc_signed();
02649 }
02650
02651 CONVERT_LONG(u);
02652
02653
02654 return mod_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
02655 v.nbits, v.ndigits, v.digit);
02656
02657 }
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674 sc_signed
02675 operator&(const sc_unsigned& u, const sc_signed& v)
02676 {
02677
02678 if ((u.sgn == SC_ZERO) || (v.sgn == SC_ZERO))
02679 return sc_signed();
02680
02681
02682 return and_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02683 v.sgn, v.nbits, v.ndigits, v.digit);
02684
02685 }
02686
02687
02688 sc_signed
02689 operator&(const sc_signed& u, const sc_unsigned& v)
02690 {
02691
02692 if ((u.sgn == SC_ZERO) || (v.sgn == SC_ZERO))
02693 return sc_signed();
02694
02695
02696 return and_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02697 v.sgn, v.nbits, v.ndigits, v.digit);
02698
02699 }
02700
02701
02702 sc_signed
02703 operator&(const sc_signed& u, const sc_signed& v)
02704 {
02705
02706 if ((u.sgn == SC_ZERO) || (v.sgn == SC_ZERO))
02707 return sc_signed();
02708
02709
02710 return and_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02711 v.sgn, v.nbits, v.ndigits, v.digit);
02712
02713 }
02714
02715
02716 sc_signed
02717 operator&(const sc_signed& u, int64 v)
02718 {
02719
02720 if ((u.sgn == SC_ZERO) || (v == 0))
02721 return sc_signed();
02722
02723 CONVERT_INT64(v);
02724
02725
02726 return and_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02727 vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
02728
02729 }
02730
02731
02732 sc_signed
02733 operator&(int64 u, const sc_signed& v)
02734 {
02735
02736 if ((u == 0) || (v.sgn == SC_ZERO))
02737 return sc_signed();
02738
02739 CONVERT_INT64(u);
02740
02741
02742 return and_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
02743 v.sgn, v.nbits, v.ndigits, v.digit);
02744
02745 }
02746
02747
02748 sc_signed
02749 operator&(const sc_unsigned& u, int64 v)
02750 {
02751
02752 if ((u.sgn == SC_ZERO) || (v == 0))
02753 return sc_signed();
02754
02755 CONVERT_INT64(v);
02756
02757
02758 return and_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02759 vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
02760
02761 }
02762
02763
02764 sc_signed
02765 operator&(int64 u, const sc_unsigned& v)
02766 {
02767
02768 if ((u == 0) || (v.sgn == SC_ZERO))
02769 return sc_signed();
02770
02771 CONVERT_INT64(u);
02772
02773
02774 return and_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
02775 v.sgn, v.nbits, v.ndigits, v.digit);
02776
02777 }
02778
02779
02780 sc_signed
02781 operator&(const sc_signed& u, uint64 v)
02782 {
02783
02784 if ((u.sgn == SC_ZERO) || (v == 0))
02785 return sc_signed();
02786
02787 CONVERT_INT64(v);
02788
02789
02790 return and_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02791 vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
02792
02793 }
02794
02795
02796 sc_signed
02797 operator&(uint64 u, const sc_signed& v)
02798 {
02799
02800 if ((u == 0) || (v.sgn == SC_ZERO))
02801 return sc_signed();
02802
02803 CONVERT_INT64(u);
02804
02805
02806 return and_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
02807 v.sgn, v.nbits, v.ndigits, v.digit);
02808
02809 }
02810
02811
02812 sc_signed
02813 operator&(const sc_signed& u, long v)
02814 {
02815
02816 if ((u.sgn == SC_ZERO) || (v == 0))
02817 return sc_signed();
02818
02819 CONVERT_LONG(v);
02820
02821
02822 return and_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02823 vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
02824
02825 }
02826
02827
02828 sc_signed
02829 operator&(long u, const sc_signed& v)
02830 {
02831
02832 if ((u == 0) || (v.sgn == SC_ZERO))
02833 return sc_signed();
02834
02835 CONVERT_LONG(u);
02836
02837
02838 return and_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
02839 v.sgn, v.nbits, v.ndigits, v.digit);
02840
02841 }
02842
02843
02844 sc_signed
02845 operator&(const sc_unsigned& u, long v)
02846 {
02847
02848 if ((u.sgn == SC_ZERO) || (v == 0))
02849 return sc_signed();
02850
02851 CONVERT_LONG(v);
02852
02853
02854 return and_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02855 vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
02856
02857 }
02858
02859
02860 sc_signed
02861 operator&(long u, const sc_unsigned& v)
02862 {
02863
02864 if ((u == 0) || (v.sgn == SC_ZERO))
02865 return sc_signed();
02866
02867 CONVERT_LONG(u);
02868
02869
02870 return and_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
02871 v.sgn, v.nbits, v.ndigits, v.digit);
02872
02873 }
02874
02875
02876 sc_signed
02877 operator&(const sc_signed& u, unsigned long v)
02878 {
02879
02880 if ((u.sgn == SC_ZERO) || (v == 0))
02881 return sc_signed();
02882
02883 CONVERT_LONG(v);
02884
02885
02886 return and_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02887 vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
02888
02889 }
02890
02891
02892 sc_signed
02893 operator&(unsigned long u, const sc_signed& v)
02894 {
02895
02896 if ((u == 0) || (v.sgn == SC_ZERO))
02897 return sc_signed();
02898
02899 CONVERT_LONG(u);
02900
02901
02902 return and_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
02903 v.sgn, v.nbits, v.ndigits, v.digit);
02904
02905 }
02906
02907
02908
02909
02910
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02921
02922
02923 sc_signed
02924 operator|(const sc_unsigned& u, const sc_signed& v)
02925 {
02926
02927 if (v.sgn == SC_ZERO)
02928 return sc_signed(u);
02929
02930 if (u.sgn == SC_ZERO)
02931 return sc_signed(v);
02932
02933
02934 return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02935 v.sgn, v.nbits, v.ndigits, v.digit);
02936
02937 }
02938
02939
02940 sc_signed
02941 operator|(const sc_signed& u, const sc_unsigned& v)
02942 {
02943
02944 if (v.sgn == SC_ZERO)
02945 return sc_signed(u);
02946
02947 if (u.sgn == SC_ZERO)
02948 return sc_signed(v);
02949
02950
02951 return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02952 v.sgn, v.nbits, v.ndigits, v.digit);
02953
02954 }
02955
02956
02957 sc_signed
02958 operator|(const sc_signed& u, const sc_signed& v)
02959 {
02960
02961 if (v.sgn == SC_ZERO)
02962 return sc_signed(u);
02963
02964 if (u.sgn == SC_ZERO)
02965 return sc_signed(v);
02966
02967
02968 return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02969 v.sgn, v.nbits, v.ndigits, v.digit);
02970
02971 }
02972
02973
02974 sc_signed
02975 operator|(const sc_signed& u, int64 v)
02976 {
02977
02978 if (v == 0)
02979 return sc_signed(u);
02980
02981 CONVERT_INT64(v);
02982
02983 if (u.sgn == SC_ZERO)
02984 return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
02985
02986
02987 return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
02988 vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
02989
02990 }
02991
02992
02993 sc_signed
02994 operator|(int64 u, const sc_signed& v)
02995 {
02996
02997 if (u == 0)
02998 return sc_signed(v);
02999
03000 CONVERT_INT64(u);
03001
03002 if (v.sgn == SC_ZERO)
03003 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
03004
03005
03006 return or_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
03007 v.sgn, v.nbits, v.ndigits, v.digit);
03008
03009 }
03010
03011
03012 sc_signed
03013 operator|(const sc_unsigned& u, int64 v)
03014 {
03015
03016 if (v == 0)
03017 return sc_signed(u);
03018
03019 CONVERT_INT64(v);
03020
03021 if (u.sgn == SC_ZERO)
03022 return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
03023
03024
03025 return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03026 vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
03027
03028 }
03029
03030
03031 sc_signed
03032 operator|(int64 u, const sc_unsigned& v)
03033 {
03034
03035 if (u == 0)
03036 return sc_signed(v);
03037
03038 CONVERT_INT64(u);
03039
03040 if (v.sgn == SC_ZERO)
03041 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
03042
03043
03044 return or_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
03045 v.sgn, v.nbits, v.ndigits, v.digit);
03046
03047 }
03048
03049
03050 sc_signed
03051 operator|(const sc_signed& u, uint64 v)
03052 {
03053
03054 if (v == 0)
03055 return sc_signed(u);
03056
03057 CONVERT_INT64(v);
03058
03059 if (u.sgn == SC_ZERO)
03060 return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
03061
03062
03063 return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03064 vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
03065
03066 }
03067
03068
03069 sc_signed
03070 operator|(uint64 u, const sc_signed& v)
03071 {
03072
03073 if (u == 0)
03074 return sc_signed(v);
03075
03076 CONVERT_INT64(u);
03077
03078 if (v.sgn == SC_ZERO)
03079 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
03080
03081
03082 return or_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
03083 v.sgn, v.nbits, v.ndigits, v.digit);
03084
03085 }
03086
03087
03088 sc_signed
03089 operator|(const sc_signed& u, long v)
03090 {
03091
03092 if (v == 0)
03093 return sc_signed(u);
03094
03095 CONVERT_LONG(v);
03096
03097 if (u.sgn == SC_ZERO)
03098 return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
03099
03100
03101 return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03102 vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
03103
03104 }
03105
03106
03107 sc_signed
03108 operator|(long u, const sc_signed& v)
03109 {
03110
03111 if (u == 0)
03112 return sc_signed(v);
03113
03114 CONVERT_LONG(u);
03115
03116 if (v.sgn == SC_ZERO)
03117 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
03118
03119
03120 return or_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
03121 v.sgn, v.nbits, v.ndigits, v.digit);
03122
03123 }
03124
03125
03126 sc_signed
03127 operator|(const sc_unsigned& u, long v)
03128 {
03129
03130 if (v == 0)
03131 return sc_signed(u);
03132
03133 CONVERT_LONG(v);
03134
03135 if (u.sgn == SC_ZERO)
03136 return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
03137
03138
03139 return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03140 vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
03141
03142 }
03143
03144
03145 sc_signed
03146 operator|(long u, const sc_unsigned& v)
03147 {
03148
03149 if (u == 0)
03150 return sc_signed(v);
03151
03152 CONVERT_LONG(u);
03153
03154 if (v.sgn == SC_ZERO)
03155 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
03156
03157
03158 return or_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
03159 v.sgn, v.nbits, v.ndigits, v.digit);
03160
03161 }
03162
03163
03164 sc_signed
03165 operator|(const sc_signed& u, unsigned long v)
03166 {
03167
03168 if (v == 0)
03169 return sc_signed(u);
03170
03171 CONVERT_LONG(v);
03172
03173 if (u.sgn == SC_ZERO)
03174 return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
03175
03176
03177 return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03178 vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
03179
03180 }
03181
03182
03183 sc_signed
03184 operator|(unsigned long u, const sc_signed& v)
03185 {
03186
03187 if (u == 0)
03188 return sc_signed(v);
03189
03190 CONVERT_LONG(u);
03191
03192 if (v.sgn == SC_ZERO)
03193 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
03194
03195
03196 return or_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
03197 v.sgn, v.nbits, v.ndigits, v.digit);
03198
03199 }
03200
03201
03202
03203
03204
03205
03206
03207
03208
03209
03210
03211
03212
03213
03214
03215
03216
03217
03218 sc_signed
03219 operator^(const sc_unsigned& u, const sc_signed& v)
03220 {
03221
03222 if (v.sgn == SC_ZERO)
03223 return sc_signed(u);
03224
03225 if (u.sgn == SC_ZERO)
03226 return sc_signed(v);
03227
03228
03229 return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03230 v.sgn, v.nbits, v.ndigits, v.digit);
03231
03232 }
03233
03234
03235 sc_signed
03236 operator^(const sc_signed& u, const sc_unsigned& v)
03237 {
03238
03239 if (v.sgn == SC_ZERO)
03240 return sc_signed(u);
03241
03242 if (u.sgn == SC_ZERO)
03243 return sc_signed(v);
03244
03245
03246 return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03247 v.sgn, v.nbits, v.ndigits, v.digit);
03248
03249 }
03250
03251
03252 sc_signed
03253 operator^(const sc_signed& u, const sc_signed& v)
03254 {
03255
03256 if (v.sgn == SC_ZERO)
03257 return sc_signed(u);
03258
03259 if (u.sgn == SC_ZERO)
03260 return sc_signed(v);
03261
03262
03263 return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03264 v.sgn, v.nbits, v.ndigits, v.digit);
03265
03266 }
03267
03268
03269 sc_signed
03270 operator^(const sc_signed& u, int64 v)
03271 {
03272
03273 if (v == 0)
03274 return sc_signed(u);
03275
03276 CONVERT_INT64(v);
03277
03278 if (u.sgn == SC_ZERO)
03279 return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
03280
03281
03282 return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03283 vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
03284
03285 }
03286
03287
03288 sc_signed
03289 operator^(int64 u, const sc_signed& v)
03290 {
03291
03292 if (u == 0)
03293 return sc_signed(v);
03294
03295 CONVERT_INT64(u);
03296
03297 if (v.sgn == SC_ZERO)
03298 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
03299
03300
03301 return xor_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
03302 v.sgn, v.nbits, v.ndigits, v.digit);
03303
03304 }
03305
03306
03307 sc_signed
03308 operator^(const sc_unsigned& u, int64 v)
03309 {
03310
03311 if (v == 0)
03312 return sc_signed(u);
03313
03314 CONVERT_INT64(v);
03315
03316 if (u.sgn == SC_ZERO)
03317 return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
03318
03319
03320 return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03321 vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
03322
03323 }
03324
03325
03326 sc_signed
03327 operator^(int64 u, const sc_unsigned& v)
03328 {
03329
03330 if (u == 0)
03331 return sc_signed(v);
03332
03333 CONVERT_INT64(u);
03334
03335 if (v.sgn == SC_ZERO)
03336 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
03337
03338
03339 return xor_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
03340 v.sgn, v.nbits, v.ndigits, v.digit);
03341
03342 }
03343
03344
03345 sc_signed
03346 operator^(const sc_signed& u, uint64 v)
03347 {
03348
03349 if (v == 0)
03350 return sc_signed(u);
03351
03352 CONVERT_INT64(v);
03353
03354 if (u.sgn == SC_ZERO)
03355 return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);
03356
03357
03358 return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03359 vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);
03360
03361 }
03362
03363 sc_signed
03364 operator^(uint64 u, const sc_signed& v)
03365 {
03366 if (u == 0)
03367 return sc_signed(v);
03368
03369 CONVERT_INT64(u);
03370
03371 if (v.sgn == SC_ZERO)
03372 return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);
03373
03374
03375 return xor_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,
03376 v.sgn, v.nbits, v.ndigits, v.digit);
03377
03378 }
03379
03380
03381 sc_signed
03382 operator^(const sc_signed& u, long v)
03383 {
03384
03385 if (v == 0)
03386 return sc_signed(u);
03387
03388 CONVERT_LONG(v);
03389
03390 if (u.sgn == SC_ZERO)
03391 return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
03392
03393
03394 return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03395 vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
03396
03397 }
03398
03399
03400 sc_signed
03401 operator^(long u, const sc_signed& v)
03402 {
03403
03404 if (u == 0)
03405 return sc_signed(v);
03406
03407 CONVERT_LONG(u);
03408
03409 if (v.sgn == SC_ZERO)
03410 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
03411
03412
03413 return xor_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
03414 v.sgn, v.nbits, v.ndigits, v.digit);
03415
03416 }
03417
03418
03419 sc_signed
03420 operator^(const sc_unsigned& u, long v)
03421 {
03422
03423 if (v == 0)
03424 return sc_signed(u);
03425
03426 CONVERT_LONG(v);
03427
03428 if (u.sgn == SC_ZERO)
03429 return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
03430
03431
03432 return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03433 vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
03434
03435 }
03436
03437
03438 sc_signed
03439 operator^(long u, const sc_unsigned& v)
03440 {
03441
03442 if (u == 0)
03443 return sc_signed(v);
03444
03445 CONVERT_LONG(u);
03446
03447 if (v.sgn == SC_ZERO)
03448 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
03449
03450
03451 return xor_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
03452 v.sgn, v.nbits, v.ndigits, v.digit);
03453
03454 }
03455
03456
03457 sc_signed
03458 operator^(const sc_signed& u, unsigned long v)
03459 {
03460
03461 if (v == 0)
03462 return sc_signed(u);
03463
03464 CONVERT_LONG(v);
03465
03466 if (u.sgn == SC_ZERO)
03467 return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);
03468
03469
03470 return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,
03471 vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);
03472
03473 }
03474
03475 sc_signed
03476 operator^(unsigned long u, const sc_signed& v)
03477 {
03478 if (u == 0)
03479 return sc_signed(v);
03480
03481 CONVERT_LONG(u);
03482
03483 if (v.sgn == SC_ZERO)
03484 return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);
03485
03486
03487 return xor_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,
03488 v.sgn, v.nbits, v.ndigits, v.digit);
03489
03490 }
03491
03492
03493
03494
03495
03496
03497
03498
03499
03500
03501
03502
03503
03504
03505
03506
03507 sc_signed
03508 operator<<(const sc_signed& u, const sc_unsigned& v)
03509 {
03510 if (v.sgn == SC_ZERO)
03511 return sc_signed(u);
03512
03513 return operator<<(u, v.to_ulong());
03514 }
03515
03516
03517
03518
03519
03520
03521
03522
03523
03524 sc_signed
03525 operator>>(const sc_signed& u, const sc_unsigned& v)
03526 {
03527
03528 if (v.sgn == SC_ZERO)
03529 return sc_signed(u);
03530
03531 return operator>>(u, v.to_ulong());
03532
03533 }
03534
03535
03536
03537
03538
03539
03540
03541
03542
03543 sc_signed
03544 operator+(const sc_signed& u)
03545 {
03546 return sc_signed(u);
03547 }
03548
03549 sc_signed
03550 operator-(const sc_signed& u)
03551 {
03552 return sc_signed(u, -u.sgn);
03553 }
03554
03555 sc_signed
03556 operator-(const sc_unsigned& u)
03557 {
03558 return sc_signed(u, -u.sgn);
03559 }
03560
03561
03562
03563
03564
03565
03566 bool
03567 operator==(const sc_signed& u, const sc_signed& v)
03568 {
03569
03570 if (u.sgn != v.sgn)
03571 return false;
03572
03573 if (&u == &v)
03574 return true;
03575
03576 if (vec_skip_and_cmp(u.ndigits, u.digit, v.ndigits, v.digit) != 0)
03577 return false;
03578
03579 return true;
03580
03581 }
03582
03583
03584 bool
03585 operator==(const sc_signed& u, int64 v)
03586 {
03587
03588 CONVERT_INT64(v);
03589
03590 if (u.sgn != vs)
03591 return false;
03592
03593 if (vec_skip_and_cmp(u.ndigits, u.digit, DIGITS_PER_INT64, vd) != 0)
03594 return false;
03595
03596 return true;
03597
03598 }
03599
03600
03601 bool
03602 operator==(int64 u, const sc_signed& v)
03603 {
03604
03605 CONVERT_INT64(u);
03606
03607 if (us != v.sgn)
03608 return false;
03609
03610 if (vec_skip_and_cmp(DIGITS_PER_INT64, ud, v.ndigits, v.digit) != 0)
03611 return false;
03612
03613 return true;
03614
03615 }
03616
03617
03618 bool
03619 operator==(const sc_signed& u, uint64 v)
03620 {
03621
03622 CONVERT_INT64(v);
03623
03624 if (u.sgn != vs)
03625 return false;
03626
03627 if (vec_skip_and_cmp(u.ndigits, u.digit, DIGITS_PER_INT64, vd) != 0)
03628 return false;
03629
03630 return true;
03631
03632 }
03633
03634
03635 bool
03636 operator==(uint64 u, const sc_signed& v)
03637 {
03638
03639 CONVERT_INT64(u);
03640
03641 if (us != v.sgn)
03642 return false;
03643
03644 if (vec_skip_and_cmp(DIGITS_PER_INT64, ud, v.ndigits, v.digit) != 0)
03645 return false;
03646
03647 return true;
03648
03649 }
03650
03651
03652 bool
03653 operator==(const sc_signed& u, long v)
03654 {
03655
03656 CONVERT_LONG(v);
03657
03658 if (u.sgn != vs)
03659 return false;
03660
03661 if (vec_skip_and_cmp(u.ndigits, u.digit, DIGITS_PER_LONG, vd) != 0)
03662 return false;
03663
03664 return true;
03665
03666 }
03667
03668
03669 bool
03670 operator==(long u, const sc_signed& v)
03671 {
03672
03673 CONVERT_LONG(u);
03674
03675 if (us != v.sgn)
03676 return false;
03677
03678 if (vec_skip_and_cmp(DIGITS_PER_LONG, ud, v.ndigits, v.digit) != 0)
03679 return false;
03680
03681 return true;
03682
03683 }
03684
03685
03686 bool
03687 operator==(const sc_signed& u, unsigned long v)
03688 {
03689
03690 CONVERT_LONG(v);
03691
03692 if (u.sgn != vs)
03693 return false;
03694
03695 if (vec_skip_and_cmp(u.ndigits, u.digit, DIGITS_PER_LONG, vd) != 0)
03696 return false;
03697
03698 return true;
03699
03700 }
03701
03702
03703 bool
03704 operator==(unsigned long u, const sc_signed& v)
03705 {
03706
03707 CONVERT_LONG(u);
03708
03709 if (us != v.sgn)
03710 return false;
03711
03712 if (vec_skip_and_cmp(DIGITS_PER_LONG, ud, v.ndigits, v.digit) != 0)
03713 return false;
03714
03715 return true;
03716
03717 }
03718
03719
03720
03721
03722
03723
03724
03725
03726
03727
03728
03729
03730
03731 bool
03732 operator<(const sc_signed& u, const sc_signed& v)
03733 {
03734
03735 if (u.sgn < v.sgn)
03736 return true;
03737
03738 if (u.sgn > v.sgn)
03739 return false;
03740
03741
03742
03743 if (&u == &v)
03744 return false;
03745
03746 if (u.sgn == SC_POS) {
03747
03748 if (vec_skip_and_cmp(u.ndigits, u.digit, v.ndigits, v.digit) < 0)
03749 return true;
03750
03751 }
03752 else if (u.sgn == SC_NEG) {
03753
03754 if (vec_skip_and_cmp(u.ndigits, u.digit, v.ndigits, v.digit) > 0)
03755 return true;
03756
03757 }
03758
03759 return false;
03760
03761 }
03762
03763
03764 bool
03765 operator<(const sc_signed& u, int64 v)
03766 {
03767
03768 CONVERT_INT64(v);
03769
03770 if (u.sgn < vs)
03771 return true;
03772
03773 if (u.sgn > vs)
03774 return false;
03775
03776
03777
03778 if (vs == SC_POS) {
03779
03780 if (vec_skip_and_cmp(u.ndigits, u.digit, DIGITS_PER_INT64, vd) < 0)
03781 return true;
03782
03783 }
03784 else if (vs == SC_NEG) {
03785
03786 if (vec_skip_and_cmp(u.ndigits, u.digit, DIGITS_PER_INT64, vd) > 0)
03787 return true;
03788
03789 }
03790
03791 return false;
03792
03793 }
03794
03795
03796 bool
03797 operator<(int64 u, const sc_signed& v)
03798 {
03799
03800 CONVERT_INT64(u);
03801
03802 if (us < v.sgn)
03803 return true;
03804
03805 if (us > v.sgn)
03806 return false;
03807
03808
03809
03810 if (us == SC_POS) {
03811
03812 if (vec_skip_and_cmp(DIGITS_PER_INT64, ud, v.ndigits, v.digit) < 0)
03813 return true;
03814
03815 }
03816 else if (us == SC_NEG) {
03817
03818 if (vec_skip_and_cmp(DIGITS_PER_INT64, ud, v.ndigits, v.digit) > 0)
03819 return true;
03820
03821 }
03822
03823 return false;
03824
03825 }
03826
03827
03828 bool
03829 operator<(const sc_signed& u, uint64 v)
03830 {
03831
03832 CONVERT_INT64(v);
03833
03834 if (u.sgn < vs)
03835 return true;
03836
03837 if (u.sgn > vs)
03838 return false;
03839
03840
03841
03842 if (vs == SC_POS) {
03843
03844 if (vec_skip_and_cmp(u.ndigits, u.digit, DIGITS_PER_INT64, vd) < 0)
03845 return true;
03846
03847 }
03848
03849 return false;
03850
03851 }
03852
03853
03854 bool
03855 operator<(uint64 u, const sc_signed& v)
03856 {
03857
03858 CONVERT_INT64(u);
03859
03860 if (us < v.sgn)
03861 return true;
03862
03863 if (us > v.sgn)
03864 return false;
03865
03866
03867
03868 if (us == SC_POS) {
03869
03870 if (vec_skip_and_cmp(DIGITS_PER_INT64, ud, v.ndigits, v.digit) < 0)
03871 return true;
03872
03873 }
03874
03875 return false;
03876
03877 }
03878
03879
03880 bool
03881 operator<(const sc_signed& u, long v)
03882 {
03883
03884 CONVERT_LONG(v);
03885
03886 if (u.sgn < vs)
03887 return true;
03888
03889 if (u.sgn > vs)
03890 return false;
03891
03892
03893
03894 if (vs == SC_POS) {
03895
03896 if (vec_skip_and_cmp(u.ndigits, u.digit, DIGITS_PER_LONG, vd) < 0)
03897 return true;
03898
03899 }
03900 else if (vs == SC_NEG) {
03901
03902 if (vec_skip_and_cmp(u.ndigits, u.digit, DIGITS_PER_LONG, vd) > 0)
03903 return true;
03904
03905 }
03906
03907 return false;
03908
03909 }
03910
03911
03912 bool
03913 operator<(long u, const sc_signed& v)
03914 {
03915 CONVERT_LONG(u);
03916
03917 if (us < v.sgn)
03918 return true;
03919
03920 if (us > v.sgn)
03921 return false;
03922
03923
03924
03925 if (us == SC_POS) {
03926
03927 if (vec_skip_and_cmp(DIGITS_PER_LONG, ud, v.ndigits, v.digit) < 0)
03928 return true;
03929
03930 }
03931 else if (us == SC_NEG) {
03932
03933 if (vec_skip_and_cmp(DIGITS_PER_LONG, ud, v.ndigits, v.digit) > 0)
03934 return true;
03935
03936 }
03937
03938 return false;
03939 }
03940
03941
03942 bool
03943 operator<(const sc_signed& u, unsigned long v)
03944 {
03945 CONVERT_LONG(v);
03946
03947 if (u.sgn < vs)
03948 return true;
03949
03950 if (u.sgn > vs)
03951 return false;
03952
03953
03954
03955 if (vs == SC_POS) {
03956
03957 if (vec_skip_and_cmp(u.ndigits, u.digit, DIGITS_PER_LONG, vd) < 0)
03958 return true;
03959
03960 }
03961
03962 return false;
03963 }
03964
03965
03966 bool
03967 operator<(unsigned long u, const sc_signed& v)
03968 {
03969 CONVERT_LONG(u);
03970
03971 if (us < v.sgn)
03972 return true;
03973
03974 if (us > v.sgn)
03975 return false;
03976
03977
03978
03979 if (us == SC_POS) {
03980
03981 if (vec_skip_and_cmp(DIGITS_PER_LONG, ud, v.ndigits, v.digit) < 0)
03982 return true;
03983
03984 }
03985
03986 return false;
03987 }
03988
03989
03990
03991
03992
03993
03994
03995
03996
03997
03998
03999
04000
04001
04002
04003
04004
04005
04006
04007
04008
04009
04010
04011
04012
04013
04014
04015 bool
04016 sc_signed::iszero() const
04017 {
04018 if (sgn == SC_ZERO)
04019 return true;
04020 else if (sgn != SC_NOSIGN)
04021 return false;
04022 else
04023 return check_for_zero(ndigits, digit);
04024 }
04025
04026
04027 bool
04028 sc_signed::sign() const
04029 {
04030 if (sgn == SC_NEG)
04031 return 1;
04032 else if (sgn != SC_NOSIGN)
04033 return 0;
04034 else
04035 return ((digit[ndigits - 1] & one_and_zeros(bit_ord(nbits - 1))) != 0);
04036 }
04037
04038
04039
04040
04041
04042
04043
04044
04045
04046
04047 #define CLASS_TYPE sc_signed
04048 #define CLASS_TYPE_STR "sc_signed"
04049
04050 #define ADD_HELPER add_signed_friend
04051 #define SUB_HELPER sub_signed_friend
04052 #define MUL_HELPER mul_signed_friend
04053 #define DIV_HELPER div_signed_friend
04054 #define MOD_HELPER mod_signed_friend
04055 #define AND_HELPER and_signed_friend
04056 #define OR_HELPER or_signed_friend
04057 #define XOR_HELPER xor_signed_friend
04058
04059 #include "sc_nbfriends.inc"
04060
04061 #undef SC_UNSIGNED
04062 #define SC_SIGNED
04063 #define IF_SC_SIGNED 1 // 1 = sc_signed
04064 #define CLASS_TYPE_SUBREF sc_signed_subref_r
04065 #define OTHER_CLASS_TYPE sc_unsigned
04066 #define OTHER_CLASS_TYPE_SUBREF sc_unsigned_subref_r
04067
04068 #define MUL_ON_HELPER mul_on_help_signed
04069 #define DIV_ON_HELPER div_on_help_signed
04070 #define MOD_ON_HELPER mod_on_help_signed
04071
04072 #include "sc_nbcommon.inc"
04073
04074 #undef MOD_ON_HELPER
04075 #undef DIV_ON_HELPER
04076 #undef MUL_ON_HELPER
04077
04078 #undef OTHER_CLASS_TYPE_SUBREF
04079 #undef OTHER_CLASS_TYPE
04080 #undef CLASS_TYPE_SUBREF
04081 #undef IF_SC_SIGNED
04082 #undef SC_SIGNED
04083
04084 #undef XOR_HELPER
04085 #undef OR_HELPER
04086 #undef AND_HELPER
04087 #undef MOD_HELPER
04088 #undef DIV_HELPER
04089 #undef MUL_HELPER
04090 #undef SUB_HELPER
04091 #undef ADD_HELPER
04092
04093 #undef CLASS_TYPE
04094 #undef CLASS_TYPE_STR
04095
04096 #include "sc_signed_bitref.inc"
04097 #include "sc_signed_subref.inc"
04098
04099 #undef CONVERT_LONG
04100 #undef CONVERT_LONG_2
04101 #undef CONVERT_INT64
04102 #undef CONVERT_INT64_2
04103
04104 }
04105
04106
04107