diff --git a/backends/cxxrtl/runtime/cxxrtl/cxxrtl.h b/backends/cxxrtl/runtime/cxxrtl/cxxrtl.h index c1cc81e44a2..d61c2312ee2 100644 --- a/backends/cxxrtl/runtime/cxxrtl/cxxrtl.h +++ b/backends/cxxrtl/runtime/cxxrtl/cxxrtl.h @@ -585,78 +585,6 @@ struct value : public expr_base> { return result; } - // parallel to BigUnsigned::divideWithRemainder; quotient is stored in q, - // *this is left with the remainder. See that function for commentary describing - // how/why this works. - void divideWithRemainder(const value &b, value &q) { - assert(this != &q); - - if (this == &b || &q == &b) { - value tmpB(b); - divideWithRemainder(tmpB, q); - return; - } - - q = value {0u}; - - size_t blen = b.chunks_used(); - if (blen == 0) { - return; - } - - size_t len = chunks_used(); - if (len < blen) { - return; - } - - size_t i, j, k; - size_t i2; - chunk_t temp; - bool borrowIn, borrowOut; - - size_t origLen = len; - len++; - chunk::type blk[len]; - std::copy(data, data + origLen, blk); - blk[origLen] = 0; - chunk::type subtractBuf[len]; - std::fill(subtractBuf, subtractBuf + len, 0); - - size_t qlen = origLen - blen + 1; - - i = qlen; - while (i > 0) { - i--; - i2 = chunk::bits; - while (i2 > 0) { - i2--; - for (j = 0, k = i, borrowIn = false; j <= blen; j++, k++) { - temp = blk[k] - getShiftedBlock(b, j, i2); - borrowOut = (temp > blk[k]); - if (borrowIn) { - borrowOut |= (temp == 0); - temp--; - } - subtractBuf[k] = temp; - borrowIn = borrowOut; - } - for (; k < origLen && borrowIn; k++) { - borrowIn = (blk[k] == 0); - subtractBuf[k] = blk[k] - 1; - } - if (!borrowIn) { - q.data[i] |= (chunk::type(1) << i2); - while (k > i) { - k--; - blk[k] = subtractBuf[k]; - } - } - } - } - - std::copy(blk, blk + origLen, data); - } - static chunk::type getShiftedBlock(const value &num, size_t x, size_t y) { chunk::type part1 = (x == 0 || y == 0) ? 0 : (num.data[x - 1] >> (chunk::bits - y)); chunk::type part2 = (x == num.chunks) ? 0 : (num.data[x] << y); @@ -849,9 +777,9 @@ std::ostream &operator<<(std::ostream &os, const value_formatted &vf) if (val.is_zero()) buf += '0'; while (!val.is_zero()) { - value quotient; - val.divideWithRemainder(value{10u}, quotient); - buf += '0' + val.template trunc<(Bits > 4 ? 4 : Bits)>().val().template get(); + value quotient, remainder; + std::tie(quotient, remainder) = val.template divmod_uu(value{10u}); + buf += '0' + remainder.template trunc<(Bits > 4 ? 4 : Bits)>().val().template get(); val = quotient; } if (negative || vf.plus)