cxxrtl.h: Fix incorrect CarryOut in alu()

This commit is contained in:
Andy Knowles 2020-08-12 21:04:34 +02:00 committed by GitHub
parent 1227c3681b
commit 5829d16fcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 8 deletions

View File

@ -450,18 +450,13 @@ struct value : public expr_base<value<Bits>> {
std::pair<value<Bits>, bool /*CarryOut*/> alu(const value<Bits> &other) const {
value<Bits> result;
bool carry = CarryIn;
// Handle full chunks first
for (size_t n = 0; n < result.chunks - 1; n++) {
for (size_t n = 0; n < result.chunks; n++) {
result.data[n] = data[n] + (Invert ? ~other.data[n] : other.data[n]) + carry;
if (result.chunks - 1 == n)
result.data[result.chunks - 1] &= result.msb_mask;
carry = (result.data[n] < data[n]) ||
(result.data[n] == data[n] && carry);
}
// Handle last chunk (mask before updating carry)
constexpr size_t last = result.chunks - 1;
result.data[last] = data[last] + (Invert ? ~other.data[last] : other.data[last]) + carry;
result.data[last] &= result.msb_mask;
carry = (result.data[last] < data[last]) ||
(result.data[last] == data[last] && carry);
return {result, carry};
}