mirror of https://github.com/YosysHQ/yosys.git
fmt: merge fuzzers since we don't rely on BigInteger logic
This is per fmt's (effective) use, as it turns out, so we're not losing any fidelity in the comparison.
This commit is contained in:
parent
3571bf2c2d
commit
a1de898fcc
|
@ -17,7 +17,6 @@ add_executable(
|
|||
x_test
|
||||
x_test.cc
|
||||
../../../libs/bigint/BigUnsigned.cc
|
||||
../../../libs/bigint/BigInteger.cc
|
||||
)
|
||||
|
||||
link_fuzztest(x_test)
|
||||
|
|
|
@ -4,11 +4,10 @@
|
|||
#include <sstream>
|
||||
#include "backends/cxxrtl/cxxrtl.h"
|
||||
#include "libs/bigint/BigUnsigned.hh"
|
||||
#include "libs/bigint/BigInteger.hh"
|
||||
|
||||
using namespace cxxrtl_yosys;
|
||||
|
||||
void Formats128BitUnsignedIntegers(chunk_t x0, chunk_t x1, chunk_t x2, chunk_t x3)
|
||||
void Formats128BitIntegers(chunk_t x0, chunk_t x1, chunk_t x2, chunk_t x3, bool signed_)
|
||||
{
|
||||
// Compare output to BigUnsigned.
|
||||
value<128> v;
|
||||
|
@ -16,64 +15,30 @@ void Formats128BitUnsignedIntegers(chunk_t x0, chunk_t x1, chunk_t x2, chunk_t x
|
|||
v = v.blit<63, 0>(value<64>{x3, x2});
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << value_formatted<128>(v, false, false, ' ', 0, 10, false, false, false);
|
||||
oss << value_formatted<128>(v, false, false, ' ', 0, 10, signed_, false, false);
|
||||
auto actual = oss.str();
|
||||
|
||||
BigUnsigned u;
|
||||
u.bitShiftLeft(v.slice<127, 64>().val().get<uint64_t>(), 64);
|
||||
u.bitOr(u, v.slice<63, 0>().val().get<uint64_t>());
|
||||
|
||||
std::string expected;
|
||||
|
||||
if (u.isZero()) {
|
||||
expected = "0";
|
||||
} else {
|
||||
while (!u.isZero()) {
|
||||
expected += '0' + (u % 10).toInt();
|
||||
u /= 10;
|
||||
}
|
||||
std::reverse(expected.begin(), expected.end());
|
||||
}
|
||||
|
||||
EXPECT_EQ(actual, expected);
|
||||
}
|
||||
FUZZ_TEST(CxxrtlDivisionFuzz, Formats128BitUnsignedIntegers);
|
||||
|
||||
|
||||
void Formats128BitSignedIntegers(chunk_t x0, chunk_t x1, chunk_t x2, chunk_t x3) {
|
||||
// Compare output to BigInteger.
|
||||
value<128> v;
|
||||
v = v.blit<127, 64>(value<64>{x1, x0});
|
||||
v = v.blit<63, 0>(value<64>{x3, x2});
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << value_formatted<128>(v, false, false, ' ', 0, 10, true, false, false);
|
||||
auto actual = oss.str();
|
||||
|
||||
BigUnsigned u;
|
||||
bool negative = v.is_neg();
|
||||
bool negative = signed_ && v.is_neg();
|
||||
if (negative)
|
||||
v = v.neg();
|
||||
u.bitShiftLeft(v.slice<127, 64>().val().get<uint64_t>(), 64);
|
||||
u.bitOr(u, v.slice<63, 0>().val().get<uint64_t>());
|
||||
|
||||
std::string expected;
|
||||
|
||||
if (u.isZero()) {
|
||||
expected = "0";
|
||||
} else {
|
||||
// Note that we never actually do division of negative numbers: our division
|
||||
// routines are flooring, not truncating, so dividing by 10 repeatedly won't
|
||||
// necessarily ever get to zero.
|
||||
while (!u.isZero()) {
|
||||
expected += '0' + (u % 10).toInt();
|
||||
u /= 10;
|
||||
}
|
||||
if (negative) {
|
||||
if (negative)
|
||||
expected += '-';
|
||||
}
|
||||
std::reverse(expected.begin(), expected.end());
|
||||
}
|
||||
|
||||
EXPECT_EQ(actual, expected);
|
||||
}
|
||||
FUZZ_TEST(CxxrtlDivisionFuzz, Formats128BitSignedIntegers);
|
||||
FUZZ_TEST(CxxrtlDivisionFuzz, Formats128BitIntegers);
|
||||
|
|
Loading…
Reference in New Issue