Skip to content

Commit

Permalink
unifying the type interface to posit regression tests across exhausti…
Browse files Browse the repository at this point in the history
…ve and random
  • Loading branch information
Ravenwater committed Feb 18, 2024
1 parent 401fec5 commit 60fe91c
Show file tree
Hide file tree
Showing 23 changed files with 462 additions and 489 deletions.
4 changes: 2 additions & 2 deletions include/universal/verification/posit_test_suite_randoms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ namespace sw { namespace universal {
// generate a random set of operands to test the binary operators for a posit configuration
// Basic design is that we generate nrOfRandom posit values and store them in an operand array.
// We will then execute the binary operator nrOfRandom combinations.
template<size_t nbits, size_t es>
template<typename TestType>
int VerifyBinaryOperatorThroughRandoms(bool reportTestCases, int opcode, uint32_t nrOfRandoms) {
std::string operation_string;
switch (opcode) {
Expand Down Expand Up @@ -247,7 +247,7 @@ namespace sw { namespace universal {
bool firstDivideByZeroCall = true;
int nrOfFailedTests = 0;
for (unsigned i = 1; i < nrOfRandoms; i++) {
posit<nbits, es> testa, testb, testc, testref;
TestType testa, testb, testc, testref;
testa.setbits(distr(eng));
testb.setbits(distr(eng));
double da = double(testa);
Expand Down
34 changes: 17 additions & 17 deletions static/posit/arithmetic/addition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#define POSIT_THROW_ARITHMETIC_EXCEPTION 0
// third: enable tracing
// when you define ALGORITHM_VERBOSE_OUTPUT executing an ADD the code will print intermediate results
#define ALGORITHM_VERBOSE_OUTPUT
#define ALGORITHM_TRACE_ADD
//#define ALGORITHM_VERBOSE_OUTPUT
//#define ALGORITHM_TRACE_ADD
#include <universal/number/posit/posit.hpp>
#include <universal/verification/posit_test_suite.hpp>
#include <universal/verification/posit_test_suite_randoms.hpp>
Expand Down Expand Up @@ -75,7 +75,7 @@ try {
nrOfFailedTestCases += ReportTestResult(VerifyAddition<posit<3, 2>>(reportTestCases), "posit<3,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyAddition<posit<3, 3>>(reportTestCases), "posit<3,3>", "addition");

nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<64, 2>(reportTestCases, OPCODE_ADD, 1000), "posit<64,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<64, 2>>(reportTestCases, OPCODE_ADD, 1000), "posit<64,2>", "addition");

ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
return EXIT_SUCCESS;
Expand Down Expand Up @@ -119,32 +119,32 @@ try {
#endif

#if REGRESSION_LEVEL_2
nrOfFailedTestCases += ReportTestResult(VerifyAddition<posit<10, 0>>(reportTestCases), "posit<10,0>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyAddition<posit<10, 1>>(reportTestCases), "posit<10,1>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyAddition<posit<10, 0>>(reportTestCases), "posit<10,0>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyAddition<posit<10, 1>>(reportTestCases), "posit<10,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyAddition<posit<10, 2>>(reportTestCases), "posit<10,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyAddition<posit<10, 3>>(reportTestCases), "posit<10,3>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyAddition<posit<10, 3>>(reportTestCases), "posit<10,3>", "addition");

nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<16, 2>(reportTestCases, OPCODE_ADD, 1000), "posit<16,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<24, 2>(reportTestCases, OPCODE_ADD, 1000), "posit<24,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<16, 2>>(reportTestCases, OPCODE_ADD, 1000), "posit<16,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<24, 2>> (reportTestCases, OPCODE_ADD, 1000), "posit<24,1>", "addition");
#endif

#if REGRESSION_LEVEL_3
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<20, 1>(reportTestCases, OPCODE_ADD, 1000), "posit<20,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<28, 1>(reportTestCases, OPCODE_ADD, 1000), "posit<28,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<20, 1>> (reportTestCases, OPCODE_ADD, 1000), "posit<20,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<28, 1>> (reportTestCases, OPCODE_ADD, 1000), "posit<28,1>", "addition");

nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<32, 1>(reportTestCases, OPCODE_ADD, 1000), "posit<32,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<32, 2>(reportTestCases, OPCODE_ADD, 1000), "posit<32,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<32, 3>(reportTestCases, OPCODE_ADD, 1000), "posit<32,3>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<32, 1>> (reportTestCases, OPCODE_ADD, 1000), "posit<32,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<32, 2>> (reportTestCases, OPCODE_ADD, 1000), "posit<32,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<32, 3>> (reportTestCases, OPCODE_ADD, 1000), "posit<32,3>", "addition");
#endif

#if REGRESSION_LEVEL_4
// nbits=48 also shows failures
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<48, 2>(reportTestCases, OPCODE_ADD, 1000), "posit<48,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<48, 2>> (reportTestCases, OPCODE_ADD, 1000), "posit<48,2>", "addition");

// nbits=64 requires long double compiler support
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<64, 2>(reportTestCases, OPCODE_ADD, 1000), "posit<64,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<64, 3>(reportTestCases, OPCODE_ADD, 1000), "posit<64,3>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<64, 4>(reportTestCases, OPCODE_ADD, 1000), "posit<64,4>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<64, 2>>(reportTestCases, OPCODE_ADD, 1000), "posit<64,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<64, 3>>(reportTestCases, OPCODE_ADD, 1000), "posit<64,3>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<64, 4>> (reportTestCases, OPCODE_ADD, 1000), "posit<64,4>", "addition");

#ifdef HARDWARE_ACCELERATION
nrOfFailedTestCases += ReportTestResult(VerifyAddition<posit<12, 1>>(reportTestCases), "posit<12,1>", "addition");
Expand Down
64 changes: 19 additions & 45 deletions static/posit/arithmetic/complex_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ try {
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<5, 2>>(reportTestCases), "complex<posit<5,2>>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<5, 3>>(reportTestCases), "complex<posit<5,3>>", "addition");

// nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms<16, 1>>(reportTestCases, OPCODE_ADD, 1000), "posit<16,1>", "addition");
// nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms<64, 2>>(reportTestCases, OPCODE_ADD, 1000), "posit<64,2>", "addition");

ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
return EXIT_SUCCESS;
#else
Expand All @@ -172,59 +169,36 @@ try {
#endif

#if REGRESSION_LEVEL_2
#endif

#if REGRESSION_LEVEL_3
/* TODO
nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms<16, 1>>(reportTestCases, OPCODE_ADD, 1000), "posit<16,1>", "addition");
nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms<24, 1>>(reportTestCases, OPCODE_ADD, 1000), "posit<24,1>", "addition");
nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms<32, 1>>(reportTestCases, OPCODE_ADD, 1000), "posit<32,1>", "addition");
nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms<32, 2>>(reportTestCases, OPCODE_ADD, 1000), "posit<32,2>", "addition");
*/

#endif

#if REGRESSION_LEVEL_4

nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<5, 0>>(reportTestCases), "posit<5,0>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<5, 1>>(reportTestCases), "posit<5,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<5, 2>>(reportTestCases), "posit<5,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<5, 3>>(reportTestCases), "posit<5,3>", "addition");
#endif

nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<6, 0>>(reportTestCases), "posit<6,0>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<6, 1>>(reportTestCases), "posit<6,1>", "addition");
#if REGRESSION_LEVEL_3
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<6, 0>>(reportTestCases), "posit<6,0>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<6, 1>>(reportTestCases), "posit<6,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<6, 2>>(reportTestCases), "posit<6,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<6, 3>>(reportTestCases), "posit<6,3>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<6, 4>>(reportTestCases), "posit<6,4>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<6, 3>>(reportTestCases), "posit<6,3>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<6, 4>>(reportTestCases), "posit<6,4>", "addition");

nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<7, 0>>(reportTestCases), "posit<7,0>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<7, 1>>(reportTestCases), "posit<7,1>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<7, 0>>(reportTestCases), "posit<7,0>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<7, 1>>(reportTestCases), "posit<7,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<7, 2>>(reportTestCases), "posit<7,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<7, 3>>(reportTestCases), "posit<7,3>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<7, 4>>(reportTestCases), "posit<7,4>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<7, 5>>(reportTestCases), "posit<7,5>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<7, 3>>(reportTestCases), "posit<7,3>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<7, 4>>(reportTestCases), "posit<7,4>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<7, 5>>(reportTestCases), "posit<7,5>", "addition");
#endif

nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 0>>(reportTestCases), "posit<8,0>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 1>>(reportTestCases), "posit<8,1>", "addition");
#if REGRESSION_LEVEL_4
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 0>>(reportTestCases), "posit<8,0>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 1>>(reportTestCases), "posit<8,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 2>>(reportTestCases), "posit<8,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 3>>(reportTestCases), "posit<8,3>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 4>>(reportTestCases), "posit<8,4>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 5>>(reportTestCases), "posit<8,5>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 6>>(reportTestCases), "posit<8,6>", "addition");

// nbits=48 also shows failures
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<48, 2>(reportTestCases, OPCODE_ADD, 1000), "posit<48,2>", "addition");

// nbits=64 requires long double compiler support
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<64, 2>(reportTestCases, OPCODE_ADD, 1000), "posit<64,2>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<64, 3>(reportTestCases, OPCODE_ADD, 1000), "posit<64,3>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<64, 4>(reportTestCases, OPCODE_ADD, 1000), "posit<64,4>", "addition");

// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 3>>(reportTestCases), "posit<8,3>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 4>>(reportTestCases), "posit<8,4>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 5>>(reportTestCases), "posit<8,5>", "addition");
// nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<8, 6>>(reportTestCases), "posit<8,6>", "addition");

nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<10, 1>>(reportTestCases), "posit<10,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<12, 1>>(reportTestCases), "posit<12,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<14, 1>>(reportTestCases), "posit<14,1>", "addition");
nrOfFailedTestCases += ReportTestResult(VerifyComplexAddition<posit<16, 1>>(reportTestCases), "posit<16,1>", "addition");
#endif // REGRESSION_LEVEL_4

ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
Expand Down
30 changes: 15 additions & 15 deletions static/posit/arithmetic/division.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// third: enable tracing
// when you define ALGORITHM_VERBOSE_OUTPUT executing an ADD the code will print intermediate results
//#define ALGORITHM_VERBOSE_OUTPUT
#define ALGORITHM_TRACE_DIV
//#define ALGORITHM_TRACE_DIV
#include <universal/number/posit/posit.hpp>
#include <universal/verification/posit_test_suite.hpp>
#include <universal/verification/posit_test_suite_randoms.hpp>
Expand Down Expand Up @@ -254,33 +254,33 @@ try {
#endif

#if REGRESSION_LEVEL_2
nrOfFailedTestCases += ReportTestResult(VerifyDivision<posit<10, 0>>(reportTestCases), "posit<10,0>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyDivision<posit<10, 1>>(reportTestCases), "posit<10,1>", "division");
// nrOfFailedTestCases += ReportTestResult(VerifyDivision<posit<10, 0>>(reportTestCases), "posit<10,0>", "division");
// nrOfFailedTestCases += ReportTestResult(VerifyDivision<posit<10, 1>>(reportTestCases), "posit<10,1>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyDivision<posit<10, 2>>(reportTestCases), "posit<10,2>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyDivision<posit<10, 3>>(reportTestCases), "posit<10,3>", "division");
// nrOfFailedTestCases += ReportTestResult(VerifyDivision<posit<10, 3>>(reportTestCases), "posit<10,3>", "division");

nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<16, 2>(reportTestCases, OPCODE_DIV, 1000), "posit<16,2>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<24, 2>(reportTestCases, OPCODE_DIV, 1000), "posit<24,2>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<16, 2>>(reportTestCases, OPCODE_DIV, 1000), "posit<16,2>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<24, 2>>(reportTestCases, OPCODE_DIV, 1000), "posit<24,2>", "division");
#endif

#if REGRESSION_LEVEL_3
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<20, 1>(reportTestCases, OPCODE_DIV, 1000), "posit<20,1>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<28, 1>(reportTestCases, OPCODE_DIV, 1000), "posit<28,1>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<20, 1>>(reportTestCases, OPCODE_DIV, 1000), "posit<20,1>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<28, 1>>(reportTestCases, OPCODE_DIV, 1000), "posit<28,1>", "division");

nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<32, 1>(reportTestCases, OPCODE_DIV, 1000), "posit<32,1>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<32, 2>(reportTestCases, OPCODE_DIV, 1000), "posit<32,2>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<32, 3>(reportTestCases, OPCODE_DIV, 1000), "posit<32,3>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<32, 1>>(reportTestCases, OPCODE_DIV, 1000), "posit<32,1>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<32, 2>>(reportTestCases, OPCODE_DIV, 1000), "posit<32,2>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<32, 3>>(reportTestCases, OPCODE_DIV, 1000), "posit<32,3>", "division");
#endif

#if REGRESSION_LEVEL_4
// nbits = 48 also shows failures
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<48, 2>(reportTestCases, OPCODE_DIV, 1000), "posit<48,2>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<48, 2>>(reportTestCases, OPCODE_DIV, 1000), "posit<48,2>", "division");

// nbits=64 requires long double compiler support
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<64, 2>(reportTestCases, OPCODE_DIV, 1000), "posit<64,2>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<64, 3>(reportTestCases, OPCODE_DIV, 1000), "posit<64,3>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<64, 2>>(reportTestCases, OPCODE_DIV, 1000), "posit<64,2>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<64, 3>>(reportTestCases, OPCODE_DIV, 1000), "posit<64,3>", "division");
// posit<64,4> is hitting subnormal numbers
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<64, 4>(reportTestCases, OPCODE_DIV, 1000), "posit<64,4>", "division");
nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms<posit<64, 4>>(reportTestCases, OPCODE_DIV, 1000), "posit<64,4>", "division");

#ifdef HARDWARE_ACCELERATION
nrOfFailedTestCases += ReportTestResult(VerifyDivision<posit<12, 1>>(reportTestCases), "posit<12,1>", "division");
Expand Down
Loading

0 comments on commit 60fe91c

Please sign in to comment.