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

📄 sc_nbexterns.cpp

📁 system C源码 一种替代verilog的语言
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    if (cmp_res == 0) {       us = SC_ZERO;      vec_zero(old_und, ud);      return;    }        // else if u > v - case 5        sc_digit vd0 = (*vd);        if ((vnd == 1) && (vd0 == 1)) {      us = SC_ZERO;      vec_zero(old_und, ud);      return;    }        // One extra digit for d is allocated to simplify vec_div_*().    int nd = sc_max(und, vnd) + 1;    #ifdef SC_MAX_NBITS    sc_digit d[MAX_NDIGITS + 1];#else    sc_digit *d = new sc_digit[nd];#endif        vec_zero(nd, d);        if ((vnd == 1) && (und == 1))      d[0] = (*ud) % vd0;        if ((vnd == 1) && (vd0 < HALF_DIGIT_RADIX))      d[0] = vec_rem_small(und, ud, vd0);        else      vec_rem_large(und, ud, vnd, vd, d);        us = check_for_zero(us, nd - 1, d);        if (us == SC_ZERO)      vec_zero(old_und, ud);    else      COPY_DIGITS(us, unb, old_und, ud, sc_min(unb, vnd), nd - 1, d);    #ifndef SC_MAX_NBITS    delete [] d;#endif      }  #undef COPY_DIGITS  }voidmod_on_help_unsigned(small_type &us,                      int unb, int und,                      sc_digit *ud,                      int /* vnb */, int vnd,                     const sc_digit *vd){#define COPY_DIGITS copy_digits_unsigned  { // Body of mod_on_help    int old_und = und;        und = vec_skip_leading_zeros(und, ud);    vnd = vec_skip_leading_zeros(vnd, vd);        int cmp_res = vec_cmp(und, ud, vnd, vd);        // u < v => u % v = u - case 4    if (cmp_res < 0)       return;        // u = v => u % v = 0 - case 3    if (cmp_res == 0) {       us = SC_ZERO;      vec_zero(old_und, ud);      return;    }        // else if u > v - case 5        sc_digit vd0 = (*vd);        if ((vnd == 1) && (vd0 == 1)) {      us = SC_ZERO;      vec_zero(old_und, ud);      return;    }        // One extra digit for d is allocated to simplify vec_div_*().    int nd = sc_max(und, vnd) + 1;    #ifdef SC_MAX_NBITS    sc_digit d[MAX_NDIGITS + 1];#else    sc_digit *d = new sc_digit[nd];#endif        vec_zero(nd, d);        if ((vnd == 1) && (und == 1))      d[0] = (*ud) % vd0;        if ((vnd == 1) && (vd0 < HALF_DIGIT_RADIX))      d[0] = vec_rem_small(und, ud, vd0);        else      vec_rem_large(und, ud, vnd, vd, d);        us = check_for_zero(us, nd - 1, d);        if (us == SC_ZERO)      vec_zero(old_und, ud);    else      COPY_DIGITS(us, unb, old_und, ud, sc_min(unb, vnd), nd - 1, d);    #ifndef SC_MAX_NBITS    delete [] d;#endif      }  #undef COPY_DIGITS  }// ----------------------------------------------------------------------------//  SECTION: External functions for AND operators.// ----------------------------------------------------------------------------// Handles the cases 2-5 and returns the result in u.voidand_on_help(small_type us,             int /* unb */, int und,             sc_digit *ud,             small_type vs,            int /* vnb */, int vnd,            const sc_digit *vd){  register sc_digit *x = ud;  register const sc_digit *y = vd;  int xnd = und;  int ynd = vnd;  // Truncate y.  if (xnd < ynd)    ynd = xnd;  const sc_digit *xend = (x + xnd);  const sc_digit *yend = (y + ynd);  // x is longer than y.  small_type s = mul_signs(us, vs);  if (s > 0) {    if (us > 0) { // case 2      while (y < yend)        (*x++) &= (*y++);      while (x < xend)        (*x++) = 0;    }    else {  // case 3      register sc_digit xcarry = 1;      register sc_digit ycarry = 1;      while (y < yend) {        xcarry += (~(*x) & DIGIT_MASK);        ycarry += (~(*y++) & DIGIT_MASK);        (*x++) = (xcarry & ycarry) & DIGIT_MASK;        xcarry >>= BITS_PER_DIGIT;        ycarry >>= BITS_PER_DIGIT;      }      while (x < xend) {        xcarry += (~(*x) & DIGIT_MASK);        ycarry += DIGIT_MASK;        (*x++) = (xcarry & ycarry) & DIGIT_MASK;        xcarry >>= BITS_PER_DIGIT;        ycarry >>= BITS_PER_DIGIT;      }    }  }  else {    if (us > 0) { // case 4      register sc_digit ycarry = 1;      while (y < yend) {        ycarry += (~(*y++) & DIGIT_MASK);        (*x++) &= ycarry & DIGIT_MASK;        ycarry >>= BITS_PER_DIGIT;      }      while (x < xend) {        ycarry += DIGIT_MASK;        (*x++) &= ycarry & DIGIT_MASK;        ycarry >>= BITS_PER_DIGIT;      }    }    else {  // case 5      register sc_digit xcarry = 1;      while (y < yend) {        xcarry += (~(*x) & DIGIT_MASK);        (*x++) = (xcarry & (*y++)) & DIGIT_MASK;        xcarry >>= BITS_PER_DIGIT;      }      while (x < xend)        (*x++) = 0;    }  }}// ----------------------------------------------------------------------------//  SECTION: External functions for OR operators.// ----------------------------------------------------------------------------// Handles the cases 3-5 and returns the result in u.voidor_on_help(small_type us,            int /* unb */, int und,            sc_digit *ud,            small_type vs,           int /* vnb */, int vnd,           const sc_digit *vd){    register sc_digit *x = ud;  register const sc_digit *y = vd;  int xnd = und;  int ynd = vnd;  if (xnd < ynd)    ynd = xnd;  const sc_digit *xend = (x + xnd);  const sc_digit *yend = (y + ynd);  // x is longer than y.  small_type s = mul_signs(us, vs);  if (s > 0) {    if (us > 0) { // case 3      while (y < yend)        (*x++) |= (*y++);      // No change for the rest of x.    }    else {  // case 4      register sc_digit xcarry = 1;      register sc_digit ycarry = 1;      while (y < yend) {        xcarry += (~(*x) & DIGIT_MASK);        ycarry += (~(*y++) & DIGIT_MASK);        (*x++) = (xcarry | ycarry) & DIGIT_MASK;        xcarry >>= BITS_PER_DIGIT;        ycarry >>= BITS_PER_DIGIT;      }      while (x < xend) {        xcarry += (~(*x) & DIGIT_MASK);        ycarry += DIGIT_MASK;        (*x++) = (xcarry | ycarry) & DIGIT_MASK;        xcarry >>= BITS_PER_DIGIT;        ycarry >>= BITS_PER_DIGIT;      }    }  }  else {    if (us > 0) { // case 5      register sc_digit ycarry = 1;      while (y < yend) {        ycarry += (~(*y++) & DIGIT_MASK);        (*x) = ((*x) | ycarry) & DIGIT_MASK;        x++;        ycarry >>= BITS_PER_DIGIT;      }      while (x < xend) {        ycarry += DIGIT_MASK;        (*x) = ((*x) | ycarry) & DIGIT_MASK;        x++;        ycarry >>= BITS_PER_DIGIT;      }    }    else {  // case 6      register sc_digit xcarry = 1;      while (y < yend) {        xcarry += (~(*x) & DIGIT_MASK);        (*x++) = (xcarry | (*y++)) & DIGIT_MASK;        xcarry >>= BITS_PER_DIGIT;      }      while (x < xend) {        xcarry += (~(*x) & DIGIT_MASK);        (*x++) = xcarry & DIGIT_MASK;        xcarry >>= BITS_PER_DIGIT;      }    }  }}// ----------------------------------------------------------------------------//  SECTION: External functions for XOR operators.// ----------------------------------------------------------------------------// Handles the cases 3-5 and returns the result in u.voidxor_on_help(small_type us,             int /* unb */, int und,             sc_digit *ud,             small_type vs,            int /* vnb */, int vnd,            const sc_digit *vd){    register sc_digit *x = ud;  register const sc_digit *y = vd;  int xnd = und;  int ynd = vnd;  if (xnd < ynd)    ynd = xnd;  const sc_digit *xend = (x + xnd);  const sc_digit *yend = (y + ynd);  // x is longer than y.  small_type s = mul_signs(us, vs);  if (s > 0) {    if (us > 0) { // case 3      while (y < yend) {        (*x) = ((*x) ^ (*y)) & DIGIT_MASK;        x++;        y++;      }      // No change for the rest of x.    }    else {  // case 4      register sc_digit xcarry = 1;      register sc_digit ycarry = 1;      while (y < yend) {        xcarry += (~(*x) & DIGIT_MASK);        ycarry += (~(*y++) & DIGIT_MASK);        (*x++) = (xcarry ^ ycarry) & DIGIT_MASK;        xcarry >>= BITS_PER_DIGIT;        ycarry >>= BITS_PER_DIGIT;      }      while (x < xend) {        xcarry += (~(*x) & DIGIT_MASK);        ycarry += DIGIT_MASK;        (*x++) = (xcarry ^ ycarry) & DIGIT_MASK;        xcarry >>= BITS_PER_DIGIT;        ycarry >>= BITS_PER_DIGIT;      }    }  }  else {    if (us > 0) { // case 5      register sc_digit ycarry = 1;      while (y < yend) {        ycarry += (~(*y++) & DIGIT_MASK);        (*x) = ((*x) ^ ycarry) & DIGIT_MASK;        x++;        ycarry >>= BITS_PER_DIGIT;      }      while (x < xend) {        ycarry += DIGIT_MASK;        (*x) = ((*x) ^ ycarry) & DIGIT_MASK;        x++;        ycarry >>= BITS_PER_DIGIT;      }    }    else {  // case 6      register sc_digit xcarry = 1;      while (y < yend) {        xcarry += (~(*x) & DIGIT_MASK);        (*x++) = (xcarry ^ (*y++)) & DIGIT_MASK;        xcarry >>= BITS_PER_DIGIT;      }      while (x < xend) {        xcarry += (~(*x) & DIGIT_MASK);        (*x++) = xcarry & DIGIT_MASK;        xcarry >>= BITS_PER_DIGIT;      }    }  }}} // namespace sc_dt// End of file

⌨️ 快捷键说明

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