Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix addOne/subOne for SVInt #729

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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