Skip to content

Commit

Permalink
fix addOne/subOne for SVInt
Browse files Browse the repository at this point in the history
Signed-off-by: adream307 <[email protected]>
  • Loading branch information
adream307 committed Mar 12, 2023
1 parent d9c8300 commit 89cebd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/numeric/SVIntHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/unittests/NumericTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 89cebd0

Please sign in to comment.