2023-06-27 20:51:23 -05:00
|
|
|
#include "fuzztest/fuzztest.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include "backends/cxxrtl/cxxrtl.h"
|
|
|
|
#include "libs/bigint/BigUnsigned.hh"
|
|
|
|
|
|
|
|
using namespace cxxrtl_yosys;
|
|
|
|
|
2023-06-27 20:51:24 -05:00
|
|
|
void Formats128BitIntegers(chunk_t x0, chunk_t x1, chunk_t x2, chunk_t x3, bool signed_)
|
2023-06-27 20:51:24 -05:00
|
|
|
{
|
|
|
|
// Compare output to BigUnsigned.
|
2023-06-27 20:51:23 -05:00
|
|
|
value<128> v;
|
2023-06-27 20:51:24 -05:00
|
|
|
v = v.blit<127, 64>(value<64>{x1, x0});
|
|
|
|
v = v.blit<63, 0>(value<64>{x3, x2});
|
2023-06-27 20:51:23 -05:00
|
|
|
|
|
|
|
std::ostringstream oss;
|
2023-06-27 20:51:24 -05:00
|
|
|
oss << value_formatted<128>(v, false, false, ' ', 0, 10, signed_, false, false);
|
2023-06-27 20:51:23 -05:00
|
|
|
auto actual = oss.str();
|
|
|
|
|
2023-06-27 20:51:24 -05:00
|
|
|
BigUnsigned u;
|
2023-06-27 20:51:24 -05:00
|
|
|
bool negative = signed_ && v.is_neg();
|
2023-06-27 20:51:24 -05:00
|
|
|
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;
|
2023-06-27 20:51:24 -05:00
|
|
|
|
2023-06-27 20:51:24 -05:00
|
|
|
if (u.isZero()) {
|
|
|
|
expected = "0";
|
|
|
|
} else {
|
|
|
|
while (!u.isZero()) {
|
|
|
|
expected += '0' + (u % 10).toInt();
|
|
|
|
u /= 10;
|
|
|
|
}
|
2023-06-27 20:51:24 -05:00
|
|
|
if (negative)
|
2023-06-27 20:51:24 -05:00
|
|
|
expected += '-';
|
|
|
|
std::reverse(expected.begin(), expected.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
}
|
2023-06-27 20:51:24 -05:00
|
|
|
FUZZ_TEST(CxxrtlDivisionFuzz, Formats128BitIntegers);
|