From 5829d16fcd9a7645ea22eee3a489499780acc79c Mon Sep 17 00:00:00 2001 From: Andy Knowles Date: Wed, 12 Aug 2020 21:04:34 +0200 Subject: [PATCH] cxxrtl.h: Fix incorrect CarryOut in alu() --- backends/cxxrtl/cxxrtl.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/backends/cxxrtl/cxxrtl.h b/backends/cxxrtl/cxxrtl.h index dfdb49929..e3c96d422 100644 --- a/backends/cxxrtl/cxxrtl.h +++ b/backends/cxxrtl/cxxrtl.h @@ -450,18 +450,13 @@ struct value : public expr_base> { std::pair, bool /*CarryOut*/> alu(const value &other) const { value 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}; } -- 2.30.2