Skip to content

Commit

Permalink
bringing areal forward to the new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Oct 15, 2021
1 parent 3c76d33 commit 86f8c8f
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 225 deletions.
8 changes: 8 additions & 0 deletions include/universal/number/areal/areal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
#ifndef _AREAL_STANDARD_HEADER_
#define _AREAL_STANDARD_HEADER_

////////////////////////////////////////////////////////////////////////////////////////
/// COMPILATION DIRECTIVES TO DIFFERENT COMPILERS

// compiler specific configuration for long double support
#include <universal/utility/long_double.hpp>
// compiler specific configuration for C++20 bit_cast
#include <universal/utility/bit_cast.hpp>

////////////////////////////////////////////////////////////////////////////////////////
/// BEHAVIORAL COMPILATION SWITCHES

Expand Down
14 changes: 8 additions & 6 deletions include/universal/number/areal/areal_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,17 +1036,17 @@ class areal {
void constexprClassParameters() const {
std::cout << "nbits : " << nbits << '\n';
std::cout << "es : " << es << std::endl;
std::cout << "ALLONES : " << to_binary(ALLONES, true) << '\n';
std::cout << "BLOCK_MASK : " << to_binary(BLOCK_MASK, true) << '\n';
std::cout << "ALLONES : " << to_binary(ALLONES, bitsInBlock, true) << '\n';
std::cout << "BLOCK_MASK : " << to_binary(BLOCK_MASK, bitsInBlock, true) << '\n';
std::cout << "nrBlocks : " << nrBlocks << '\n';
std::cout << "bits in MSU : " << bitsInMSU << '\n';
std::cout << "MSU : " << MSU << '\n';
std::cout << "MSU MASK : " << to_binary(MSU_MASK, true) << '\n';
std::cout << "SIGN_BIT_MASK : " << to_binary(SIGN_BIT_MASK, true) << '\n';
std::cout << "LSB_BIT_MASK : " << to_binary(LSB_BIT_MASK, true) << '\n';
std::cout << "MSU MASK : " << to_binary(MSU_MASK, bitsInBlock, true) << '\n';
std::cout << "SIGN_BIT_MASK : " << to_binary(SIGN_BIT_MASK, bitsInBlock, true) << '\n';
std::cout << "LSB_BIT_MASK : " << to_binary(LSB_BIT_MASK, bitsInBlock, true) << '\n';
std::cout << "MSU CAPTURES E : " << (MSU_CAPTURES_E ? "yes\n" : "no\n");
std::cout << "EXP_SHIFT : " << EXP_SHIFT << '\n';
std::cout << "MSU EXP MASK : " << to_binary(MSU_EXP_MASK, true) << '\n';
std::cout << "MSU EXP MASK : " << to_binary(MSU_EXP_MASK, bitsInBlock, true) << '\n';
std::cout << "EXP_BIAS : " << EXP_BIAS << '\n';
std::cout << "MAX_EXP : " << MAX_EXP << '\n';
std::cout << "MIN_EXP_NORMAL : " << MIN_EXP_NORMAL << '\n';
Expand Down Expand Up @@ -1460,6 +1460,7 @@ inline std::string to_binary(const areal<nbits, es, bt>& number, bool nibbleMark
return ss.str();
}

#ifdef DEPRECATED
// helper to report on BlockType blocks
template<typename bt>
inline std::string to_binary(const bt& number, bool nibbleMarker) {
Expand All @@ -1476,6 +1477,7 @@ inline std::string to_binary(const bt& number, bool nibbleMarker) {
}
return ss.str();
}
#endif

/// Magnitude of a scientific notation value (equivalent to turning the sign bit off).
template<size_t nbits, size_t es, typename bt>
Expand Down
5 changes: 3 additions & 2 deletions include/universal/verification/areal_test_suite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <limits>

#include <universal/math/stub/classify.hpp> // fpclassify, isnormal, issubnormal, isinf, isnan
#include <universal/verification/test_reporters.hpp>

namespace sw::universal {

Expand Down Expand Up @@ -171,7 +172,7 @@ namespace sw::universal {
std::cout << "interval: " << to_binary(previousInterval) << " : " << previousInterval << std::endl;
std::cout << "current : " << to_binary(current) << " : " << current << std::endl;
std::cout << "interval: " << to_binary(interval) << " : " << interval << std::endl;
std::cout << "delta : " << delta << " : " << to_binary(delta, true) << std::endl;
std::cout << "delta : " << delta << " : " << to_binary(delta) << std::endl;
}
// da - delta = (prev,current) == previous + ubit = previous interval value
testValue = da - delta;
Expand All @@ -191,7 +192,7 @@ namespace sw::universal {
std::cout << "interval: " << to_binary(previousInterval) << " : " << previousInterval << std::endl;
std::cout << "current : " << to_binary(current) << " : " << current << std::endl;
std::cout << "interval: " << to_binary(interval) << " : " << interval << std::endl;
std::cout << "delta : " << delta << " : " << to_binary(delta, true) << std::endl;
std::cout << "delta : " << delta << " : " << to_binary(delta) << std::endl;
}

}
Expand Down
14 changes: 4 additions & 10 deletions tests/areal/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,20 @@
#include <iomanip>
#include <fstream>
#include <typeinfo>
// minimum set of include files to reflect source code dependencies
#include <universal/number/areal/areal_impl.hpp>
#include <universal/number/areal/manipulators.hpp> // hex_print and the like

#include <universal/number/areal/areal.hpp>
#include <universal/verification/test_suite_arithmetic.hpp>

#define MANUAL_TESTING 1
#define STRESS_TESTING 0

int main(int argc, char** argv)
int main()
try {
using namespace sw::universal;

if (argc > 0) {
std::cout << argv[0] << std::endl;
}
// const size_t RND_TEST_CASES = 0; // no randoms, 8-bit posits can be done exhaustively

std::cout << "areal<> Application Programming Interface tests" << std::endl;
int nrOfFailedTestCases = 0;

std::cout << "areal<> Application Programming Interface tests" << std::endl;

#if MANUAL_TESTING

Expand Down
49 changes: 23 additions & 26 deletions tests/areal/api/assignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
#define AREAL_THROW_ARITHMETIC_EXCEPTION 0
// enabling tracing
#define TRACE_CONVERSION 0
// minimum set of include files to reflect source code dependencies
#include <universal/number/areal/areal_impl.hpp>
// fixed-point type manipulators such as pretty printers
#include <universal/number/areal/manipulators.hpp>
#include <universal/number/areal/math_functions.hpp>

#include <universal/number/areal/areal.hpp>
#include <universal/verification/test_suite_arithmetic.hpp>
#include <universal/number/areal/table.hpp>

Expand Down Expand Up @@ -438,11 +435,12 @@ int main(int argc, char** argv)
try {
using namespace sw::universal;

std::string test_suite = "areal assignment";
std::string test_tag = "assignment";
std::cout << test_suite << '\n';
bool bReportIndividualTestCases = false;
int nrOfFailedTestCases = 0;

std::string tag = "AREAL assignment: ";

#if MANUAL_TESTING

using Real = sw::universal::areal<8, 2>;
Expand Down Expand Up @@ -503,7 +501,6 @@ try {
nrOfFailedTestCases = 0; // disregard any test failures in manual testing mode

#else
std::cout << "AREAL assignment validation\n";

bool bVerbose = false;

Expand All @@ -514,34 +511,34 @@ try {
nrOfFailedTestCases += VerifySpecialCases<Real, long double>("long double->areal special cases");

std::cout << "Single block representations\n--------------------------------------------- es = 1 encodings\n";
nrOfFailedTestCases += TestSingleBlockRepresentations<1, float>(tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestSingleBlockRepresentations<1, double>(tag, "=double", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestSingleBlockRepresentations<1, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestSingleBlockRepresentations<1, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose);
std::cout << "--------------------------------------------- es = 2 encodings\n";
nrOfFailedTestCases += TestSingleBlockRepresentations<2, float>(tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestSingleBlockRepresentations<2, double>(tag, "=double", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestSingleBlockRepresentations<2, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestSingleBlockRepresentations<2, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose);
std::cout << "--------------------------------------------- es = 3 encodings\n";
nrOfFailedTestCases += TestSingleBlockRepresentations<3, float>(tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestSingleBlockRepresentations<3, double>(tag, "=double", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestSingleBlockRepresentations<3, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestSingleBlockRepresentations<3, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose);
std::cout << "--------------------------------------------- es = 4 encodings\n";
nrOfFailedTestCases += TestSingleBlockRepresentations<4, float>(tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestSingleBlockRepresentations<4, double>(tag, "=double", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestSingleBlockRepresentations<4, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestSingleBlockRepresentations<4, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose);

std::cout << "Double block representations\n--------------------------------------------- es = 1 encodings\n";
nrOfFailedTestCases += TestDoubleBlockRepresentations<1, float>(tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestDoubleBlockRepresentations<1, double>(tag, "=double", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestDoubleBlockRepresentations<1, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestDoubleBlockRepresentations<1, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose);
std::cout << "--------------------------------------------- es = 2 encodings\n";
nrOfFailedTestCases += TestDoubleBlockRepresentations<2, float>(tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestDoubleBlockRepresentations<2, double>(tag, "=double", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestDoubleBlockRepresentations<2, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestDoubleBlockRepresentations<2, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose);
std::cout << "--------------------------------------------- es = 3 encodings\n";
nrOfFailedTestCases += TestDoubleBlockRepresentations<3, float>(tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestDoubleBlockRepresentations<3, double>(tag, "=double", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestDoubleBlockRepresentations<3, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestDoubleBlockRepresentations<3, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose);
std::cout << "--------------------------------------------- es = 4 encodings\n";
nrOfFailedTestCases += TestDoubleBlockRepresentations<4, float>(tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestDoubleBlockRepresentations<4, double>(tag, "=double", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestDoubleBlockRepresentations<4, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestDoubleBlockRepresentations<4, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose);

std::cout << "Triple block representations\n--------------------------------------------- es = 1 encodings\n";
nrOfFailedTestCases += TestTripleBlockRepresentations<1, float>(tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestTripleBlockRepresentations<1, double>(tag, "=double", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestTripleBlockRepresentations<1, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose);
nrOfFailedTestCases += TestTripleBlockRepresentations<1, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose);


/*
Expand Down
20 changes: 5 additions & 15 deletions tests/areal/api/constexpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@
// second: enable/disable areal arithmetic exceptions
#define AREAL_THROW_ARITHMETIC_EXCEPTION 1

// minimum set of include files to reflect source code dependencies
#include <universal/number/areal/areal_impl.hpp>
// fixed-point type manipulators such as pretty printers
#include <universal/number/areal/manipulators.hpp>
#include <universal/number/areal/math_functions.hpp>
#include <universal/number/areal/areal.hpp>
#include <universal/verification/test_reporters.hpp>

#if BIT_CAST_SUPPORT
// stylistic constexpr of pi that we'll assign constexpr to an areal
constexpr double pi = 3.14159265358979323846;
#endif // BIT_CAST_SUPPORT

template<typename Real>
void TestConstexprConstruction() {
Expand Down Expand Up @@ -112,9 +107,9 @@ int main()
try {
using namespace sw::universal;

std::string test_suite = "areal constexpr ";
std::cout << test_suite << '\n';
int nrOfFailedTestCases = 0;

std::cout << "AREAL constexpr tests\n";

using Real = areal<12, 2>;
Real a;
Expand All @@ -124,12 +119,7 @@ try {
TestConstexprAssignment<Real>();
TestConstexprSpecificValues<Real>();

if (nrOfFailedTestCases > 0) {
std::cout << "FAIL\n";
}
else {
std::cout << "PASS\n";
}
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
}
catch (char const* msg) {
Expand Down
5 changes: 2 additions & 3 deletions tests/areal/api/special_cases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
#include <iomanip>
#include <fstream>
#include <typeinfo>
// minimum set of include files to reflect source code dependencies
#include <universal/number/areal/areal_impl.hpp>
#include <universal/number/areal/manipulators.hpp> // hex_print and the like

#include <universal/number/areal/areal.hpp>
#include <universal/verification/test_suite_arithmetic.hpp>
#include <universal/number/areal/table.hpp>

Expand Down
4 changes: 2 additions & 2 deletions tests/areal/arithmetic/addition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#pragma warning(disable : 4710) // function is not inlined
#pragma warning(disable : 5045) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
#endif
// minimum set of include files to reflect source code dependencies
#include <universal/number/areal/areal_impl.hpp>

#include <universal/number/areal/areal.hpp>
#include <universal/verification/test_status.hpp>
#include <universal/verification/test_case.hpp>
#include <universal/verification/test_suite_arithmetic.hpp>
Expand Down
5 changes: 1 addition & 4 deletions tests/areal/conversion/double_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
// third: enable trace conversion
#define TRACE_CONVERSION 0

// minimum set of include files to reflect source code dependencies
#include <universal/number/areal/areal_impl.hpp>
#include <universal/number/areal/manipulators.hpp>
#include <universal/number/areal/math_functions.hpp>
#include <universal/number/areal/areal.hpp>
#include <universal/verification/test_suite_arithmetic.hpp>
#include <universal/verification/areal_test_suite.hpp>
#include <universal/number/areal/table.hpp> // only used for value table generation
Expand Down
5 changes: 1 addition & 4 deletions tests/areal/conversion/float_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
// third: enable trace conversion
#define TRACE_CONVERSION 0

// minimum set of include files to reflect source code dependencies
#include <universal/number/areal/areal_impl.hpp>
#include <universal/number/areal/manipulators.hpp>
#include <universal/number/areal/math_functions.hpp>
#include <universal/number/areal/areal.hpp>
#include <universal/verification/test_suite_arithmetic.hpp>
#include <universal/verification/areal_test_suite.hpp>
#include <universal/number/areal/table.hpp> // only used for value table generation
Expand Down
5 changes: 1 addition & 4 deletions tests/areal/conversion/sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
// second: enable/disable arithmetic exceptions
#define AREAL_THROW_ARITHMETIC_EXCEPTION 0

// minimum set of include files to reflect source code dependencies
#include <universal/number/areal/areal_impl.hpp>
#include <universal/number/areal/manipulators.hpp>
#include <universal/number/areal/math_functions.hpp>
#include <universal/number/areal/areal.hpp>
#include <universal/verification/test_suite_arithmetic.hpp>


Expand Down
3 changes: 1 addition & 2 deletions tests/areal/logic/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

// minimum set of include files to reflect source code dependencies
#include <universal/number/areal/areal_impl.hpp>
#include <universal/number/areal/areal.hpp>
#include <universal/verification/test_status.hpp>

namespace sw::universal {
Expand Down
30 changes: 4 additions & 26 deletions tests/areal/standard/double_precision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,27 @@
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <iostream>
#include <iomanip>
// minimum set of include files to reflect source code dependencies
#include <universal/number/cfloat/cfloat_impl.hpp>

#include <universal/number/areal/areal.hpp>
#include <universal/verification/test_suite_arithmetic.hpp>

int main(int argc, char** argv)
try {
using namespace sw::universal;

//const size_t RND_TEST_CASES = 500000;

constexpr size_t nbits = 64;
constexpr size_t es = 11;

int nrOfFailedTestCases = 0;
std::string tag = " cfloat<64,11>";

std::cout << "Standard double-precision cfloat<64,52> configuration tests\n";

cfloat<nbits, es> r;
r = 1.2345;
std::cout << r << '\n';

#if 0
std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each" << std::endl;
bool bReportIndividualTestCases = false;

nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms<nbits, es>(tag, bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition ");
nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms<nbits, es>(tag, bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction ");
nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms<nbits, es>(tag, bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication");
nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms<nbits, es>(tag, bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division ");
#endif

return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
}
catch (char const* msg) {
std::cerr << "Caught exception: " << msg << std::endl;
return EXIT_FAILURE;
}
catch (const sw::universal::cfloat_arithmetic_exception& err) {
catch (const sw::universal::areal_arithmetic_exception& err) {
std::cerr << "Uncaught real arithmetic exception: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (const sw::universal::cfloat_internal_exception& err) {
catch (const sw::universal::areal_internal_exception& err) {
std::cerr << "Uncaught real internal exception: " << err.what() << std::endl;
return EXIT_FAILURE;
}
Expand Down
Loading

0 comments on commit 86f8c8f

Please sign in to comment.