Skip to content

Commit

Permalink
CI fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolgodvorov Egor Victorovich committed Apr 2, 2024
1 parent b737561 commit d2e3402
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
16 changes: 8 additions & 8 deletions include/slang/numeric/SVInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ class SLANG_EXPORT SVInt : SVIntStorage {
static SVInt createFillX(bitwidth_t bitWidth, bool isSigned);
static SVInt createFillZ(bitwidth_t bitWidth, bool isSigned);

// Returns maximum value of signed or unsugned int
SLANG_EXPORT static SVInt getMinValue(const SVInt& Int);
SLANG_EXPORT static SVInt getMinValue(bitwidth_t bitwidth, bool isSigned);

// Returns minimum value of signed or unsugned int
SLANG_EXPORT static SVInt getMaxValue(const SVInt& Int);
SLANG_EXPORT static SVInt getMaxValue(bitwidth_t bitwidth, bool isSigned);

[[nodiscard]] size_t hash() const;
void writeTo(SmallVectorBase<char>& buffer, LiteralBase base,
bitwidth_t abbreviateThresholdBits = DefaultStringAbbreviationThresholdBits) const;
Expand Down Expand Up @@ -684,14 +692,6 @@ inline SLANG_EXPORT uint32_t clog2(const SVInt& v) {
return v.getBitWidth() - (v - SVInt::One).countLeadingZeros();
}

// Returns maximum value of signed or unsugned int
SVInt getMinValue(const SVInt& Int);
SVInt getMinValue(bitwidth_t bitwidth, bool isSigned);

// Returns minimum value of signed or unsugned int
SVInt getMaxValue(const SVInt& Int);
SVInt getMaxValue(bitwidth_t bitwidth, bool isSigned);

inline namespace literals {

inline SVInt operator""_si(const char* str, size_t size) {
Expand Down
8 changes: 4 additions & 4 deletions source/numeric/SVInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2433,11 +2433,11 @@ bool caseZWildcardEqual(const SVInt& lhs, const SVInt& rhs) {
return true;
}

SVInt getMinValue(const SVInt& Int) {
SVInt SVInt::getMinValue(const SVInt& Int) {
return getMinValue(Int.getBitWidth(), Int.isSigned());
}

SVInt getMinValue(bitwidth_t bitwidth, bool isSigned) {
SVInt SVInt::getMinValue(bitwidth_t bitwidth, bool isSigned) {
if (!isSigned)
return SVInt(bitwidth, 0, isSigned);

Expand All @@ -2448,11 +2448,11 @@ SVInt getMinValue(bitwidth_t bitwidth, bool isSigned) {
return out;
}

SVInt getMaxValue(const SVInt& Int) {
SVInt SVInt::getMaxValue(const SVInt& Int) {
return getMaxValue(Int.getBitWidth(), Int.isSigned());
}

SVInt getMaxValue(bitwidth_t bitwidth, bool isSigned) {
SVInt SVInt::getMaxValue(bitwidth_t bitwidth, bool isSigned) {
SVInt out(bitwidth, 0, isSigned);
out.setAllOnes();
if (isSigned)
Expand Down
15 changes: 11 additions & 4 deletions tests/unittests/util/NumericTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,10 +830,17 @@ value = value >> 1
compilation.addSyntaxTree(tree);
compilation.getAllDiagnostics();
}

TEST_CASE("Get minimum and maximum value") {
CHECK(slang::getMaxValue(32, 0) == 4294967295);
CHECK(slang::getMinValue(32, 0) == 0);
CHECK(slang::SVInt::getMaxValue(32, 0) == 4294967295);
CHECK(slang::SVInt::getMinValue(32, 0) == 0);

CHECK(slang::SVInt::getMaxValue(32, 1) == 2147483647);
CHECK(slang::SVInt::getMinValue(32, 1) == -2147483648);

CHECK(slang::SVInt::getMaxValue(SVInt(4, 0, 0)) == 15);
CHECK(slang::SVInt::getMinValue(SVInt(4, 0, 0)) == 0);

CHECK(slang::getMaxValue(32, 1) == 2147483647);
CHECK(slang::getMinValue(32, 1) == -2147483648);
CHECK(slang::SVInt::getMaxValue(SVInt(4, 0, 1)) == 7);
CHECK(slang::SVInt::getMinValue(SVInt(4, 0, 1)) == -8);
}

0 comments on commit d2e3402

Please sign in to comment.