sc_signed.cpp

来自「基于4个mips核的noc设计」· C++ 代码 · 共 3,016 行 · 第 1/5 页

CPP
3,016
字号
sc_signedoperator&(uint64 u, const sc_signed& v){  if ((u == 0) || (v.sgn == SC_ZERO)) // case 1    return sc_signed();  CONVERT_INT64(u);  // other cases  return and_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,                           v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator&(const sc_signed& u, long v){  if ((u.sgn == SC_ZERO) || (v == 0)) // case 1    return sc_signed();  CONVERT_LONG(v);  // other cases  return and_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                           vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);}sc_signedoperator&(long u, const sc_signed& v){  if ((u == 0) || (v.sgn == SC_ZERO)) // case 1    return sc_signed();  CONVERT_LONG(u);  // other cases  return and_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,                           v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator&(const sc_unsigned& u, long v){  if ((u.sgn == SC_ZERO) || (v == 0)) // case 1    return sc_signed();  CONVERT_LONG(v);  // other cases  return and_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                           vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);}sc_signedoperator&(long u, const sc_unsigned& v){  if ((u == 0) || (v.sgn == SC_ZERO)) // case 1    return sc_signed();  CONVERT_LONG(u);  // other cases  return and_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,                           v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator&(const sc_signed& u, unsigned long v){  if ((u.sgn == SC_ZERO) || (v == 0)) // case 1    return sc_signed();  CONVERT_LONG(v);  // other cases  return and_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                           vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);}sc_signedoperator&(unsigned long u, const sc_signed& v){  if ((u == 0) || (v.sgn == SC_ZERO)) // case 1    return sc_signed();  CONVERT_LONG(u);  // other cases  return and_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,                           v.sgn, v.nbits, v.ndigits, v.digit);}// The rest of the operators in this section are included from// sc_nbcommon.cpp.// ----------------------------------------------------------------------------//  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 = -sc_signedoperator|(const sc_unsigned& u, const sc_signed& v){  if (v.sgn == SC_ZERO)  // case 1    return sc_signed(u);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(v);  // other cases  return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                          v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator|(const sc_signed& u, const sc_unsigned& v){  if (v.sgn == SC_ZERO)  // case 1    return sc_signed(u);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(v);  // other cases  return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                          v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator|(const sc_signed& u, const sc_signed& v){  if (v.sgn == SC_ZERO)  // case 1    return sc_signed(u);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(v);  // other cases  return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                          v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator|(const sc_signed& u, int64 v){  if (v == 0)  // case 1    return sc_signed(u);  CONVERT_INT64(v);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);  // other cases  return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                          vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);}sc_signedoperator|(int64 u, const sc_signed& v){  if (u == 0)    return sc_signed(v);  CONVERT_INT64(u);  if (v.sgn == SC_ZERO)    return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);  // other cases  return or_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,                          v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator|(const sc_unsigned& u, int64 v){  if (v == 0)  // case 1    return sc_signed(u);  CONVERT_INT64(v);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);  // other cases  return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                          vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);}sc_signedoperator|(int64 u, const sc_unsigned& v){  if (u == 0)    return sc_signed(v);  CONVERT_INT64(u);  if (v.sgn == SC_ZERO)    return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);  // other cases  return or_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,                          v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator|(const sc_signed& u, uint64 v){  if (v == 0)  // case 1    return sc_signed(u);  CONVERT_INT64(v);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);  // other cases  return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                          vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);}sc_signedoperator|(uint64 u, const sc_signed& v){  if (u == 0)    return sc_signed(v);  CONVERT_INT64(u);  if (v.sgn == SC_ZERO)    return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);  // other cases  return or_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,                          v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator|(const sc_signed& u, long v){  if (v == 0)  // case 1    return sc_signed(u);  CONVERT_LONG(v);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);  // other cases  return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                          vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);}sc_signedoperator|(long u, const sc_signed& v){  if (u == 0)    return sc_signed(v);  CONVERT_LONG(u);  if (v.sgn == SC_ZERO)    return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);  // other cases  return or_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,                          v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator|(const sc_unsigned& u, long v){  if (v == 0)  // case 1    return sc_signed(u);  CONVERT_LONG(v);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);  // other cases  return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                          vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);}sc_signedoperator|(long u, const sc_unsigned& v){  if (u == 0)    return sc_signed(v);  CONVERT_LONG(u);  if (v.sgn == SC_ZERO)    return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);  // other cases  return or_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,                          v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator|(const sc_signed& u, unsigned long v){  if (v == 0)  // case 1    return sc_signed(u);  CONVERT_LONG(v);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);  // other cases  return or_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                          vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd);}sc_signedoperator|(unsigned long u, const sc_signed& v){  if (u == 0)    return sc_signed(v);  CONVERT_LONG(u);  if (v.sgn == SC_ZERO)    return sc_signed(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud, false);  // other cases  return or_signed_friend(us, BITS_PER_ULONG, DIGITS_PER_ULONG, ud,                          v.sgn, v.nbits, v.ndigits, v.digit);}// The rest of the operators in this section are included from// sc_nbcommon.cpp.// ----------------------------------------------------------------------------//  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 = +sc_signedoperator^(const sc_unsigned& u, const sc_signed& v){  if (v.sgn == SC_ZERO)  // case 1    return sc_signed(u);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(v);  // other cases  return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                           v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator^(const sc_signed& u, const sc_unsigned& v){  if (v.sgn == SC_ZERO)  // case 1    return sc_signed(u);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(v);  // other cases  return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                           v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator^(const sc_signed& u, const sc_signed& v){  if (v.sgn == SC_ZERO)  // case 1    return sc_signed(u);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(v);  // other cases  return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                           v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator^(const sc_signed& u, int64 v){  if (v == 0)  // case 1    return sc_signed(u);  CONVERT_INT64(v);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);  // other cases  return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                           vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);}sc_signedoperator^(int64 u, const sc_signed& v){  if (u == 0)    return sc_signed(v);  CONVERT_INT64(u);  if (v.sgn == SC_ZERO)    return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);  // other cases  return xor_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,                           v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator^(const sc_unsigned& u, int64 v){  if (v == 0)  // case 1    return sc_signed(u);  CONVERT_INT64(v);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);  // other cases  return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                           vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);}sc_signedoperator^(int64 u, const sc_unsigned& v){  if (u == 0)    return sc_signed(v);  CONVERT_INT64(u);  if (v.sgn == SC_ZERO)    return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);  // other cases  return xor_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,                           v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator^(const sc_signed& u, uint64 v){  if (v == 0)  // case 1    return sc_signed(u);  CONVERT_INT64(v);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd, false);  // other cases  return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                           vs, BITS_PER_UINT64, DIGITS_PER_UINT64, vd);}sc_signedoperator^(uint64 u, const sc_signed& v){  if (u == 0)    return sc_signed(v);  CONVERT_INT64(u);  if (v.sgn == SC_ZERO)    return sc_signed(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud, false);  // other cases  return xor_signed_friend(us, BITS_PER_UINT64, DIGITS_PER_UINT64, ud,                           v.sgn, v.nbits, v.ndigits, v.digit);}sc_signedoperator^(const sc_signed& u, long v){  if (v == 0)  // case 1    return sc_signed(u);  CONVERT_LONG(v);  if (u.sgn == SC_ZERO)  // case 2    return sc_signed(vs, BITS_PER_ULONG, DIGITS_PER_ULONG, vd, false);  // other cases  return xor_signed_friend(u.sgn, u.nbits, u.ndigits, u.digit,                       

⌨️ 快捷键说明

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