From d2e34020bc4460f8f1ec4b2159979bb99378470f Mon Sep 17 00:00:00 2001 From: Dolgodvorov Egor Victorovich Date: Tue, 2 Apr 2024 13:30:08 +0300 Subject: [PATCH] CI fix --- include/slang/numeric/SVInt.h | 16 ++++++++-------- source/numeric/SVInt.cpp | 8 ++++---- tests/unittests/util/NumericTests.cpp | 15 +++++++++++---- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/include/slang/numeric/SVInt.h b/include/slang/numeric/SVInt.h index 986e8f970..f177656df 100644 --- a/include/slang/numeric/SVInt.h +++ b/include/slang/numeric/SVInt.h @@ -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& buffer, LiteralBase base, bitwidth_t abbreviateThresholdBits = DefaultStringAbbreviationThresholdBits) const; @@ -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) { diff --git a/source/numeric/SVInt.cpp b/source/numeric/SVInt.cpp index 9da39074c..676252981 100644 --- a/source/numeric/SVInt.cpp +++ b/source/numeric/SVInt.cpp @@ -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); @@ -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) diff --git a/tests/unittests/util/NumericTests.cpp b/tests/unittests/util/NumericTests.cpp index 26fd78438..d4be83a67 100644 --- a/tests/unittests/util/NumericTests.cpp +++ b/tests/unittests/util/NumericTests.cpp @@ -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); }