From 89cebd0079d740f518e0b82cfa2a66596c5010d0 Mon Sep 17 00:00:00 2001 From: adream307 Date: Sun, 12 Mar 2023 23:32:02 +0800 Subject: [PATCH] fix addOne/subOne for SVInt Signed-off-by: adream307 --- source/numeric/SVIntHelpers.h | 4 ++++ tests/unittests/NumericTests.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/source/numeric/SVIntHelpers.h b/source/numeric/SVIntHelpers.h index f2923d990..e922efeb0 100644 --- a/source/numeric/SVIntHelpers.h +++ b/source/numeric/SVIntHelpers.h @@ -217,6 +217,8 @@ static bool addOne(uint64_t* dst, uint64_t* src, uint32_t len, uint64_t value) { if (!carry) break; + + value = 0; } return carry; } @@ -231,6 +233,8 @@ static bool subOne(uint64_t* dst, uint64_t* src, uint32_t len, uint64_t value) { if (!borrow) break; + + value = 0; } return borrow; } diff --git a/tests/unittests/NumericTests.cpp b/tests/unittests/NumericTests.cpp index 470cf6b1d..43e930b00 100644 --- a/tests/unittests/NumericTests.cpp +++ b/tests/unittests/NumericTests.cpp @@ -342,6 +342,14 @@ TEST_CASE("Arithmetic") { CHECK(v8 == 2); CHECK_THAT(-SVInt(logic_t::z), exactlyEquals(SVInt(logic_t::x))); + + SVInt v9 = "193'hFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF"_si; + v9++; + CHECK(v9 == "193'h1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000"_si); + + SVInt v10 = "193'h1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000"_si; + v10--; + CHECK(v10 == "193'hFFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF_FFFF"_si); } void testDiv(const SVInt& a, const SVInt& b, const SVInt& c) {