sc_nbcommon.inc

来自「system C源码 一种替代verilog的语言」· INC 代码 · 共 3,013 行 · 第 1/4 页

INC
3,013
字号
  if (sgn == SC_ZERO) // case 1    vec_zero(ndigits, digit);  else     // cases 2-4    MUL_ON_HELPER(sgn,  nbits, ndigits, digit,                  v.nbits, v.ndigits, v.digit);  return *this;}const CLASS_TYPE&CLASS_TYPE::operator*=(int64 v){  // u = *this  sgn = mul_signs(sgn, get_sign(v));  if (sgn == SC_ZERO) // case 1    vec_zero(ndigits, digit);  else {  // cases 2-4    CONVERT_INT64_2(v);    MUL_ON_HELPER(sgn,  nbits, ndigits, digit,                  BITS_PER_UINT64, DIGITS_PER_UINT64, vd);  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator*=(uint64 v){  // u = *this  sgn = mul_signs(sgn, get_sign(v));  if (sgn == SC_ZERO) // case 1    vec_zero(ndigits, digit);  else { // cases 2-4    CONVERT_INT64_2(v);    MUL_ON_HELPER(sgn,  nbits, ndigits, digit,                  BITS_PER_UINT64, DIGITS_PER_UINT64, vd);  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator*=(long v){  // u = *this  sgn = mul_signs(sgn, get_sign(v));  if (sgn == SC_ZERO) // case 1    vec_zero(ndigits, digit);  else {   // cases 2-4    CONVERT_LONG_2(v);    MUL_ON_HELPER(sgn,  nbits, ndigits, digit,                  BITS_PER_ULONG, DIGITS_PER_ULONG, vd);  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator*=(unsigned long v){  // u = *this  sgn = mul_signs(sgn, get_sign(v));  if (sgn == SC_ZERO) // case 1    vec_zero(ndigits, digit);  else {  // cases 2-4    CONVERT_LONG_2(v);    MUL_ON_HELPER(sgn,  nbits, ndigits, digit,                  BITS_PER_ULONG, DIGITS_PER_ULONG, vd);  }  return *this;}// ----------------------------------------------------------------------------//  SECTION: DIVISION operators: /, /=// ----------------------------------------------------------------------------// Cases to consider when finding the quotient q = floor(u/v):// Note that u = q * v + r for r < q.// 1. 0 / 0 or u / 0 => error// 2. 0 / v => 0 = 0 * v + 0// 3. u / v && u = v => u = 1 * u + 0  - u or v can be 1 or -1// 4. u / v && u < v => u = 0 * v + u  - u can be 1 or -1// 5. u / v && u > v => u = q * v + r  - v can be 1 or -1const CLASS_TYPE&CLASS_TYPE::operator/=(const CLASS_TYPE& v){  sgn = mul_signs(sgn, v.sgn);  if (sgn == SC_ZERO) {    div_by_zero(v.sgn); // case 1    vec_zero(ndigits, digit);  // case 2  }  else  // other cases    DIV_ON_HELPER(sgn, nbits, ndigits, digit,                  v.nbits, v.ndigits, v.digit);  return *this;}const CLASS_TYPE&CLASS_TYPE::operator/=(const OTHER_CLASS_TYPE& v){  sgn = mul_signs(sgn, v.sgn);  if (sgn == SC_ZERO) {    div_by_zero(v.sgn); // case 1    vec_zero(ndigits, digit);  // case 2  }  else  // other cases    DIV_ON_HELPER(sgn, nbits, ndigits, digit,                  v.nbits, v.ndigits, v.digit);  return *this;}const CLASS_TYPE&CLASS_TYPE::operator/=(int64 v){  // u = *this  sgn = mul_signs(sgn, get_sign(v));  if (sgn == SC_ZERO) {    div_by_zero(v);  // case 1    vec_zero(ndigits, digit); // case 2  }  else {    CONVERT_INT64_2(v);    // other cases    DIV_ON_HELPER(sgn, nbits, ndigits, digit,                  BITS_PER_UINT64, DIGITS_PER_UINT64, vd);  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator/=(uint64 v){  // u = *this  sgn = mul_signs(sgn, get_sign(v));  if (sgn == SC_ZERO) {    div_by_zero(v);  // case 1    vec_zero(ndigits, digit);  // case 2  }  else {    CONVERT_INT64_2(v);    // other cases    DIV_ON_HELPER(sgn, nbits, ndigits, digit,                  BITS_PER_UINT64, DIGITS_PER_UINT64, vd);  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator/=(long v){  // u = *this  sgn = mul_signs(sgn, get_sign(v));  if (sgn == SC_ZERO) {    div_by_zero(v);  // case 1    vec_zero(ndigits, digit); // case 2  }  else {    CONVERT_LONG_2(v);    // other cases    DIV_ON_HELPER(sgn,  nbits, ndigits, digit,                  BITS_PER_ULONG, DIGITS_PER_ULONG, vd);  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator/=(unsigned long v){  // u = *this  sgn = mul_signs(sgn, get_sign(v));  if (sgn == SC_ZERO) {    div_by_zero(v);  // case 1    vec_zero(ndigits, digit);  // case 2  }  else {        CONVERT_LONG_2(v);    // other cases    DIV_ON_HELPER(sgn,  nbits, ndigits, digit,                  BITS_PER_ULONG, DIGITS_PER_ULONG, vd);  }  return *this;}// ----------------------------------------------------------------------------//  SECTION: MOD operators: %, %=.// ----------------------------------------------------------------------------// Cases to consider when finding the remainder r = u % v:// Note that u = q * v + r for r < q.// 1. 0 % 0 or u % 0 => error// 2. 0 % v => 0 = 0 * v + 0// 3. u % v && u = v => u = 1 * u + 0  - u or v can be 1 or -1// 4. u % v && u < v => u = 0 * v + u  - u can be 1 or -1// 5. u % v && u > v => u = q * v + r  - v can be 1 or -1const CLASS_TYPE&CLASS_TYPE::operator%=(const CLASS_TYPE& v){  if ((sgn == SC_ZERO) || (v.sgn == SC_ZERO)) {    div_by_zero(v.sgn);  // case 1    vec_zero(ndigits, digit);  // case 2  }  else // other cases    MOD_ON_HELPER(sgn, nbits, ndigits, digit,                  v.nbits, v.ndigits, v.digit);  return *this;}const CLASS_TYPE&CLASS_TYPE::operator%=(const OTHER_CLASS_TYPE& v){  if ((sgn == SC_ZERO) || (v.sgn == SC_ZERO)) {    div_by_zero(v.sgn);  // case 1    vec_zero(ndigits, digit);  // case 2  }  else  // other cases    MOD_ON_HELPER(sgn, nbits, ndigits, digit,                  v.nbits, v.ndigits, v.digit);  return *this;}const CLASS_TYPE&CLASS_TYPE::operator%=(int64 v){  small_type vs = get_sign(v);  if ((sgn == SC_ZERO) || (vs == SC_ZERO)) {    div_by_zero(v);  // case 1    vec_zero(ndigits, digit);  // case 2  }  else {        CONVERT_INT64_2(v);    // other cases    MOD_ON_HELPER(sgn, nbits, ndigits, digit,                  BITS_PER_UINT64, DIGITS_PER_UINT64, vd);  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator%=(uint64 v){  if ((sgn == SC_ZERO) || (v == 0)) {    div_by_zero(v);  // case 1    vec_zero(ndigits, digit);  // case 2  }  else {        CONVERT_INT64_2(v);    // other cases    MOD_ON_HELPER(sgn, nbits, ndigits, digit,                  BITS_PER_UINT64, DIGITS_PER_UINT64, vd);  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator%=(long v){  small_type vs = get_sign(v);  if ((sgn == SC_ZERO) || (vs == SC_ZERO)) {    div_by_zero(v);  // case 1    vec_zero(ndigits, digit);  // case 2  }  else {        CONVERT_LONG_2(v);    // other cases    MOD_ON_HELPER(sgn, nbits, ndigits, digit,                  BITS_PER_ULONG, DIGITS_PER_ULONG, vd);  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator%=(unsigned long v){  if ((sgn == SC_ZERO) || (v == 0)) {    div_by_zero(v);  // case 1    vec_zero(ndigits, digit);  // case 2  }  else {        CONVERT_LONG_2(v);    // other cases    MOD_ON_HELPER(sgn, nbits, ndigits, digit,                  BITS_PER_ULONG, DIGITS_PER_ULONG, vd);  }  return *this;}// ----------------------------------------------------------------------------//  SECTION: Bitwise AND operators: &, &=// ----------------------------------------------------------------------------// Cases to consider when computing u & v:// 1. u & 0 = 0 & v = 0// 2. u & v => sgn = +// 3. (-u) & (-v) => sgn = -// 4. u & (-v) => sgn = +// 5. (-u) & v => sgn = +const CLASS_TYPE&CLASS_TYPE::operator&=(const CLASS_TYPE& v){  // u = *this  if ((sgn == SC_ZERO) || (v.sgn == SC_ZERO)) // case 1    makezero();  else  {  // other cases    and_on_help(sgn, nbits, ndigits, digit,                v.sgn, v.nbits, v.ndigits, v.digit);    convert_2C_to_SM();  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator&=(const OTHER_CLASS_TYPE& v){  // u = *this  if ((sgn == SC_ZERO) || (v.sgn == SC_ZERO)) // case 1    makezero();  else {  // other cases        and_on_help(sgn, nbits, ndigits, digit,                v.sgn, v.nbits, v.ndigits, v.digit);    convert_2C_to_SM();  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator&=(int64 v){  // u = *this  if ((sgn == SC_ZERO) || (v == 0)) // case 1    makezero();  else {    // other cases    CONVERT_INT64(v);    and_on_help(sgn, nbits, ndigits, digit,                vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);    convert_2C_to_SM();  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator&=(uint64 v){  // u = *this  if ((sgn == SC_ZERO) || (v == 0))  // case 1    makezero();  else {  // other cases    CONVERT_INT64(v);    and_on_help(sgn, nbits, ndigits, digit,                vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);    convert_2C_to_SM();      }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator&=(long v){  // u = *this  if ((sgn == SC_ZERO) || (v == 0))  // case 1    makezero();  else {      // other cases    CONVERT_LONG(v);    and_on_help(sgn, nbits, ndigits, digit,                vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);    convert_2C_to_SM();  }  return *this;}const CLASS_TYPE&CLASS_TYPE::operator&=(unsigned long v){  // u = *this  if ((sgn == SC_ZERO) || (v == 0))  // case 1    makezero();  else {  // other cases    CONVERT_LONG(v);    and_on_help(sgn, nbits, ndigits, digit,                vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);    convert_2C_to_SM();  }  return *this;}// ----------------------------------------------------------------------------//  SECTION: Bitwise OR operators: |, |=// ----------------------------------------------------------------------------// Cases to consider when computing u | v:// 1. u | 0 = u// 2. 0 | v = v// 3. u | v => sgn = +// 4. (-u) | (-v) => sgn = -// 5. u | (-v) => sgn = -// 6. (-u) | v => sgn = -const CLASS_TYPE&CLASS_TYPE::operator|=(const CLASS_TYPE& v){  if (v.sgn == SC_ZERO)  // case 1    return *this;  if (sgn == SC_ZERO)  // case 2    return (*this = v);  // other cases  or_on_help(sgn, nbits, ndigits, digit,             v.sgn, v.nbits, v.ndigits, v.digit);  convert_2C_to_SM();  return *this;}const CLASS_TYPE&CLASS_TYPE::operator|=(const OTHER_CLASS_TYPE& v){  if (v.sgn == SC_ZERO)  // case 1    return *this;  if (sgn == SC_ZERO)  // case 2    return (*this = v);  // other cases  or_on_help(sgn, nbits, ndigits, digit,             v.sgn, v.nbits, v.ndigits, v.digit);  convert_2C_to_SM();  return *this;}const CLASS_TYPE&CLASS_TYPE::operator|=(int64 v){  if (v == 0)  // case 1    return *this;  if (sgn == SC_ZERO)  // case 2    return (*this = v);  // other cases  CONVERT_INT64(v);  or_on_help(sgn, nbits, ndigits, digit,             vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);  convert_2C_to_SM();  return *this;}const CLASS_TYPE&CLASS_TYPE::operator|=(uint64 v){  if (v == 0)  // case 1    return *this;  if (sgn == SC_ZERO)  // case 2    return (*this = v);  // other cases  CONVERT_INT64(v);  or_on_help(sgn, nbits, ndigits, digit,             vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);  convert_2C_to_SM();  return *this;}const CLASS_TYPE&CLASS_TYPE::operator|=(long v){  if (v == 0)  // case 1    return *this;  if (sgn == SC_ZERO)  // case 2    return (*this = v);  // other cases  CONVERT_LONG(v);  or_on_help(sgn, nbits, ndigits, digit,             vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);  convert_2C_to_SM();  return *this;}const CLASS_TYPE&CLASS_TYPE::operator|=(unsigned long v){  if (v == 0)  // case 1    return *this;  if (sgn == SC_ZERO)  // case 2    return (*this = v);  // other cases  CONVERT_LONG(v);  or_on_help(sgn, nbits, ndigits, digit,             vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);  convert_2C_to_SM();  return *this;}// ----------------------------------------------------------------------------//  SECTION: Bitwise XOR operators: ^, ^=// ----------------------------------------------------------------------------// Cases to consider when computing u ^ v:// Note that  u ^ v = (~u & v) | (u & ~v).// 1. u ^ 0 = u// 2. 0 ^ v = v// 3. u ^ v => sgn = +// 4. (-u) ^ (-v) => sgn = -// 5. u ^ (-v) => sgn = -// 6. (-u) ^ v => sgn = +const CLASS_TYPE&CLASS_TYPE::operator^=(const CLASS_TYPE& v){  // u = *this  if (v.sgn == SC_ZERO)  // case 1    return *this;  if (sgn == SC_ZERO)  // case 2    return (*this = v);  // other cases  xor_on_help(sgn, nbits, ndigits, digit,              v.sgn, v.nbits, v.ndigits, v.digit);  convert_2C_to_SM();  return *this;}const CLASS_TYPE&CLASS_TYPE::operator^=(const OTHER_CLASS_TYPE& v){  // u = *this  if (v.sgn == SC_ZERO)  // case 1    return *this;  if (sgn == SC_ZERO)  // case 2    return (*this = v);  // other cases  xor_on_help(sgn, nbits, ndigits, digit,              v.sgn, v.nbits, v.ndigits, v.digit);  convert_2C_to_SM();  return *this;}const CLASS_TYPE&CLASS_TYPE::operator^=(int64 v){  if (v == 0)  // case 1    return *this;  if (sgn == SC_ZERO)  // case 2    return (*this = v);  // other cases  CONVERT_INT64(v);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?