diff --git a/benchmark/accuracy/quantization/mpdot.cpp b/benchmark/accuracy/quantization/mpdot.cpp index 134bf9748..84d7c739c 100644 --- a/benchmark/accuracy/quantization/mpdot.cpp +++ b/benchmark/accuracy/quantization/mpdot.cpp @@ -361,7 +361,7 @@ namespace sw { if constexpr (bCSV) { std::cout << stats.stddev << ", " << faEquivalency << ", " << stats.mean ; for (int i = 0; i < 5; ++i) { - std::cout << ", " << stats.quartiles[i]; + std::cout << ", " << stats.quantiles.q[i]; } std::cout << '\n'; } diff --git a/include/universal/blas/blas_l1.hpp b/include/universal/blas/blas_l1.hpp index 9e0f7cccd..d51452efd 100644 --- a/include/universal/blas/blas_l1.hpp +++ b/include/universal/blas/blas_l1.hpp @@ -172,9 +172,8 @@ void strided_print(std::ostream& ostr, size_t n, Vector& x, size_t incx = 1) { // L1-norm of a vector template Scalar normL1(const sw::universal::blas::vector& v) { - using namespace sw::universal; // to specialize abs() Scalar L1Norm{ 0 }; - for (auto e : v) { + for (const Scalar& e : v) { L1Norm += abs(e); } return L1Norm; @@ -184,7 +183,7 @@ Scalar normL1(const sw::universal::blas::vector& v) { template Scalar normL2(const sw::universal::blas::vector& v) { Scalar L2Norm{ 0 }; - for (auto e : v) { + for (const Scalar& e : v) { L2Norm += e * e; } return sqrt(L2Norm); @@ -196,7 +195,7 @@ Scalar normL3(const sw::universal::blas::vector& v) { using namespace std; using namespace sw::universal; // to specialize abs() Scalar L3Norm{ 0 }; - for (auto e : v) { + for (const Scalar& e : v) { Scalar abse = abs(e); L3Norm += abse * abse * abse; } @@ -207,7 +206,7 @@ Scalar normL3(const sw::universal::blas::vector& v) { template Scalar normL4(const sw::universal::blas::vector& v) { Scalar L4Norm{ 0 }; - for (auto e : v) { + for (const Scalar& e : v) { Scalar esqr = e * e; L4Norm += esqr * esqr; } @@ -220,7 +219,7 @@ Scalar normLinf(const sw::universal::blas::vector& v) { using namespace std; using namespace sw::universal; // to specialize abs() Scalar LinfNorm{ 0 }; - for (auto e : v) { + for (const Scalar& e : v) { LinfNorm = (abs(e) > LinfNorm) ? abs(e) : LinfNorm; } return LinfNorm; @@ -251,10 +250,11 @@ Scalar norm(const sw::universal::blas::vector& v, int p) { break; default: { - for (auto e : v) { - norm += pow(abs(e), Scalar( p )); + Scalar sp = Scalar( p ); + for (const Scalar& e : v) { + norm += pow(abs(e), sp); } - norm = pow(norm, Scalar( 1 ) / Scalar( p )); + norm = pow(norm, Scalar( 1 ) / sp); } break; } diff --git a/include/universal/blas/solvers/cg_dot_dot.hpp b/include/universal/blas/solvers/cg_dot_dot.hpp index 295c2a67a..79e93d4e3 100644 --- a/include/universal/blas/solvers/cg_dot_dot.hpp +++ b/include/universal/blas/solvers/cg_dot_dot.hpp @@ -59,10 +59,10 @@ size_t cg_dot_dot(const Matrix& M, const Matrix& A, const Vector& b, Vector& x, ++itr; } if (residual < tolerance) { - std::cout << "solution in " << itr << " iterations\n"; + std::cout << "successfully converged in : " << itr << " iterations\n"; } else { - std::cout << "failed to converge in " << itr << " iterations\n"; + std::cout << "failed to converge in : " << itr << " iterations\n"; } return itr; diff --git a/include/universal/blas/solvers/cg_dot_fdp.hpp b/include/universal/blas/solvers/cg_dot_fdp.hpp index 32507a90d..8563cb427 100644 --- a/include/universal/blas/solvers/cg_dot_fdp.hpp +++ b/include/universal/blas/solvers/cg_dot_fdp.hpp @@ -59,10 +59,10 @@ size_t cg_dot_fdp(const Matrix& M, const Matrix& A, const Vector& b, Vector& x, ++itr; } if (residual < tolerance) { - std::cout << "solution in " << itr << " iterations\n"; + std::cout << "successfully converged in : " << itr << " iterations\n"; } else { - std::cout << "failed to converge in " << itr << " iterations\n"; + std::cout << "failed to converge in : " << itr << " iterations\n"; } return itr; diff --git a/include/universal/verification/posit_test_randoms.hpp b/include/universal/verification/posit_test_randoms.hpp index c08585a86..fa3943ff1 100644 --- a/include/universal/verification/posit_test_randoms.hpp +++ b/include/universal/verification/posit_test_randoms.hpp @@ -61,142 +61,142 @@ namespace sw { namespace universal { // Execute a binary operator template - void executeBinary(int opcode, double da, double db, const TestType& testa, const TestType& testb, TestType& testresult, TestType& testref) { - double reference = 0.0; + void executeBinary(int opcode, double da, double db, double& dc, const TestType& testa, const TestType& testb, TestType& testc, TestType& testref) { + dc = 0.0; switch (opcode) { case OPCODE_ADD: - testresult = testa + testb; - reference = da + db; + testc = testa + testb; + dc = da + db; break; case OPCODE_SUB: - testresult = testa - testb; - reference = da - db; + testc = testa - testb; + dc = da - db; break; case OPCODE_MUL: - testresult = testa * testb; - reference = da * db; + testc = testa * testb; + dc = da * db; break; case OPCODE_DIV: - testresult = testa / testb; - reference = da / db; + testc = testa / testb; + dc = da / db; break; case OPCODE_IPA: - testresult = testa; - testresult += testb; - reference = da + db; + testc = testa; + testc += testb; + dc = da + db; break; case OPCODE_IPS: - testresult = testa; - testresult -= testb; - reference = da - db; + testc = testa; + testc -= testb; + dc = da - db; break; case OPCODE_IPM: - testresult = testa; - testresult *= testb; - reference = da * db; + testc = testa; + testc *= testb; + dc = da * db; break; case OPCODE_IPD: - testresult = testa; - testresult /= testb; - reference = da / db; + testc = testa; + testc /= testb; + dc = da / db; break; case OPCODE_POW: - testresult = sw::universal::pow(testa, testb); - reference = std::pow(da, db); + testc = sw::universal::pow(testa, testb); + dc = std::pow(da, db); break; case OPCODE_NOP: default: - std::cerr << "Unsupported unary operator: operation ignored\n"; + std::cerr << "unary operators not supported in executeBinary: operation ignored\n"; break; } - testref = reference; + testref = dc; } // Execute a unary operator template - void executeUnary(int opcode, double da, const TestType& testa, TestType& testref, TestType& testresult, double dminpos) { - double reference = 0.0; + void executeUnary(int opcode, double da, double& dc, const TestType& testa, TestType& testc, TestType& testref, double dminpos) { + dc = 0.0; switch (opcode) { case OPCODE_SQRT: - testresult = sw::universal::sqrt(testa); - reference = std::sqrt(da); + testc = sw::universal::sqrt(testa); + dc = std::sqrt(da); break; case OPCODE_EXP: - testresult = sw::universal::exp(testa); - reference = std::exp(da); - if (0.0 == reference) reference = dminpos; + testc = sw::universal::exp(testa); + dc = std::exp(da); + if (0.0 == dc) dc = dminpos; break; case OPCODE_EXP2: - testresult = sw::universal::exp2(testa); - reference = std::exp2(da); - if (0.0 == reference) reference = dminpos; + testc = sw::universal::exp2(testa); + dc = std::exp2(da); + if (0.0 == dc) dc = dminpos; break; case OPCODE_LOG: - testresult = sw::universal::log(testa); - reference = std::log(da); + testc = sw::universal::log(testa); + dc = std::log(da); break; case OPCODE_LOG2: - testresult = sw::universal::log2(testa); - reference = std::log2(da); + testc = sw::universal::log2(testa); + dc = std::log2(da); break; case OPCODE_LOG10: - testresult = sw::universal::log10(testa); - reference = std::log10(da); + testc = sw::universal::log10(testa); + dc = std::log10(da); break; case OPCODE_SIN: - testresult = sw::universal::sin(testa); - reference = std::sin(da); + testc = sw::universal::sin(testa); + dc = std::sin(da); break; case OPCODE_COS: - testresult = sw::universal::cos(testa); - reference = std::cos(da); + testc = sw::universal::cos(testa); + dc = std::cos(da); break; case OPCODE_TAN: - testresult = sw::universal::tan(testa); - reference = std::tan(da); + testc = sw::universal::tan(testa); + dc = std::tan(da); break; case OPCODE_ASIN: - testresult = sw::universal::asin(testa); - reference = std::asin(da); + testc = sw::universal::asin(testa); + dc = std::asin(da); break; case OPCODE_ACOS: - testresult = sw::universal::acos(testa); - reference = std::acos(da); + testc = sw::universal::acos(testa); + dc = std::acos(da); break; case OPCODE_ATAN: - testresult = sw::universal::atan(testa); - reference = std::atan(da); + testc = sw::universal::atan(testa); + dc = std::atan(da); break; case OPCODE_SINH: - testresult = sw::universal::sinh(testa); - reference = std::sinh(da); + testc = sw::universal::sinh(testa); + dc = std::sinh(da); break; case OPCODE_COSH: - testresult = sw::universal::cosh(testa); - reference = std::cosh(da); + testc = sw::universal::cosh(testa); + dc = std::cosh(da); break; case OPCODE_TANH: - testresult = sw::universal::tanh(testa); - reference = std::tanh(da); + testc = sw::universal::tanh(testa); + dc = std::tanh(da); break; case OPCODE_ASINH: - testresult = sw::universal::asinh(testa); - reference = std::asinh(da); + testc = sw::universal::asinh(testa); + dc = std::asinh(da); break; case OPCODE_ACOSH: - testresult = sw::universal::acosh(testa); - reference = std::acosh(da); + testc = sw::universal::acosh(testa); + dc = std::acosh(da); break; case OPCODE_ATANH: - testresult = sw::universal::atanh(testa); - reference = std::atanh(da); + testc = sw::universal::atanh(testa); + dc = std::atanh(da); break; case OPCODE_NOP: default: std::cerr << "Unsupported binary operator: operation ignored\n"; break; } - testref = reference; + testref = dc; } // generate a random set of operands to test the binary operators for a posit configuration @@ -245,18 +245,19 @@ namespace sw { namespace universal { std::uniform_int_distribution distr; int nrOfFailedTests = 0; for (unsigned i = 1; i < nrOfRandoms; i++) { - posit testa, testb, testresult, testref; + posit testa, testb, testc, testref; testa.setbits(distr(eng)); testb.setbits(distr(eng)); double da = double(testa); double db = double(testb); + double dc = 0.0; // in case you have numeric_limits::digits trouble... this will show that //std::cout << "sizeof da: " << sizeof(da) << " bits in significant " << (std::numeric_limits::digits - 1) << " value da " << da << " at index " << ia << " testa " << testa << std::endl; //std::cout << "sizeof db: " << sizeof(db) << " bits in significant " << (std::numeric_limits::digits - 1) << " value db " << db << " at index " << ia << " testa " << testb << std::endl; #if POSIT_THROW_ARITHMETIC_EXCEPTION try { - executeBinary(opcode, da, db, testa, testb, testref, testresult); + executeBinary(opcode, da, db, dc, testa, testb, testc, testref); } catch (const posit_arithmetic_exception& err) { if (testa.isnar() || testb.isnar() || ((opcode == OPCODE_DIV || opcode == OPCODE_IPD) && testb.iszero())) { @@ -267,16 +268,15 @@ namespace sw { namespace universal { } } #else - executeBinary(opcode, da, db, testa, testb, testref, testresult); + executeBinary(opcode, da, db, dc, testa, testb, testc, testref); #endif - testresult = testref; - if (testresult != testref) { + if (testc != testref) { nrOfFailedTests++; - if (reportTestCases) ReportBinaryArithmeticError("FAIL", operation_string, testa, testb, testresult, testref); + if (reportTestCases) ReportBinaryArithmeticError("FAIL", operation_string, testa, testb, testc, testref); } else { - //if (reportTestCases) ReportBinaryArithmeticSuccess("PASS", operation_string, testa, testb, testresult, testref); + //if (reportTestCases) ReportBinaryArithmeticSuccess("PASS", operation_string, testa, testb, testc, testref); } } return nrOfFailedTests; @@ -337,15 +337,16 @@ namespace sw { namespace universal { std::uniform_int_distribution distr; int nrOfFailedTests = 0; for (unsigned i = 1; i < nrOfRandoms; i++) { - TestType testa, testresult, testref; + TestType testa, testc, testref; testa.setbits(distr(eng)); if (sqrtOperator && testa < 0) testa = -testa; double da = double(testa); + double dc = 0.0; // in case you have numeric_limits::digits trouble... this will show that //std::cout << "sizeof da: " << sizeof(da) << " bits in significant " << (std::numeric_limits::digits - 1) << " value da " << da << " at index " << ia << " testa " << testa << std::endl; #if POSIT_THROW_ARITHMETIC_EXCEPTION try { - executeUnary(opcode, da, testa, testref, testresult, dminpos); + executeUnary(opcode, da, dc, testa, testc, testref, dminpos); } catch (const posit_arithmetic_exception& err) { if (testa.isnar()) { @@ -356,14 +357,14 @@ namespace sw { namespace universal { } } #else - executeUnary(opcode, da, testa, testref, testresult, dminpos); + executeUnary(opcode, da, dc, testa, testc, testref, dminpos); #endif - if (testresult != testref) { + if (testc != testref) { nrOfFailedTests++; - if (reportTestCases) ReportUnaryArithmeticError("FAIL", operation_string, testa, testresult, testref); + if (reportTestCases) ReportUnaryArithmeticError("FAIL", operation_string, testa, testc, testref); } else { - //if (reportTestCases) ReportUnaryArithmeticSuccess("PASS", operation_string, testa, testresult, testref); + //if (reportTestCases) ReportUnaryArithmeticSuccess("PASS", operation_string, testa, testc, testref); } } diff --git a/linalg/data/summary_statistics.cpp b/linalg/data/summary_statistics.cpp index 28523895a..21daa7768 100644 --- a/linalg/data/summary_statistics.cpp +++ b/linalg/data/summary_statistics.cpp @@ -1,6 +1,6 @@ // summary_statistics.cpp: test suite for summary statistics function for data preprocessing // -// Copyright (C) 2017-2023 Stillwater Supercomputing, Inc. +// Copyright (C) 2023 Stillwater Supercomputing, Inc. // // This file is part of the universal numbers project, which is released under an MIT Open Source license. #include @@ -67,7 +67,7 @@ try { size_t N = 1024*1024; std::vector data(N); blas::gaussian_random(data, 0.0, 1.0); - blas::SummaryStats stats = blas::summaryStatistics(data); + auto stats = blas::summaryStatistics(data); std::cout << "Summary statistics:\n" << stats << '\n'; diff --git a/mixedprecision/tensor/cg/cg.cpp b/mixedprecision/tensor/cg/cg.cpp index 2445b3789..002594c5b 100644 --- a/mixedprecision/tensor/cg/cg.cpp +++ b/mixedprecision/tensor/cg/cg.cpp @@ -19,7 +19,7 @@ #define POSIT_THROW_ARITHMETIC_EXCEPTION 1 // and fast posits //#define POSIT_FAST_SPECIALIZATION 1 -#define POSIT_FAST_POSIT_32_2 1 +#define POSIT_FAST_POSIT_32_2 0 #include #include #include diff --git a/mixedprecision/tensor/cg/cg_mvdot_cmpdot.cpp b/mixedprecision/tensor/cg/cg_mvdot_cmpdot.cpp index 20c56b866..1df16c043 100644 --- a/mixedprecision/tensor/cg/cg_mvdot_cmpdot.cpp +++ b/mixedprecision/tensor/cg/cg_mvdot_cmpdot.cpp @@ -19,7 +19,7 @@ #define POSIT_THROW_ARITHMETIC_EXCEPTION 1 // and fast posits //#define POSIT_FAST_SPECIALIZATION 1 -#define POSIT_FAST_POSIT_32_2 1 +#define POSIT_FAST_POSIT_32_2 0 #include #include #include diff --git a/mixedprecision/tensor/cg/cg_mvdot_cmpfdp.cpp b/mixedprecision/tensor/cg/cg_mvdot_cmpfdp.cpp index 34e6c0b37..ca51d0421 100644 --- a/mixedprecision/tensor/cg/cg_mvdot_cmpfdp.cpp +++ b/mixedprecision/tensor/cg/cg_mvdot_cmpfdp.cpp @@ -19,7 +19,7 @@ #define POSIT_THROW_ARITHMETIC_EXCEPTION 1 // and fast posits //#define POSIT_FAST_SPECIALIZATION 1 -#define POSIT_FAST_POSIT_32_2 1 +#define POSIT_FAST_POSIT_32_2 0 #include #include #include @@ -138,6 +138,8 @@ try { } #else + + std::cout << "CG convergence and final residuals\n"; // with a preconditioner M = Jacobian(A)^-1 constexpr size_t MAX_ITERATIONS = 100; fdTest(64); diff --git a/mixedprecision/tensor/cg/cg_mvfdp_cmpdot.cpp b/mixedprecision/tensor/cg/cg_mvfdp_cmpdot.cpp index df0cab33b..79a976e89 100644 --- a/mixedprecision/tensor/cg/cg_mvfdp_cmpdot.cpp +++ b/mixedprecision/tensor/cg/cg_mvfdp_cmpdot.cpp @@ -19,7 +19,7 @@ #define POSIT_THROW_ARITHMETIC_EXCEPTION 1 // and fast posits //#define POSIT_FAST_SPECIALIZATION 1 -#define POSIT_FAST_POSIT_32_2 1 +#define POSIT_FAST_POSIT_32_2 0 #include #include #include diff --git a/mixedprecision/tensor/cg/cg_mvfdp_cmpfdp.cpp b/mixedprecision/tensor/cg/cg_mvfdp_cmpfdp.cpp index ecf5f1e82..8eb72dd6a 100644 --- a/mixedprecision/tensor/cg/cg_mvfdp_cmpfdp.cpp +++ b/mixedprecision/tensor/cg/cg_mvfdp_cmpfdp.cpp @@ -19,7 +19,7 @@ #define POSIT_THROW_ARITHMETIC_EXCEPTION 1 // and fast posits //#define POSIT_FAST_SPECIALIZATION 1 -#define POSIT_FAST_POSIT_32_2 1 +#define POSIT_FAST_POSIT_32_2 0 #include #include #include @@ -153,9 +153,6 @@ try { #if STRESS #endif // STRESS -#if STRESS -#endif // STRESS - #endif // MANUAL return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); diff --git a/static/posit/specialized/posit_128_2.cpp b/static/posit/specialized/posit_128_2.cpp index f0d2769c5..b693ae81f 100644 --- a/static/posit/specialized/posit_128_2.cpp +++ b/static/posit/specialized/posit_128_2.cpp @@ -18,11 +18,15 @@ /// Standard posits with nbits = 128 have 2 exponent bits. // Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override -#define MANUAL_TESTING 0 +#define MANUAL_TESTING 1 // REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity // It is the responsibility of the regression test to organize the tests in a quartile progression. //#undef REGRESSION_LEVEL_OVERRIDE #ifndef REGRESSION_LEVEL_OVERRIDE +#undef REGRESSION_LEVEL_1 +#undef REGRESSION_LEVEL_2 +#undef REGRESSION_LEVEL_3 +#undef REGRESSION_LEVEL_4 #define REGRESSION_LEVEL_1 1 #define REGRESSION_LEVEL_2 1 #define REGRESSION_LEVEL_3 1 @@ -37,16 +41,20 @@ try { constexpr size_t nbits = 128; constexpr size_t es = 2; - int nrOfFailedTestCases = 0; - bool bReportIndividualTestCases = false; - size_t RND_TEST_CASES = 1024; - #if POSIT_FAST_POSIT_128_2 - std::cout << "Fast specialization posit<128,2> configuration tests\n"; + std::string test_suite = "Fast specialization posit<128,2>"; #else - std::cout << "Standard posit<128,2> configuration tests\n"; + std::string test_suite = "Standard posit<128,2>"; #endif + std::string test_tag = "arithmetic type tests"; + bool reportTestCases = false; + int nrOfFailedTestCases = 0; + + ReportTestSuiteHeader(test_suite, reportTestCases); + + size_t RND_TEST_CASES = 1024; + using Scalar = posit; Scalar p; std::cout << dynamic_range(p) << "\n\n"; @@ -54,9 +62,36 @@ try { #if MANUAL_TESTING - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + // special cases + std::cout << "Special case tests\n"; + std::string test = "Initialize to zero: "; + p = 0; + nrOfFailedTestCases += ReportCheck(tag, test, p.iszero()); + test = "Initialize to NAN"; + p = NAN; + nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + test = "Initialize to INFINITY"; + p = INFINITY; + nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + test = "sign is true"; + p = -1.0f; + nrOfFailedTestCases += ReportCheck(tag, test, p.sign()); + test = "is negative"; + nrOfFailedTestCases += ReportCheck(tag, test, p.isneg()); + test = "sign is false"; + p = +1.0f; + nrOfFailedTestCases += ReportCheck(tag, test, !p.sign()); + test = "is positive"; + nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); - nrOfFailedTestCases = 0; + RND_TEST_CASES = 1024; + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return EXIT_SUCCESS; // ignore failures #else #if REGRESSION_LEVEL_1 @@ -83,10 +118,10 @@ try { nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); RND_TEST_CASES = 1024; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); #endif @@ -106,17 +141,17 @@ try { RND_TEST_CASES = 1024 * 1024; std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each\n"; std::cout << "Without an arithmetic reference, test failures can be ignored\n"; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); nrOfFailedTestCases = 0; #endif -#endif // MANUAL_TESTING - + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); +#endif // MANUAL_TESTING } catch (char const* msg) { std::cerr << msg << std::endl; diff --git a/static/posit/specialized/posit_128_4.cpp b/static/posit/specialized/posit_128_4.cpp index ff0935c53..678ca6bbd 100644 --- a/static/posit/specialized/posit_128_4.cpp +++ b/static/posit/specialized/posit_128_4.cpp @@ -18,11 +18,15 @@ /// Standard posits with nbits = 128 have 4 exponent bits. // Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override -#define MANUAL_TESTING 0 +#define MANUAL_TESTING 1 // REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity // It is the responsibility of the regression test to organize the tests in a quartile progression. //#undef REGRESSION_LEVEL_OVERRIDE #ifndef REGRESSION_LEVEL_OVERRIDE +#undef REGRESSION_LEVEL_1 +#undef REGRESSION_LEVEL_2 +#undef REGRESSION_LEVEL_3 +#undef REGRESSION_LEVEL_4 #define REGRESSION_LEVEL_1 1 #define REGRESSION_LEVEL_2 1 #define REGRESSION_LEVEL_3 1 @@ -35,18 +39,22 @@ try { // posit<128,4> constexpr size_t nbits = 128; - constexpr size_t es = 4; - - int nrOfFailedTestCases = 0; - bool bReportIndividualTestCases = false; - size_t RND_TEST_CASES = 1024; + constexpr size_t es = 4; #if POSIT_FAST_POSIT_128_4 - std::cout << "Fast specialization posit<128,4> configuration tests\n"; + std::string test_suite = "Fast specialization posit<128,4>"; #else - std::cout << "Standard posit<128,4> configuration tests\n"; + std::string test_suite = "Standard posit<128,4>"; #endif + std::string test_tag = "arithmetic type tests"; + bool reportTestCases = false; + int nrOfFailedTestCases = 0; + + ReportTestSuiteHeader(test_suite, reportTestCases); + + size_t RND_TEST_CASES = 1024; + using Scalar = posit; Scalar p; std::cout << dynamic_range(p) << "\n\n"; @@ -54,9 +62,36 @@ try { #if MANUAL_TESTING - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + // special cases + std::cout << "Special case tests\n"; + std::string test = "Initialize to zero: "; + p = 0; + nrOfFailedTestCases += ReportCheck(tag, test, p.iszero()); + test = "Initialize to NAN"; + p = NAN; + nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + test = "Initialize to INFINITY"; + p = INFINITY; + nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + test = "sign is true"; + p = -1.0f; + nrOfFailedTestCases += ReportCheck(tag, test, p.sign()); + test = "is negative"; + nrOfFailedTestCases += ReportCheck(tag, test, p.isneg()); + test = "sign is false"; + p = +1.0f; + nrOfFailedTestCases += ReportCheck(tag, test, !p.sign()); + test = "is positive"; + nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); - nrOfFailedTestCases = 0; + RND_TEST_CASES = 1024; + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return EXIT_SUCCESS; // ignore failures #else #if REGRESSION_LEVEL_1 @@ -83,10 +118,10 @@ try { nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); RND_TEST_CASES = 1024; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); #endif @@ -106,17 +141,17 @@ try { RND_TEST_CASES = 1024 * 1024; std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each\n"; std::cout << "Without an arithmetic reference, test failures can be ignored\n"; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); nrOfFailedTestCases = 0; #endif -#endif // MANUAL_TESTING - + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); +#endif // MANUAL_TESTING } catch (char const* msg) { std::cerr << msg << std::endl; diff --git a/static/posit/specialized/posit_16_1.cpp b/static/posit/specialized/posit_16_1.cpp index 64a9d9734..eee672543 100644 --- a/static/posit/specialized/posit_16_1.cpp +++ b/static/posit/specialized/posit_16_1.cpp @@ -39,18 +39,22 @@ try { // configure a posit<16,1> constexpr size_t nbits = 16; - constexpr size_t es = 1; - - int nrOfFailedTestCases = 0; - bool bReportIndividualTestCases = false; - size_t RND_TEST_CASES = 10000; + constexpr size_t es = 1; #if POSIT_FAST_POSIT_16_1 - std::cout << "Fast specialization posit<16,1> configuration tests\n"; + std::string test_suite = "Fast specialization posit<16,1>"; #else - std::cout << "Standard posit<16,1> configuration tests\n"; + std::string test_suite = "Standard posit<16,1>"; #endif + std::string test_tag = "arithmetic type tests"; + bool reportTestCases = false; + int nrOfFailedTestCases = 0; + + ReportTestSuiteHeader(test_suite, reportTestCases); + + size_t RND_TEST_CASES = 10000; + using Scalar = posit; Scalar p; std::cout << dynamic_range(p) << "\n\n"; @@ -72,10 +76,10 @@ try { a = fa; b = fb; c = a; c += b; std::cout << hex_format(a) << " + " << hex_format(b) << " = " << hex_format(a + b) << "(" << (fa + fb) << ") " << hex_format(c) << "(" << c << ")" << '\n'; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_IPA, 100), tag, "+= (native) "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_IPS, 100), tag, "-= (native) "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_IPM, 100), tag, "*= (native) "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_IPD, 100), tag, "/= (native) "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_IPA, 100), tag, "+= (native) "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_IPS, 100), tag, "-= (native) "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_IPM, 100), tag, "*= (native) "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_IPD, 100), tag, "/= (native) "); a.setnar(); b.setnar(); @@ -100,9 +104,8 @@ try { testLogicOperators(a, b); testLogicOperators(b, a); - std::cout << nrOfFailedTestCases << " number of failures\n"; - - nrOfFailedTestCases = 0; // ignore failures in manual testing + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return EXIT_SUCCESS; // ignore failures #else #if REGRESSION_LEVEL_1 @@ -129,10 +132,10 @@ try { nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); RND_TEST_CASES = 1024; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); #endif @@ -150,7 +153,7 @@ try { #if REGRESSION_LEVEL_3 // conversion tests std::cout << "Assignment/conversion tests\n"; - nrOfFailedTestCases += ReportTestResult( VerifyIntegerConversion (bReportIndividualTestCases), tag, "integer assign (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyIntegerConversion (reportTestCases), tag, "integer assign (native) "); // FAIL = 0.25003 did not convert to 0.250061 instead it yielded 0.25 raw 0b0.01.0.000000000000 // FAIL = 0.99994 did not convert to 0.999878 instead it yielded 1 raw 0b0.10.0.000000000000 // posit<16, 1> float assign(native) FAIL 2 failed test cases @@ -160,39 +163,39 @@ try { // arithmetic tests // State space is too large for exhaustive testing, so we use randoms to try to catch any silly regressions std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each\n"; - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_IPA, RND_TEST_CASES), tag, "+= (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_IPS, RND_TEST_CASES), tag, "-= (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_IPM, RND_TEST_CASES), tag, "*= (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_IPD, RND_TEST_CASES), tag, "/= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_IPA, RND_TEST_CASES), tag, "+= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_IPS, RND_TEST_CASES), tag, "-= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_IPM, RND_TEST_CASES), tag, "*= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_IPD, RND_TEST_CASES), tag, "/= (native) "); #endif #if REGRESSION_LEVEL_4 // elementary function tests std::cout << "Elementary function tests\n"; - nrOfFailedTestCases += ReportTestResult( VerifySqrt (bReportIndividualTestCases), tag, "sqrt (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyExp (bReportIndividualTestCases), tag, "exp "); - nrOfFailedTestCases += ReportTestResult( VerifyExp2 (bReportIndividualTestCases), tag, "exp2 "); - nrOfFailedTestCases += ReportTestResult( VerifyLog (bReportIndividualTestCases), tag, "log "); - nrOfFailedTestCases += ReportTestResult( VerifyLog2 (bReportIndividualTestCases), tag, "log2 "); - nrOfFailedTestCases += ReportTestResult( VerifyLog10 (bReportIndividualTestCases), tag, "log10 "); - nrOfFailedTestCases += ReportTestResult( VerifySine (bReportIndividualTestCases), tag, "sin "); - nrOfFailedTestCases += ReportTestResult( VerifyCosine (bReportIndividualTestCases), tag, "cos "); - nrOfFailedTestCases += ReportTestResult( VerifyTangent (bReportIndividualTestCases), tag, "tan "); - nrOfFailedTestCases += ReportTestResult( VerifyAsin (bReportIndividualTestCases), tag, "asin "); - nrOfFailedTestCases += ReportTestResult( VerifyAcos (bReportIndividualTestCases), tag, "acos "); - nrOfFailedTestCases += ReportTestResult( VerifyAtan (bReportIndividualTestCases), tag, "atan "); - nrOfFailedTestCases += ReportTestResult( VerifySinh (bReportIndividualTestCases), tag, "sinh "); - nrOfFailedTestCases += ReportTestResult( VerifyCosh (bReportIndividualTestCases), tag, "cosh "); - nrOfFailedTestCases += ReportTestResult( VerifyTanh (bReportIndividualTestCases), tag, "tanh "); - nrOfFailedTestCases += ReportTestResult( VerifyAsinh (bReportIndividualTestCases), tag, "asinh "); - nrOfFailedTestCases += ReportTestResult( VerifyAcosh (bReportIndividualTestCases), tag, "acosh "); - nrOfFailedTestCases += ReportTestResult( VerifyAtanh (bReportIndividualTestCases), tag, "atanh "); - - nrOfFailedTestCases += ReportTestResult( VerifyPowerFunction (bReportIndividualTestCases), tag, "pow "); + nrOfFailedTestCases += ReportTestResult( VerifySqrt (reportTestCases), tag, "sqrt (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyExp (reportTestCases), tag, "exp "); + nrOfFailedTestCases += ReportTestResult( VerifyExp2 (reportTestCases), tag, "exp2 "); + nrOfFailedTestCases += ReportTestResult( VerifyLog (reportTestCases), tag, "log "); + nrOfFailedTestCases += ReportTestResult( VerifyLog2 (reportTestCases), tag, "log2 "); + nrOfFailedTestCases += ReportTestResult( VerifyLog10 (reportTestCases), tag, "log10 "); + nrOfFailedTestCases += ReportTestResult( VerifySine (reportTestCases), tag, "sin "); + nrOfFailedTestCases += ReportTestResult( VerifyCosine (reportTestCases), tag, "cos "); + nrOfFailedTestCases += ReportTestResult( VerifyTangent (reportTestCases), tag, "tan "); + nrOfFailedTestCases += ReportTestResult( VerifyAsin (reportTestCases), tag, "asin "); + nrOfFailedTestCases += ReportTestResult( VerifyAcos (reportTestCases), tag, "acos "); + nrOfFailedTestCases += ReportTestResult( VerifyAtan (reportTestCases), tag, "atan "); + nrOfFailedTestCases += ReportTestResult( VerifySinh (reportTestCases), tag, "sinh "); + nrOfFailedTestCases += ReportTestResult( VerifyCosh (reportTestCases), tag, "cosh "); + nrOfFailedTestCases += ReportTestResult( VerifyTanh (reportTestCases), tag, "tanh "); + nrOfFailedTestCases += ReportTestResult( VerifyAsinh (reportTestCases), tag, "asinh "); + nrOfFailedTestCases += ReportTestResult( VerifyAcosh (reportTestCases), tag, "acosh "); + nrOfFailedTestCases += ReportTestResult( VerifyAtanh (reportTestCases), tag, "atanh "); + + nrOfFailedTestCases += ReportTestResult( VerifyPowerFunction (reportTestCases), tag, "pow "); #endif #endif // MANUAL_TESTING diff --git a/static/posit/specialized/posit_16_2.cpp b/static/posit/specialized/posit_16_2.cpp index a0f14a4a4..5af4e9420 100644 --- a/static/posit/specialized/posit_16_2.cpp +++ b/static/posit/specialized/posit_16_2.cpp @@ -46,16 +46,20 @@ try { constexpr unsigned nbits = NBITS_IS_16; constexpr unsigned es = ES_IS_2; - int nrOfFailedTestCases = 0; - bool reportTestCases = false; - size_t RND_TEST_CASES = 10000; - #if POSIT_FAST_POSIT_16_2 - std::cout << "Fast specialization posit<16,2> configuration tests\n"; + std::string test_suite = "Fast specialization posit<16,2>"; #else - std::cout << "Standard posit<16,2> configuration tests\n"; + std::string test_suite = "Standard posit<16,2>"; #endif + std::string test_tag = "arithmetic type tests"; + bool reportTestCases = false; + int nrOfFailedTestCases = 0; + + ReportTestSuiteHeader(test_suite, reportTestCases); + + size_t RND_TEST_CASES = 10000; + using Scalar = posit; Scalar p; std::cout << dynamic_range(p) << "\n\n"; @@ -197,9 +201,8 @@ try { testLogicOperators(a, b); testLogicOperators(b, a); - std::cout << nrOfFailedTestCases << " number of failures\n"; - - nrOfFailedTestCases = 0; // ignore failures in manual testing + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return EXIT_SUCCESS; // ignore failures #else #if REGRESSION_LEVEL_1 @@ -304,10 +307,9 @@ try { nrOfFailedTestCases += ReportTestResult(VerifyReciprocation (reportTestCases), tag, "reciprocate (native) "); #endif -#endif // MANUAL_TESTING - std::cout << std::flush; - + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); +#endif // MANUAL_TESTING } catch (char const* msg) { std::cerr << msg << std::endl; diff --git a/static/posit/specialized/posit_256_2.cpp b/static/posit/specialized/posit_256_2.cpp index fa0401738..446050fc4 100644 --- a/static/posit/specialized/posit_256_2.cpp +++ b/static/posit/specialized/posit_256_2.cpp @@ -18,11 +18,15 @@ // Standard posits with nbits = 256 have 2 exponent bits. // Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override -#define MANUAL_TESTING 0 +#define MANUAL_TESTING 1 // REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity // It is the responsibility of the regression test to organize the tests in a quartile progression. //#undef REGRESSION_LEVEL_OVERRIDE #ifndef REGRESSION_LEVEL_OVERRIDE +#undef REGRESSION_LEVEL_1 +#undef REGRESSION_LEVEL_2 +#undef REGRESSION_LEVEL_3 +#undef REGRESSION_LEVEL_4 #define REGRESSION_LEVEL_1 1 #define REGRESSION_LEVEL_2 1 #define REGRESSION_LEVEL_3 1 @@ -37,61 +41,94 @@ try { constexpr size_t nbits = 256; constexpr size_t es = 2; - int nrOfFailedTestCases = 0; - bool bReportIndividualTestCases = false; - size_t RND_TEST_CASES = 1000; - std::string tag = " posit<256,2>"; - #if POSIT_FAST_POSIT_256_2 - std::cout << "Fast specialization posit<256,2> configuration tests\n"; + std::string test_suite = "Fast specialization posit<256,2>"; #else - std::cout << "Standard posit<256,2> configuration tests\n"; + std::string test_suite = "Standard posit<256,2>"; #endif -#if MANUAL_TESTING + std::string test_tag = "arithmetic type tests"; + bool reportTestCases = false; + int nrOfFailedTestCases = 0; + ReportTestSuiteHeader(test_suite, reportTestCases); + + size_t RND_TEST_CASES = 1024; -#else posit p; std::cout << dynamic_range(p) << "\n\n"; +#if MANUAL_TESTING + + // special cases + std::cout << "Special case tests\n"; + std::string test = "Initialize to zero: "; + p = 0; + nrOfFailedTestCases += ReportCheck(test_tag, test, p.iszero()); + test = "Initialize to NAN"; + p = NAN; + nrOfFailedTestCases += ReportCheck(test_tag, test, p.isnar()); + test = "Initialize to INFINITY"; + p = INFINITY; + nrOfFailedTestCases += ReportCheck(test_tag, test, p.isnar()); + test = "sign is true"; + p = -1.0f; + nrOfFailedTestCases += ReportCheck(test_tag, test, p.sign()); + test = "is negative"; + nrOfFailedTestCases += ReportCheck(test_tag, test, p.isneg()); + test = "sign is false"; + p = +1.0f; + nrOfFailedTestCases += ReportCheck(test_tag, test, !p.sign()); + test = "is positive"; + nrOfFailedTestCases += ReportCheck(test_tag, test, p.ispos()); + + RND_TEST_CASES = 1024; + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), test_tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), test_tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), test_tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), test_tag, "division "); + + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return EXIT_SUCCESS; // ignore failures +#else + #if REGRESSION_LEVEL_1 // special cases std::cout << "Special case tests\n"; std::string test = "Initialize to zero: "; p = 0; - nrOfFailedTestCases += ReportCheck(tag, test, p.iszero()); + nrOfFailedTestCases += ReportCheck(test_tag, test, p.iszero()); test = "Initialize to NAN"; p = NAN; - nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + nrOfFailedTestCases += ReportCheck(test_tag, test, p.isnar()); test = "Initialize to INFINITY"; p = INFINITY; - nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + nrOfFailedTestCases += ReportCheck(test_tag, test, p.isnar()); test = "sign is true"; p = -1.0f; - nrOfFailedTestCases += ReportCheck(tag, test, p.sign()); + nrOfFailedTestCases += ReportCheck(test_tag, test, p.sign()); test = "is negative"; - nrOfFailedTestCases += ReportCheck(tag, test, p.isneg()); + nrOfFailedTestCases += ReportCheck(test_tag, test, p.isneg()); test = "sign is false"; p = +1.0f; - nrOfFailedTestCases += ReportCheck(tag, test, !p.sign()); + nrOfFailedTestCases += ReportCheck(test_tag, test, !p.sign()); test = "is positive"; - nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); + nrOfFailedTestCases += ReportCheck(test_tag, test, p.ispos()); RND_TEST_CASES = 1024; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), test_tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), test_tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), test_tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), test_tag, "division "); #endif #if REGRESSION_LEVEL_2 RND_TEST_CASES = 1024 * 16; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), test_tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), test_tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), test_tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), test_tag, "division "); #endif @@ -106,16 +143,16 @@ try { RND_TEST_CASES = 1024 * 1024; std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each\n"; std::cout << "Without an arithmetic reference, test failures can be ignored\n"; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), test_tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), test_tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), test_tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), test_tag, "division "); nrOfFailedTestCases = 0; #endif -#endif // MANUAL_TESTING - + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); +#endif // MANUAL_TESTING } catch (char const* msg) { std::cerr << msg << std::endl; diff --git a/static/posit/specialized/posit_256_5.cpp b/static/posit/specialized/posit_256_5.cpp index 0457228dd..078308ce6 100644 --- a/static/posit/specialized/posit_256_5.cpp +++ b/static/posit/specialized/posit_256_5.cpp @@ -18,11 +18,15 @@ // Standard posits with nbits = 256 have 5 exponent bits. // Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override -#define MANUAL_TESTING 0 +#define MANUAL_TESTING 1 // REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity // It is the responsibility of the regression test to organize the tests in a quartile progression. //#undef REGRESSION_LEVEL_OVERRIDE #ifndef REGRESSION_LEVEL_OVERRIDE +#undef REGRESSION_LEVEL_1 +#undef REGRESSION_LEVEL_2 +#undef REGRESSION_LEVEL_3 +#undef REGRESSION_LEVEL_4 #define REGRESSION_LEVEL_1 1 #define REGRESSION_LEVEL_2 1 #define REGRESSION_LEVEL_3 1 @@ -35,63 +39,96 @@ try { // configure posit<256,5> constexpr size_t nbits = 256; - constexpr size_t es = 5; - - int nrOfFailedTestCases = 0; - bool bReportIndividualTestCases = false; - size_t RND_TEST_CASES = 1000; - std::string tag = " posit<256,5>"; + constexpr size_t es = 5; #if POSIT_FAST_POSIT_256_5 - std::cout << "Fast specialization posit<256,5> configuration tests\n"; + std::string test_suite = "Fast specialization posit<256,5>"; #else - std::cout << "Standard posit<256,5> configuration tests\n"; + std::string test_suite = "Standard posit<256,5>"; #endif -#if MANUAL_TESTING + std::string test_tag = "arithmetic type tests"; + bool reportTestCases = false; + int nrOfFailedTestCases = 0; + ReportTestSuiteHeader(test_suite, reportTestCases); + + size_t RND_TEST_CASES = 1024; -#else posit p; std::cout << dynamic_range(p) << "\n\n"; +#if MANUAL_TESTING + + // special cases + std::cout << "Special case tests\n"; + std::string test = "Initialize to zero: "; + p = 0; + nrOfFailedTestCases += ReportCheck(test_tag, test, p.iszero()); + test = "Initialize to NAN"; + p = NAN; + nrOfFailedTestCases += ReportCheck(test_tag, test, p.isnar()); + test = "Initialize to INFINITY"; + p = INFINITY; + nrOfFailedTestCases += ReportCheck(test_tag, test, p.isnar()); + test = "sign is true"; + p = -1.0f; + nrOfFailedTestCases += ReportCheck(test_tag, test, p.sign()); + test = "is negative"; + nrOfFailedTestCases += ReportCheck(test_tag, test, p.isneg()); + test = "sign is false"; + p = +1.0f; + nrOfFailedTestCases += ReportCheck(test_tag, test, !p.sign()); + test = "is positive"; + nrOfFailedTestCases += ReportCheck(test_tag, test, p.ispos()); + + RND_TEST_CASES = 1024; + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), test_tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), test_tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), test_tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), test_tag, "division "); + + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return EXIT_SUCCESS; // ignore failures +#else + #if REGRESSION_LEVEL_1 // special cases std::cout << "Special case tests\n"; std::string test = "Initialize to zero: "; p = 0; - nrOfFailedTestCases += ReportCheck(tag, test, p.iszero()); + nrOfFailedTestCases += ReportCheck(test_tag, test, p.iszero()); test = "Initialize to NAN"; p = NAN; - nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + nrOfFailedTestCases += ReportCheck(test_tag, test, p.isnar()); test = "Initialize to INFINITY"; p = INFINITY; - nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + nrOfFailedTestCases += ReportCheck(test_tag, test, p.isnar()); test = "sign is true"; p = -1.0f; - nrOfFailedTestCases += ReportCheck(tag, test, p.sign()); + nrOfFailedTestCases += ReportCheck(test_tag, test, p.sign()); test = "is negative"; - nrOfFailedTestCases += ReportCheck(tag, test, p.isneg()); + nrOfFailedTestCases += ReportCheck(test_tag, test, p.isneg()); test = "sign is false"; p = +1.0f; - nrOfFailedTestCases += ReportCheck(tag, test, !p.sign()); + nrOfFailedTestCases += ReportCheck(test_tag, test, !p.sign()); test = "is positive"; - nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); + nrOfFailedTestCases += ReportCheck(test_tag, test, p.ispos()); RND_TEST_CASES = 1024; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), test_tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), test_tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), test_tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), test_tag, "division "); #endif #if REGRESSION_LEVEL_2 RND_TEST_CASES = 1024 * 16; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), test_tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), test_tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), test_tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), test_tag, "division "); #endif @@ -106,16 +143,16 @@ try { RND_TEST_CASES = 1024 * 1024; std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each\n"; std::cout << "Without an arithmetic reference, test failures can be ignored\n"; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), test_tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), test_tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), test_tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), test_tag, "division "); nrOfFailedTestCases = 0; #endif -#endif // MANUAL_TESTING - + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); +#endif // MANUAL_TESTING } catch (char const* msg) { std::cerr << msg << std::endl; diff --git a/static/posit/specialized/posit_32_2.cpp b/static/posit/specialized/posit_32_2.cpp index 3ed5dd463..5cd44ed1e 100644 --- a/static/posit/specialized/posit_32_2.cpp +++ b/static/posit/specialized/posit_32_2.cpp @@ -25,9 +25,9 @@ void CheckAddition() { posit pa, pb, pc; int fails = 0; for (int a = 0; a < 256; ++a) { - pa.set_raw_bits(a); + pa.setbits(a); for (int b = 0; b < 256; ++b) { - pb.set_raw_bits(b); + pb.setbits(b); pc = pa + pb; double da, db, dref; @@ -52,11 +52,15 @@ void CheckAddition() { } // Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override -#define MANUAL_TESTING 0 +#define MANUAL_TESTING 1 // REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity // It is the responsibility of the regression test to organize the tests in a quartile progression. //#undef REGRESSION_LEVEL_OVERRIDE #ifndef REGRESSION_LEVEL_OVERRIDE +#undef REGRESSION_LEVEL_1 +#undef REGRESSION_LEVEL_2 +#undef REGRESSION_LEVEL_3 +#undef REGRESSION_LEVEL_4 #define REGRESSION_LEVEL_1 1 #define REGRESSION_LEVEL_2 1 #define REGRESSION_LEVEL_3 1 @@ -69,19 +73,21 @@ try { // configure a posit<32,2> constexpr size_t nbits = 32; - constexpr size_t es = 2; + constexpr size_t es = 2; #if POSIT_FAST_POSIT_32_2 - std::cout << "Fast specialization posit<32,2> configuration tests\n"; + std::string test_suite = "Fast specialization posit<32,2>"; #else - std::cout << "Standard posit<32,2> configuration tests\n"; - + std::string test_suite = "Standard posit<32,2>"; #endif + std::string test_tag = "arithmetic type tests"; + bool reportTestCases = false; int nrOfFailedTestCases = 0; - bool bReportIndividualTestCases = false; - size_t RND_TEST_CASES = 5000; + ReportTestSuiteHeader(test_suite, reportTestCases); + + size_t RND_TEST_CASES = 5000; using Scalar = posit; Scalar p; @@ -91,16 +97,16 @@ try { #if MANUAL_TESTING posit a, b, c; - a.set_raw_bits(0x0aa99eea); - b.set_raw_bits(0xf97fcf40); - cout << hex_format(a) << " + " << hex_format(b) << " = " << hex_format(a + b) << endl; + a.setbits(0x0aa99eea); + b.setbits(0xf97fcf40); + std::cout << hex_format(a) << " + " << hex_format(b) << " = " << hex_format(a + b) << '\n'; c = a + b; - cout << a << " + " << b << " = " << c << endl; - cout << color_print(a) << " + " << color_print(b) << " = " << color_print(c) << endl; + std::cout << a << " + " << b << " = " << c << '\n'; + std::cout << color_print(a) << " + " << color_print(b) << " = " << color_print(c) << '\n'; c = a; c += b; - cout << a << " + " << b << " = " << c << endl; - cout << color_print(a) << " + " << color_print(b) << " = " << color_print(c) << endl; + std::cout << a << " + " << b << " = " << c << '\n'; + std::cout << color_print(a) << " + " << color_print(b) << " = " << color_print(c) << '\n'; #if 1 std::string testVector[] = { @@ -140,14 +146,44 @@ try { std::cerr << "unable to parse -" << v << "- into a posit value\n"; } else { - cout << hex_format(accu1) << " + " << hex_format(p) << endl; + std::cout << hex_format(accu1) << " + " << hex_format(p) << '\n'; accu1 = accu1 + p; accu2 += p; - cout << hex_format(accu1) << " vs " << golden[i++] << " " << accu2 << endl; + std::cout << hex_format(accu1) << " vs " << golden[i++] << " " << accu2 << '\n'; } } #endif + // special cases + std::cout << "Special case tests\n"; + std::string test = "Initialize to zero: "; + p = 0; + nrOfFailedTestCases += ReportCheck(tag, test, p.iszero()); + test = "Initialize to NAN"; + p = NAN; + nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + test = "Initialize to INFINITY"; + p = INFINITY; + nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + test = "sign is true"; + p = -1.0f; + nrOfFailedTestCases += ReportCheck(tag, test, p.sign()); + test = "is negative"; + nrOfFailedTestCases += ReportCheck(tag, test, p.isneg()); + test = "sign is false"; + p = +1.0f; + nrOfFailedTestCases += ReportCheck(tag, test, !p.sign()); + test = "is positive"; + nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); + + RND_TEST_CASES = 5000; + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return EXIT_SUCCESS; // ignore failures #else #if REGRESSION_LEVEL_1 @@ -174,10 +210,10 @@ try { nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); RND_TEST_CASES = 5000; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); #endif @@ -194,9 +230,9 @@ try { // conversion tests // internally this generators are clamped as the state space 2^33 is too big std::cout << "Assignment/conversion tests\n"; - nrOfFailedTestCases += ReportTestResult( VerifyIntegerConversion (bReportIndividualTestCases), tag, "sint32 assign (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyUintConversion (bReportIndividualTestCases), tag, "uint32 assign (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyConversion (bReportIndividualTestCases), tag, "float assign (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyIntegerConversion (reportTestCases), tag, "sint32 assign (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyUintConversion (reportTestCases), tag, "uint32 assign (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyConversion (reportTestCases), tag, "float assign (native) "); // nrOfFailedTestCases += ReportTestResult( VerifyConversionThroughRandoms (tag, true, 100), tag, "float assign "); #endif @@ -204,14 +240,14 @@ try { // arithmetic tests RND_TEST_CASES = 1024 * 1024; std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each\n"; - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "+= (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "-= (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "*= (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "/= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "+= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "-= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "*= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "/= (native) "); #endif #if REGRESSION_LEVEL_4 @@ -220,32 +256,32 @@ try { std::cout << "Elementary function tests\n"; p.minpos(); double dminpos = double(p); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SQRT, RND_TEST_CASES, dminpos), tag, "sqrt (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_EXP, RND_TEST_CASES, dminpos), tag, "exp "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_EXP2, RND_TEST_CASES, dminpos), tag, "exp2 "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_LOG, RND_TEST_CASES, dminpos), tag, "log "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_LOG2, RND_TEST_CASES, dminpos), tag, "log2 "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_LOG10, RND_TEST_CASES, dminpos), tag, "log10 "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SIN, RND_TEST_CASES, dminpos), tag, "sin "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_COS, RND_TEST_CASES, dminpos), tag, "cos "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_TAN, RND_TEST_CASES, dminpos), tag, "tan "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ASIN, RND_TEST_CASES, dminpos), tag, "asin "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ACOS, RND_TEST_CASES, dminpos), tag, "acos "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ATAN, RND_TEST_CASES, dminpos), tag, "atan "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SINH, RND_TEST_CASES, dminpos), tag, "sinh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_COSH, RND_TEST_CASES, dminpos), tag, "cosh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_TANH, RND_TEST_CASES, dminpos), tag, "tanh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ASINH, RND_TEST_CASES, dminpos), tag, "asinh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ACOSH, RND_TEST_CASES, dminpos), tag, "acosh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ATANH, RND_TEST_CASES, dminpos), tag, "atanh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_SQRT, RND_TEST_CASES, dminpos), tag, "sqrt (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_EXP, RND_TEST_CASES, dminpos), tag, "exp "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_EXP2, RND_TEST_CASES, dminpos), tag, "exp2 "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_LOG, RND_TEST_CASES, dminpos), tag, "log "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_LOG2, RND_TEST_CASES, dminpos), tag, "log2 "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_LOG10, RND_TEST_CASES, dminpos), tag, "log10 "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_SIN, RND_TEST_CASES, dminpos), tag, "sin "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_COS, RND_TEST_CASES, dminpos), tag, "cos "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_TAN, RND_TEST_CASES, dminpos), tag, "tan "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ASIN, RND_TEST_CASES, dminpos), tag, "asin "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ACOS, RND_TEST_CASES, dminpos), tag, "acos "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ATAN, RND_TEST_CASES, dminpos), tag, "atan "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_SINH, RND_TEST_CASES, dminpos), tag, "sinh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_COSH, RND_TEST_CASES, dminpos), tag, "cosh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_TANH, RND_TEST_CASES, dminpos), tag, "tanh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ASINH, RND_TEST_CASES, dminpos), tag, "asinh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ACOSH, RND_TEST_CASES, dminpos), tag, "acosh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ATANH, RND_TEST_CASES, dminpos), tag, "atanh "); // elementary functions with two operands - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_POW, RND_TEST_CASES), tag, "pow "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_POW, RND_TEST_CASES), tag, "pow "); #endif -#endif // MANUAL_TESTING - + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); +#endif // MANUAL_TESTING } catch (char const* msg) { std::cerr << msg << std::endl; diff --git a/static/posit/specialized/posit_48_2.cpp b/static/posit/specialized/posit_48_2.cpp index 37d87558a..52b1fc9c6 100644 --- a/static/posit/specialized/posit_48_2.cpp +++ b/static/posit/specialized/posit_48_2.cpp @@ -17,11 +17,15 @@ // Extended Standard posit with nbits = 48 have es = 2 exponent bits. // Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override -#define MANUAL_TESTING 0 +#define MANUAL_TESTING 1 // REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity // It is the responsibility of the regression test to organize the tests in a quartile progression. //#undef REGRESSION_LEVEL_OVERRIDE #ifndef REGRESSION_LEVEL_OVERRIDE +#undef REGRESSION_LEVEL_1 +#undef REGRESSION_LEVEL_2 +#undef REGRESSION_LEVEL_3 +#undef REGRESSION_LEVEL_4 #define REGRESSION_LEVEL_1 1 #define REGRESSION_LEVEL_2 1 #define REGRESSION_LEVEL_3 1 @@ -34,28 +38,59 @@ try { // configuring a posit<48,2> constexpr size_t nbits = 48; - constexpr size_t es = 2; + constexpr size_t es = 2; +#if POSIT_FAST_POSIT_48_2 + std::string test_suite = "Fast specialization posit<48,2>"; +#else + std::string test_suite = "Standard posit<48,2>"; +#endif + + std::string test_tag = "arithmetic type tests"; + bool reportTestCases = false; int nrOfFailedTestCases = 0; - bool bReportIndividualTestCases = false; - size_t RND_TEST_CASES = 10000; + + ReportTestSuiteHeader(test_suite, reportTestCases); + + size_t RND_TEST_CASES = 1024; using Scalar = posit; Scalar p; std::cout << dynamic_range(p) << "\n\n"; std::string tag = type_tag(p); -#if POSIT_FAST_POSIT_48_2 - std::cout << "Fast specialization posit<48,2> configuration tests\n"; -#else - std::cout << "Extended Standard posit<48,2> configuration tests\n"; -#endif - #if MANUAL_TESTING + // special cases + std::cout << "Special case tests\n"; + std::string test = "Initialize to zero: "; + p = 0; + nrOfFailedTestCases += ReportCheck(tag, test, p.iszero()); + test = "Initialize to NAN"; + p = NAN; + nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + test = "Initialize to INFINITY"; + p = INFINITY; + nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + test = "sign is true"; + p = -1.0f; + nrOfFailedTestCases += ReportCheck(tag, test, p.sign()); + test = "is negative"; + nrOfFailedTestCases += ReportCheck(tag, test, p.isneg()); + test = "sign is false"; + p = +1.0f; + nrOfFailedTestCases += ReportCheck(tag, test, !p.sign()); + test = "is positive"; + nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); -#else - + RND_TEST_CASES = 1024; + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return EXIT_SUCCESS; // ignore failures +#else #if REGRESSION_LEVEL_1 // special cases @@ -81,10 +116,10 @@ try { nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); RND_TEST_CASES = 1024; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); #endif @@ -102,17 +137,15 @@ try { RND_TEST_CASES = 1024 * 16; std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each\n"; std::cout << "Without an arithmetic reference, test failures can be ignored\n"; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); - - nrOfFailedTestCases = 0; + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); #endif -#endif // MANUAL_TESTING - + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); +#endif // MANUAL_TESTING } catch (char const* msg) { std::cerr << msg << std::endl; diff --git a/static/posit/specialized/posit_64_2.cpp b/static/posit/specialized/posit_64_2.cpp index 837271024..d40b9015e 100644 --- a/static/posit/specialized/posit_64_2.cpp +++ b/static/posit/specialized/posit_64_2.cpp @@ -17,7 +17,7 @@ // Standard posit with nbits = 64 have es = 2 exponent bits. // Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override -#define MANUAL_TESTING 0 +#define MANUAL_TESTING 1 // REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity // It is the responsibility of the regression test to organize the tests in a quartile progression. //#undef REGRESSION_LEVEL_OVERRIDE @@ -40,16 +40,20 @@ try { constexpr size_t nbits = 64; constexpr size_t es = 2; - int nrOfFailedTestCases = 0; - bool bReportIndividualTestCases = false; - size_t RND_TEST_CASES = 1000; - #if POSIT_FAST_POSIT_64_2 - std::cout << "Fast specialization posit<64,2> configuration tests\n"; + std::string test_suite = "Fast specialization posit<64,2>"; #else - std::cout << "Standard posit<64,2> configuration tests\n"; + std::string test_suite = "Standard posit<64,2>"; #endif + std::string test_tag = "arithmetic type tests"; + bool reportTestCases = false; + int nrOfFailedTestCases = 0; + + ReportTestSuiteHeader(test_suite, reportTestCases); + + size_t RND_TEST_CASES = 1024; + using Scalar = posit; Scalar p; std::cout << dynamic_range(p) << "\n\n"; @@ -77,6 +81,36 @@ try { // 32 bit posit around 1.0: 1 sign bit, 2 regime bits, 2 exponent bits = 32 -5 = 27 mantissa bits // 3.3 bits per decimal: 27 mantissa bits -> between 8 and 9 decimal bits + // special cases + std::cout << "Special case tests\n"; + std::string test = "Initialize to zero: "; + p = 0; + nrOfFailedTestCases += ReportCheck(tag, test, p.iszero()); + test = "Initialize to NAN"; + p = NAN; + nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + test = "Initialize to INFINITY"; + p = INFINITY; + nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + test = "sign is true"; + p = -1.0f; + nrOfFailedTestCases += ReportCheck(tag, test, p.sign()); + test = "is negative"; + nrOfFailedTestCases += ReportCheck(tag, test, p.isneg()); + test = "sign is false"; + p = +1.0f; + nrOfFailedTestCases += ReportCheck(tag, test, !p.sign()); + test = "is positive"; + nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); + + RND_TEST_CASES = 1024; + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return EXIT_SUCCESS; // ignore failures #else #if REGRESSION_LEVEL_1 @@ -103,10 +137,10 @@ try { nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); RND_TEST_CASES = 1024; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); #endif @@ -123,23 +157,23 @@ try { // conversion tests // internally this generators are clamped as the state space 2^33 is too big std::cout << "Assignment/conversion tests\n"; - nrOfFailedTestCases += ReportTestResult( VerifyIntegerConversion (bReportIndividualTestCases), tag, "sint32 assign (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyUintConversion (bReportIndividualTestCases), tag, "uint32 assign (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyConversion (bReportIndividualTestCases), tag, "float assign (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyIntegerConversion (reportTestCases), tag, "sint32 assign (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyUintConversion (reportTestCases), tag, "uint32 assign (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyConversion (reportTestCases), tag, "float assign (native) "); // nrOfFailedTestCases += ReportTestResult( VerifyConversionThroughRandoms (tag, true, 100), tag, "float assign "); #endif #if REGRESSION_LEVEL_3 // arithmetic tests std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each\n"; - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "+= (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "-= (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "*= (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "/= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "+= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "-= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "*= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "/= (native) "); #endif @@ -148,34 +182,31 @@ try { std::cout << "Elementary function tests\n"; p.minpos(); double dminpos = double(p); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SQRT, RND_TEST_CASES, dminpos), tag, "sqrt (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_EXP, RND_TEST_CASES, dminpos), tag, "exp "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_EXP2, RND_TEST_CASES, dminpos), tag, "exp2 "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_LOG, RND_TEST_CASES, dminpos), tag, "log "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_LOG2, RND_TEST_CASES, dminpos), tag, "log2 "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_LOG10, RND_TEST_CASES, dminpos), tag, "log10 "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SIN, RND_TEST_CASES, dminpos), tag, "sin "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_COS, RND_TEST_CASES, dminpos), tag, "cos "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_TAN, RND_TEST_CASES, dminpos), tag, "tan "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ASIN, RND_TEST_CASES, dminpos), tag, "asin "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ACOS, RND_TEST_CASES, dminpos), tag, "acos "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ATAN, RND_TEST_CASES, dminpos), tag, "atan "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SINH, RND_TEST_CASES, dminpos), tag, "sinh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_COSH, RND_TEST_CASES, dminpos), tag, "cosh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_TANH, RND_TEST_CASES, dminpos), tag, "tanh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ASINH, RND_TEST_CASES, dminpos), tag, "asinh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ACOSH, RND_TEST_CASES, dminpos), tag, "acosh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ATANH, RND_TEST_CASES, dminpos), tag, "atanh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_SQRT, RND_TEST_CASES, dminpos), tag, "sqrt (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_EXP, RND_TEST_CASES, dminpos), tag, "exp "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_EXP2, RND_TEST_CASES, dminpos), tag, "exp2 "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_LOG, RND_TEST_CASES, dminpos), tag, "log "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_LOG2, RND_TEST_CASES, dminpos), tag, "log2 "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_LOG10, RND_TEST_CASES, dminpos), tag, "log10 "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_SIN, RND_TEST_CASES, dminpos), tag, "sin "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_COS, RND_TEST_CASES, dminpos), tag, "cos "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_TAN, RND_TEST_CASES, dminpos), tag, "tan "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ASIN, RND_TEST_CASES, dminpos), tag, "asin "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ACOS, RND_TEST_CASES, dminpos), tag, "acos "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ATAN, RND_TEST_CASES, dminpos), tag, "atan "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_SINH, RND_TEST_CASES, dminpos), tag, "sinh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_COSH, RND_TEST_CASES, dminpos), tag, "cosh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_TANH, RND_TEST_CASES, dminpos), tag, "tanh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ASINH, RND_TEST_CASES, dminpos), tag, "asinh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ACOSH, RND_TEST_CASES, dminpos), tag, "acosh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ATANH, RND_TEST_CASES, dminpos), tag, "atanh "); // elementary functions with two operands - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_POW, RND_TEST_CASES), tag, "pow "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_POW, RND_TEST_CASES), tag, "pow "); #endif -#endif // !MANUAL_TESTING - - // TODO: as we don't have a reference floating point implementation to Verify - // the arithmetic operations we are going to ignore the failures - nrOfFailedTestCases = 0; + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); +#endif // MANUAL_TESTING } catch (char const* msg) { std::cerr << msg << std::endl; diff --git a/static/posit/specialized/posit_64_3.cpp b/static/posit/specialized/posit_64_3.cpp index f73f54aee..20e33c812 100644 --- a/static/posit/specialized/posit_64_3.cpp +++ b/static/posit/specialized/posit_64_3.cpp @@ -17,11 +17,15 @@ // Standard posit with nbits = 64 have es = 3 exponent bits. // Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override -#define MANUAL_TESTING 0 +#define MANUAL_TESTING 1 // REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity // It is the responsibility of the regression test to organize the tests in a quartile progression. //#undef REGRESSION_LEVEL_OVERRIDE #ifndef REGRESSION_LEVEL_OVERRIDE +#undef REGRESSION_LEVEL_1 +#undef REGRESSION_LEVEL_2 +#undef REGRESSION_LEVEL_3 +#undef REGRESSION_LEVEL_4 #define REGRESSION_LEVEL_1 1 #define REGRESSION_LEVEL_2 1 #define REGRESSION_LEVEL_3 1 @@ -34,25 +38,58 @@ try { // configure a posit<64,3> constexpr size_t nbits = 64; - constexpr size_t es = 3; - - int nrOfFailedTestCases = 0; - bool bReportIndividualTestCases = false; - size_t RND_TEST_CASES = 1000; + constexpr size_t es = 3; #if POSIT_FAST_POSIT_64_3 - std::cout << "Fast specialization posit<64,3> configuration tests\n"; + std::string test_suite = "Fast specialization posit<64,3>"; #else - std::cout << "Standard posit<64,3> configuration tests\n"; + std::string test_suite = "Standard posit<64,3>"; #endif + std::string test_tag = "arithmetic type tests"; + bool reportTestCases = false; + int nrOfFailedTestCases = 0; + + ReportTestSuiteHeader(test_suite, reportTestCases); + + size_t RND_TEST_CASES = 5000; + using Scalar = posit; Scalar p; std::cout << dynamic_range(p) << "\n\n"; std::string tag = type_tag(p); #if MANUAL_TESTING + // special cases + std::cout << "Special case tests\n"; + std::string test = "Initialize to zero: "; + p = 0; + nrOfFailedTestCases += ReportCheck(tag, test, p.iszero()); + test = "Initialize to NAN"; + p = NAN; + nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + test = "Initialize to INFINITY"; + p = INFINITY; + nrOfFailedTestCases += ReportCheck(tag, test, p.isnar()); + test = "sign is true"; + p = -1.0f; + nrOfFailedTestCases += ReportCheck(tag, test, p.sign()); + test = "is negative"; + nrOfFailedTestCases += ReportCheck(tag, test, p.isneg()); + test = "sign is false"; + p = +1.0f; + nrOfFailedTestCases += ReportCheck(tag, test, !p.sign()); + test = "is positive"; + nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); + RND_TEST_CASES = 1024; + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return EXIT_SUCCESS; // ignore failures #else #if REGRESSION_LEVEL_1 @@ -79,10 +116,10 @@ try { nrOfFailedTestCases += ReportCheck(tag, test, p.ispos()); RND_TEST_CASES = 1024; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); #endif @@ -99,23 +136,23 @@ try { // conversion tests // internally this generators are clamped as the state space 2^33 is too big std::cout << "Assignment/conversion tests\n"; - nrOfFailedTestCases += ReportTestResult( VerifyIntegerConversion (bReportIndividualTestCases), tag, "sint32 assign (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyUintConversion (bReportIndividualTestCases), tag, "uint32 assign (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyConversion (bReportIndividualTestCases), tag, "float assign (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyIntegerConversion (reportTestCases), tag, "sint32 assign (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyUintConversion (reportTestCases), tag, "uint32 assign (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyConversion (reportTestCases), tag, "float assign (native) "); // nrOfFailedTestCases += ReportTestResult( VerifyConversionThroughRandoms (tag, true, 100), tag, "float assign "); #endif #if REGRESSION_LEVEL_3 // arithmetic tests std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each\n"; - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "+= (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "-= (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "*= (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "/= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "+= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "-= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "*= (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "/= (native) "); #endif @@ -124,34 +161,31 @@ try { std::cout << "Elementary function tests\n"; p.minpos(); double dminpos = double(p); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SQRT, RND_TEST_CASES, dminpos), tag, "sqrt (native) "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_EXP, RND_TEST_CASES, dminpos), tag, "exp "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_EXP2, RND_TEST_CASES, dminpos), tag, "exp2 "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_LOG, RND_TEST_CASES, dminpos), tag, "log "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_LOG2, RND_TEST_CASES, dminpos), tag, "log2 "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_LOG10, RND_TEST_CASES, dminpos), tag, "log10 "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SIN, RND_TEST_CASES, dminpos), tag, "sin "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_COS, RND_TEST_CASES, dminpos), tag, "cos "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_TAN, RND_TEST_CASES, dminpos), tag, "tan "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ASIN, RND_TEST_CASES, dminpos), tag, "asin "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ACOS, RND_TEST_CASES, dminpos), tag, "acos "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ATAN, RND_TEST_CASES, dminpos), tag, "atan "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_SINH, RND_TEST_CASES, dminpos), tag, "sinh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_COSH, RND_TEST_CASES, dminpos), tag, "cosh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_TANH, RND_TEST_CASES, dminpos), tag, "tanh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ASINH, RND_TEST_CASES, dminpos), tag, "asinh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ACOSH, RND_TEST_CASES, dminpos), tag, "acosh "); - nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ATANH, RND_TEST_CASES, dminpos), tag, "atanh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_SQRT, RND_TEST_CASES, dminpos), tag, "sqrt (native) "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_EXP, RND_TEST_CASES, dminpos), tag, "exp "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_EXP2, RND_TEST_CASES, dminpos), tag, "exp2 "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_LOG, RND_TEST_CASES, dminpos), tag, "log "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_LOG2, RND_TEST_CASES, dminpos), tag, "log2 "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_LOG10, RND_TEST_CASES, dminpos), tag, "log10 "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_SIN, RND_TEST_CASES, dminpos), tag, "sin "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_COS, RND_TEST_CASES, dminpos), tag, "cos "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_TAN, RND_TEST_CASES, dminpos), tag, "tan "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ASIN, RND_TEST_CASES, dminpos), tag, "asin "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ACOS, RND_TEST_CASES, dminpos), tag, "acos "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ATAN, RND_TEST_CASES, dminpos), tag, "atan "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_SINH, RND_TEST_CASES, dminpos), tag, "sinh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_COSH, RND_TEST_CASES, dminpos), tag, "cosh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_TANH, RND_TEST_CASES, dminpos), tag, "tanh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ASINH, RND_TEST_CASES, dminpos), tag, "asinh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ACOSH, RND_TEST_CASES, dminpos), tag, "acosh "); + nrOfFailedTestCases += ReportTestResult( VerifyUnaryOperatorThroughRandoms(reportTestCases, OPCODE_ATANH, RND_TEST_CASES, dminpos), tag, "atanh "); // elementary functions with two operands - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_POW, RND_TEST_CASES), tag, "pow "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_POW, RND_TEST_CASES), tag, "pow "); #endif -#endif // !MANUAL_TESTING - - // TODO: as we don't have a reference floating point implementation to Verify - // the arithmetic operations we are going to ignore the failures - nrOfFailedTestCases = 0; + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); +#endif // MANUAL_TESTING } catch (char const* msg) { std::cerr << msg << std::endl; diff --git a/static/posit/specialized/quire_32_2.cpp b/static/posit/specialized/quire_32_2.cpp index 7348abcac..7fb3648f8 100644 --- a/static/posit/specialized/quire_32_2.cpp +++ b/static/posit/specialized/quire_32_2.cpp @@ -8,7 +8,7 @@ // Configure the posit template environment // first: enable fast specialized posit<32,2> //#define POSIT_FAST_SPECIALIZATION // turns on all fast specializations -#define POSIT_FAST_POSIT_32_2 1 +#define POSIT_FAST_POSIT_32_2 0 // second: enable posit arithmetic exceptions #define POSIT_THROW_ARITHMETIC_EXCEPTION 1 #include @@ -28,29 +28,30 @@ int main() try { using namespace sw::universal; - constexpr size_t RND_TEST_CASES = 500000; - constexpr size_t nbits = 32; - constexpr size_t es = 2; - - int nrOfFailedTestCases = 0; - bool bReportIndividualTestCases = false; - std::string tag = " quire<32,2>"; + constexpr size_t es = 2; #if POSIT_FAST_POSIT_32_2 - std::cout << "Fast specialization quire<32,2> configuration tests\n"; + std::string test_suite = "Fast specialization quire<32,2>"; #else - std::cout << "Standard quire<32,2> configuration tests\n"; + std::string test_suite = "Standard quire<32,2>"; #endif + std::string test_tag = "arithmetic type tests"; + bool reportTestCases = false; + int nrOfFailedTestCases = 0; + + ReportTestSuiteHeader(test_suite, reportTestCases); + + constexpr size_t RND_TEST_CASES = 500000; + quire q; std::cout << dynamic_range() << "\n\n"; // special cases std::cout << "Special case tests\n"; - std::string test = "Initialize to zero: "; q = 0; - nrOfFailedTestCases += ReportCheck(tag, test, q.iszero()); + nrOfFailedTestCases += ReportCheck(test_tag, "Initialize to zero", q.iszero()); // logic tests // cout << "Logic operator tests " << endl; @@ -63,12 +64,10 @@ try { // arithmetic tests std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each\n"; - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition (native) "); - nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication (native) "); - - // elementary function tests -// cout << "Elementary function tests " << endl; + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_ADD, RND_TEST_CASES), test_tag, "addition (native) "); + nrOfFailedTestCases += ReportTestResult(VerifyBinaryOperatorThroughRandoms(reportTestCases, OPCODE_MUL, RND_TEST_CASES), test_tag, "multiplication (native) "); + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } catch (char const* msg) {