⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sc_unsigned.cpp

📁 system C源码 一种替代verilog的语言
💻 CPP
📖 第 1 页 / 共 4 页
字号:
operator==(const sc_unsigned& u, const sc_unsigned& v){  if (&u == &v)    return true;  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        v.sgn, v.nbits, v.ndigits, v.digit) != 0)    return false;  return true;}booloperator==(const sc_unsigned& u, const sc_signed& v){  if (v.sgn == SC_NEG)    return false;  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        v.sgn, v.nbits, v.ndigits, v.digit, 0, 1) != 0)    return false;  return true;}booloperator==(const sc_signed& u, const sc_unsigned& v){  if (u.sgn == SC_NEG)    return false;  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        v.sgn, v.nbits, v.ndigits, v.digit, 1, 0) != 0)    return false;  return true;}booloperator==(const sc_unsigned& u, int64 v){  if (v < 0)    return false;  CONVERT_INT64(v);  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd) != 0)    return false;  return true;}booloperator==(int64 u, const sc_unsigned& v){  if (u < 0)    return false;  CONVERT_INT64(u);  if (compare_unsigned(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,                       v.sgn, v.nbits, v.ndigits, v.digit) != 0)    return false;  return true;}booloperator==(const sc_unsigned& u, uint64 v){  CONVERT_INT64(v);  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd) != 0)    return false;  return true;}booloperator==(uint64 u, const sc_unsigned& v){  CONVERT_INT64(u);  if (compare_unsigned(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,                       v.sgn, v.nbits, v.ndigits, v.digit) != 0)    return false;  return true;}booloperator==(const sc_unsigned& u, long v){  if (v < 0)    return false;  CONVERT_LONG(v);  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd) != 0)    return false;  return true;}booloperator==(long u, const sc_unsigned& v){  if (u < 0)    return false;  CONVERT_LONG(u);  if (compare_unsigned(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,                       v.sgn, v.nbits, v.ndigits, v.digit) != 0)    return false;  return true;}booloperator==(const sc_unsigned& u, unsigned long v){  CONVERT_LONG(v);  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd) != 0)    return false;  return true;}booloperator==(unsigned long u, const sc_unsigned& v){  CONVERT_LONG(u);  if (compare_unsigned(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,                       v.sgn, v.nbits, v.ndigits, v.digit) != 0)    return false;  return true;}// ----------------------------------------------------------------------------//  SECTION: NOT_EQUAL operator: !=// ----------------------------------------------------------------------------booloperator!=(const sc_unsigned& u, const sc_signed& v){  return (! operator==(u, v));}booloperator!=(const sc_signed& u, const sc_unsigned& v){  return (! operator==(u, v));}// The rest of the operators in this section are included from sc_nbcommon.cpp.// ----------------------------------------------------------------------------//  SECTION: LESS THAN operator: <// ----------------------------------------------------------------------------booloperator<(const sc_unsigned& u, const sc_unsigned& v){  if (&u == &v)    return false;  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        v.sgn, v.nbits, v.ndigits, v.digit) < 0)    return true;  return false;}booloperator<(const sc_unsigned& u, const sc_signed& v){  if (v.sgn == SC_NEG)    return false;  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        v.sgn, v.nbits, v.ndigits, v.digit, 0, 1) < 0)    return true;  return false;}booloperator<(const sc_signed& u, const sc_unsigned& v){  if (u.sgn == SC_NEG)    return true;  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        v.sgn, v.nbits, v.ndigits, v.digit, 1, 0) < 0)    return true;  return false;}booloperator<(const sc_unsigned& u, int64 v){  if (v < 0)    return false;  CONVERT_INT64(v);  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd) < 0)    return true;  return false;}booloperator<(int64 u, const sc_unsigned& v){  if (u < 0)    return true;  CONVERT_INT64(u);  if (compare_unsigned(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,                       v.sgn, v.nbits, v.ndigits, v.digit) < 0)    return true;  return false;}booloperator<(const sc_unsigned& u, uint64 v){  CONVERT_INT64(v);  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd) < 0)    return true;  return false;}booloperator<(uint64 u, const sc_unsigned& v){  CONVERT_INT64(u);  if (compare_unsigned(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,                       v.sgn, v.nbits, v.ndigits, v.digit) < 0)    return true;  return false;    }booloperator<(const sc_unsigned& u, long v){  if (v < 0)    return false;  CONVERT_LONG(v);  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd) < 0)    return true;  return false;}booloperator<(long u, const sc_unsigned& v){  if (u < 0)    return true;  CONVERT_LONG(u);  if (compare_unsigned(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,                       v.sgn, v.nbits, v.ndigits, v.digit) < 0)    return true;  return false;}booloperator<(const sc_unsigned& u, unsigned long v){  CONVERT_LONG(v);  if (compare_unsigned(u.sgn, u.nbits, u.ndigits, u.digit,                        vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd) < 0)    return true;  return false;}booloperator<(unsigned long u, const sc_unsigned& v){  CONVERT_LONG(u);  if (compare_unsigned(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,                       v.sgn, v.nbits, v.ndigits, v.digit) < 0)    return true;  return false;    }// ----------------------------------------------------------------------------//  SECTION: LESS THAN or EQUAL operator: <=// ----------------------------------------------------------------------------booloperator<=(const sc_unsigned& u, const sc_signed& v){  return (operator<(u, v) || operator==(u, v));}booloperator<=(const sc_signed& u, const sc_unsigned& v){  return (operator<(u, v) || operator==(u, v));}// The rest of the operators in this section are included from sc_nbcommon.cpp.// ----------------------------------------------------------------------------//  SECTION: GREATER THAN operator: >// ----------------------------------------------------------------------------booloperator>(const sc_unsigned& u, const sc_signed& v){  return (! (operator<=(u, v)));}booloperator>(const sc_signed& u, const sc_unsigned& v){  return (! (operator<=(u, v)));}// The rest of the operators in this section are included from sc_nbcommon.cpp.// ----------------------------------------------------------------------------//  SECTION: GREATER THAN or EQUAL operator: >=// ----------------------------------------------------------------------------booloperator>=(const sc_unsigned& u, const sc_signed& v){  return (! (operator<(u, v)));}booloperator>=(const sc_signed& u, const sc_unsigned& v){  return (! (operator<(u, v)));}// The rest of the operators in this section are included from sc_nbcommon.cpp.// ----------------------------------------------------------------------------//  SECTION: Friends // ----------------------------------------------------------------------------// Compare u and v as unsigned and return r//  r = 0 if u == v//  r < 0 if u < v//  r > 0 if u > vintcompare_unsigned(small_type us,                  int unb, int und, const sc_digit *ud,                  small_type vs,                  int vnb, int vnd, const sc_digit *vd,                 small_type if_u_signed,                  small_type if_v_signed){  if (us == vs) {    if (us == SC_ZERO)      return 0;    else {      int cmp_res = vec_skip_and_cmp(und, ud, vnd, vd);      if (us == SC_POS)        return cmp_res;      else        return -cmp_res;    }  }  else {    if (us == SC_ZERO)      return -vs;    if (vs == SC_ZERO)      return us;    int cmp_res;    int nd = (us == SC_NEG ? und : vnd);#ifdef SC_MAX_NBITS    sc_digit d[MAX_NDIGITS];#else    sc_digit *d = new sc_digit[nd];#endif    if (us == SC_NEG) {      vec_copy(nd, d, ud);      vec_complement(nd, d);      trim(if_u_signed, unb, nd, d);      cmp_res = vec_skip_and_cmp(nd, d, vnd, vd);    }    else {      vec_copy(nd, d, vd);      vec_complement(nd, d);      trim(if_v_signed, vnb, nd, d);      cmp_res = vec_skip_and_cmp(und, ud, nd, d);    }#ifndef SC_MAX_NBITS    delete [] d;#endif    return cmp_res;  }}// ----------------------------------------------------------------------------//  SECTION: Public members - Other utils.// ----------------------------------------------------------------------------bool sc_unsigned::iszero() const{  if (sgn == SC_ZERO)    return true;  else if (sgn == SC_NEG) {    // A negative unsigned number can be zero, e.g., -16 in 4 bits, so    // check that.#ifdef SC_MAX_NBITS    sc_digit d[MAX_NDIGITS];#else    sc_digit *d = new sc_digit[ndigits];#endif    vec_copy(ndigits, d, digit);    vec_complement(ndigits, d);    trim_unsigned(nbits, ndigits, d);    bool res = check_for_zero(ndigits, d);#ifndef SC_MAX_NBITS    delete [] d;#endif    return res;      }  else    return false;}// The rest of the utils in this section are included from sc_nbcommon.cpp.// ----------------------------------------------------------------------------//  SECTION: Private members.// ----------------------------------------------------------------------------// The private members in this section are included from// sc_nbcommon.cpp.#define CLASS_TYPE sc_unsigned#define CLASS_TYPE_STR "sc_unsigned"#define ADD_HELPER add_unsigned_friend#define SUB_HELPER sub_unsigned_friend#define MUL_HELPER mul_unsigned_friend#define DIV_HELPER div_unsigned_friend#define MOD_HELPER mod_unsigned_friend#define AND_HELPER and_unsigned_friend#define  OR_HELPER  or_unsigned_friend#define XOR_HELPER xor_unsigned_friend #include "sc_nbfriends.inc"#undef  SC_SIGNED#define SC_UNSIGNED#define IF_SC_SIGNED              0  // 0 = sc_unsigned#define CLASS_TYPE_SUBREF         sc_unsigned_subref_r#define OTHER_CLASS_TYPE          sc_signed#define OTHER_CLASS_TYPE_SUBREF   sc_signed_subref_r#define MUL_ON_HELPER mul_on_help_unsigned#define DIV_ON_HELPER div_on_help_unsigned#define MOD_ON_HELPER mod_on_help_unsigned#include "sc_nbcommon.inc"#undef MOD_ON_HELPER#undef DIV_ON_HELPER#undef MUL_ON_HELPER#undef OTHER_CLASS_TYPE_SUBREF#undef OTHER_CLASS_TYPE#undef CLASS_TYPE_SUBREF#undef IF_SC_SIGNED#undef SC_UNSIGNED#undef XOR_HELPER#undef  OR_HELPER#undef AND_HELPER#undef MOD_HELPER#undef DIV_HELPER#undef MUL_HELPER#undef SUB_HELPER#undef ADD_HELPER#undef CLASS_TYPE#undef CLASS_TYPE_STR#include "sc_unsigned_bitref.inc"#include "sc_unsigned_subref.inc"#undef CONVERT_LONG#undef CONVERT_LONG_2#undef CONVERT_INT64#undef CONVERT_INT64_2} // namespace sc_dt// End of file.

⌨️ 快捷键说明

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