Skip to content

Commit

Permalink
bringing together all the complex<> regression suites into a consiste…
Browse files Browse the repository at this point in the history
…nt build flow
  • Loading branch information
Ravenwater committed Aug 28, 2024
1 parent 99f13b9 commit 4efbc00
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 16 deletions.
3 changes: 2 additions & 1 deletion applications/performance/complex/compute.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// compute.cpp: experiments with complex real/imaginary computations
//
// Copyright (C) 2017-2021 Stillwater Supercomputing, Inc.
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal number project, which is released under an MIT Open Source license.
#include <math.h>
Expand Down
7 changes: 3 additions & 4 deletions playground/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ compile_all("true" "playground" "Playground" "${REAL_SRCS}")

# NOTE: AppleClang as XCode14 and Xcode15 have std::complex libs that do not support user defined types5
if(BUILD_COMPLEX)
message(STATUS "Adding playground complex test")
compile_all("true" "playground" "Complex/Playground" "${COMPLEX_SRCS}")

message(STATUS "Adding playground complex experiment")
compile_all("true" "playground_cmplx" "Complex/Playground" "${COMPLEX_SRCS}")
else(BUILD_COMPLEX)
message(STATUS "Removing complex environment test from Playground")
message(STATUS "Removing complex environment experiment in the Playground")
endif(BUILD_COMPLEX)
17 changes: 17 additions & 0 deletions static/cfloat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ file (GLOB ARITHMETIC_SRC "arithmetic/*.cpp")
file (GLOB STANDARD_SRC "standard/*.cpp")
file (GLOB MATH_SRC "./math/*.cpp")
file (GLOB PERFORMANCE_SRC "./performance/*.cpp")
file (GLOB COMPLEX_ARITHMETIC_SRC "./complex/arithmetic/*.cpp")
file (GLOB COMPLEX_MATH_SRC "./complex/math/*.cpp")

# cfloat test suites
compile_all("true" "cfloat" "Number Systems/static/floating-point/binary/cfloat/api" "${API_SRC}")
Expand Down Expand Up @@ -63,3 +65,18 @@ compile_all("true" "cfloat_fft" "Number Systems/static/floating-point/binary/cfl
compile_all("true" "cfloat_tft" "Number Systems/static/floating-point/binary/cfloat/arithmetic/saturating/subnormal" "${SAT_ARITH_SUBNORMAL_SRC}")
compile_all("true" "cfloat_ftt" "Number Systems/static/floating-point/binary/cfloat/arithmetic/saturating/supernormal" "${SAT_ARITH_SUPNORMAL_SRC}")
compile_all("true" "cfloat_ttt" "Number Systems/static/floating-point/binary/cfloat/arithmetic/saturating/subsuper" "${SAT_ARITH_SUBSUP_SRC}")


if(BUILD_COMPLEX)

message(STATUS "Adding regression suite for complex arithmetic using cfloats")
compile_all("true" "cfloat_cmplx" "Complex/Number Systems/static/floating-point/binary/cfloat/arithmetic" "${COMPLEX_ARITHMETIC_SRC}")

message(STATUS "Adding regression suite for complex math functions using cfloats")
compile_all("true" "cfloat_cmplx" "Complex/Number Systems/static/floating-point/binary/cfloat/math" "${COMPLEX_MATH_SRC}")

else(BUILD_COMPLEX)
message(STATUS "Removing regression suite for complex arithmetic using cfloats")
message(STATUS "Removing regression suite for complex math functions using cfloats")
endif(BUILD_COMPLEX)

109 changes: 109 additions & 0 deletions static/cfloat/complex/arithmetic/addition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// addition.cpp: test suite runner for complex addition on classic floats
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <universal/utility/directives.hpp>
// minimum set of include files to reflect source code dependencies
#define BLOCKTRIPLE_VERBOSE_OUTPUT
//#define BLOCKTRIPLE_TRACE_ADD
#define TRACE_CONVERSION 0
#include <universal/number/cfloat/cfloat.hpp>
#include <universal/verification/test_status.hpp>
#include <universal/verification/test_case.hpp>
#include <universal/verification/test_suite_randoms.hpp>
#include <universal/verification/cfloat_test_suite.hpp>

// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override
#define MANUAL_TESTING 0
// 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
#define REGRESSION_LEVEL_4 1
#endif

int main()
try {
using namespace sw::universal;

// cfloat encoding configuration for the test
constexpr bool hasSubnormals = true;
constexpr bool hasSupernormals = false;
constexpr bool isSaturating = false;

std::string test_suite = "classic cfloat complex addition validation";
std::string test_tag = "cfloat_fff addition";
bool reportTestCases = true;
int nrOfFailedTestCases = 0;

ReportTestSuiteHeader(test_suite, reportTestCases);

// shorthand alias types
using c16 = cfloat< 16, 5, uint8_t, hasSubnormals, hasSupernormals, isSaturating>;
using c32 = cfloat< 32, 8, uint8_t, hasSubnormals, hasSupernormals, isSaturating>;
using c48 = cfloat< 48, 8, uint8_t, hasSubnormals, hasSupernormals, isSaturating>;
using c64 = cfloat< 64, 11, uint8_t, hasSubnormals, hasSupernormals, isSaturating>;
using c80 = cfloat< 80, 11, uint8_t, hasSubnormals, hasSupernormals, isSaturating>;
using c96 = cfloat< 96, 15, uint8_t, hasSubnormals, hasSupernormals, isSaturating>;
using c128 = cfloat<128, 15, uint8_t, hasSubnormals, hasSupernormals, isSaturating>;

// driving the intensity of the randomized arithmetic tests
size_t nrRandoms = 0;

#if MANUAL_TESTING


ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
return EXIT_SUCCESS; // ignore failures

#else

#if REGRESSION_LEVEL_1

#endif

#if REGRESSION_LEVEL_2

#endif

#if REGRESSION_LEVEL_3

#endif

#if REGRESSION_LEVEL_4

#endif

ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
#endif // MANUAL_TESTING
}
catch (char const* msg) {
std::cerr << "Caught ad-hoc exception: " << msg << std::endl;
return EXIT_FAILURE;
}
catch (const sw::universal::universal_arithmetic_exception& err) {
std::cerr << "Caught unexpected universal arithmetic exception : " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (const sw::universal::universal_internal_exception& err) {
std::cerr << "Caught unexpected universal internal exception: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (const std::runtime_error& err) {
std::cerr << "Caught runtime exception: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (...) {
std::cerr << "Caught unknown exception" << std::endl;
return EXIT_FAILURE;
}
110 changes: 110 additions & 0 deletions static/cfloat/complex/math/functions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// functions.cpp: test suite runner for complex (real, imag, conj) functions
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
#include <universal/utility/directives.hpp>
// use default number system library configuration
#include <universal/number/cfloat/cfloat.hpp>
#include <universal/verification/test_reporters.hpp>

// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override
#define MANUAL_TESTING 0
// 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
#define REGRESSION_LEVEL_4 1
#endif

int main()
try {
using namespace sw::universal;

std::string test_suite = "cfloat complex function validation";
std::string test_tag = "complex failed: ";
bool reportTestCases = false;
int nrOfFailedTestCases = 0;

ReportTestSuiteHeader(test_suite, reportTestCases);

#if MANUAL_TESTING

// manual exhaustive test

{
constexpr unsigned nbits = 8;
constexpr unsigned es = 2;
constexpr bool hasSubnormals = true;
typedef uint8_t bt;
using Real = cfloat<nbits, es, bt, hasSubnormals>;

std::complex<Real> a, b, c;

a.real = 1.0f;
a.imag = 1.0f;
}

ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
return EXIT_SUCCESS; // ignore errors
#else

constexpr unsigned nbits = 8;
constexpr unsigned es = 2;
constexpr bool hasSubnormals = true;

using Real = cfloat<nbits, es, uint8_t, hasSubnormals>;
std::complex<Real> x, y;
auto bla = std::complex<Real>(copysign(x.real(), y.real()), copysign(x.real(), y.real()));

std::cout << bla << '\n';

#if REGRESSION_LEVEL_1

#endif

#if REGRESSION_LEVEL_2

#endif

#if REGRESSION_LEVEL_3

#endif

#if REGRESSION_LEVEL_4

#endif

ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);

#endif // MANUAL_TESTING
}
catch (char const* msg) {
std::cerr << "Caught ad-hoc exception: " << msg << std::endl;
return EXIT_FAILURE;
}
catch (const sw::universal::universal_arithmetic_exception& err) {
std::cerr << "Caught unexpected universal arithmetic exception : " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (const sw::universal::universal_internal_exception& err) {
std::cerr << "Caught unexpected universal internal exception: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (const std::runtime_error& err) {
std::cerr << "Caught runtime exception: " << err.what() << std::endl;
return EXIT_FAILURE;
}
catch (...) {
std::cerr << "Caught unknown exception" << std::endl;
return EXIT_FAILURE;
}
15 changes: 11 additions & 4 deletions static/fixpnt/binary/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ file(GLOB API_SRC "api/*.cpp")
file(GLOB CONVERSION_SRC "conversion/*.cpp")
file(GLOB LOGIC_SRC "logic/*.cpp")
file(GLOB ARITHMETIC_SRC "arithmetic/*.cpp")
file(GLOB COMPLEX_SRC "complex/*.cpp")
file(GLOB MATH_SRC "math/*.cpp")

file(GLOB COMPLEX_ARITHMETIC_SRC "complex/arithmetic/*.cpp")
file(GLOB COMPLEX_MATH_SRC "complex/math/*.cpp")

compile_all("true" "fixpnt" "Number Systems/static/fixed-point/binary/fixpnt/api" "${API_SRC}")
compile_all("true" "fixpnt" "Number Systems/static/fixed-point/binary/fixpnt/conversion" "${CONVERSION_SRC}")
compile_all("true" "fixpnt" "Number Systems/static/fixed-point/binary/fixpnt/logic" "${LOGIC_SRC}")
Expand All @@ -15,9 +17,14 @@ compile_all("true" "fixpnt" "Number Systems/static/fixed-point/binary/fixpnt/mat
message(STATUS "CMAKE_CXX_COMPILER ID is -${CMAKE_CXX_COMPILER_ID}-")

if(BUILD_COMPLEX)
message(STATUS "Adding complex test for fixpnt")
compile_all("true" "fixpnt" "Complex/Number System/static/fixed-point/binary/fixpnt/complex" "${COMPLEX_SRC}")

message(STATUS "Adding regression suite for complex arithmetic using fixpnt")
compile_all("true" "fixpnt_cmplx" "Complex/Number System/static/fixed-point/binary/fixpnt/arithmetic" "${COMPLEX_ARITHMETIC_SRC}")

message(STATUS "Adding regression suite for complex math functions using fixpnt")
compile_all("true" "fixpnt_cmplx" "Complex/Number System/static/fixed-point/binary/fixpnt/math" "${COMPLEX_MATH_SRC}")

else(BUILD_COMPLEX)
message(STATUS "Removing complex environment regression suite for fixpnt")
message(STATUS "Removing regression suite for complex arithmetic using fixpnt")
endif(BUILD_COMPLEX)

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// complex.cpp: test suite runner for complex (real, imag, conj) functions
// functions.cpp: test suite runner for complex (real, imag, conj) functions
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
Expand Down Expand Up @@ -29,7 +29,7 @@ int main()
try {
using namespace sw::universal;

std::string test_suite = "fixed-point mathlib complex";
std::string test_suite = "fixed-point complex math functions";
std::string test_tag = "mathlib complex";
bool reportTestCases = true;
int nrOfFailedTestCases = 0;
Expand Down
16 changes: 16 additions & 0 deletions static/posit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@ file (GLOB CONVERSION_SRC "./conversion/*.cpp")
file (GLOB LOGIC_SRC "./logic/*.cpp")
file (GLOB ARITHMETIC_SRC "./arithmetic/*.cpp")
file (GLOB MATH_SRC "./math/*.cpp")
file (GLOB COMPLEX_ARITHMETIC_SRC "./complex/arithmetic/*.cpp")
file (GLOB COMPLEX_MATH_SRC "./complex/math/*.cpp")

compile_all("true" "posit" "Number Systems/static/floating-point/tapered/posit/api" "${API_SRC}")
compile_all("true" "posit" "Number Systems/static/floating-point/tapered/posit/conversion" "${CONVERSION_SRC}")
compile_all("true" "posit" "Number Systems/static/floating-point/tapered/posit/logic" "${LOGIC_SRC}")
compile_all("true" "posit" "Number Systems/static/floating-point/tapered/posit/arithmetic" "${ARITHMETIC_SRC}")
compile_all("true" "posit" "Number Systems/static/floating-point/tapered/posit/math" "${MATH_SRC}")


if(BUILD_COMPLEX)

message(STATUS "Adding regression suite for complex arithmetic using posits")
compile_all("true" "posit_cmplx" "Complex/Number Systems/static/floating-point/tapered/posit/arithmetic" "${COMPLEX_ARITHMETIC_SRC}")

message(STATUS "Adding regression suite for complex math functions using posits")
compile_all("true" "posit_cmplx" "Complex/Number Systems/static/floating-point/tapered/posit/math" "${COMPLEX_MATH_SRC}")

else(BUILD_COMPLEX)
message(STATUS "Removing regression suite for complex arithmetic using posits")
message(STATUS "Removing regression suite for complex math functions using posits")
endif(BUILD_COMPLEX)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// complex_add.cpp: test suite runner for posit complex addition
// addition.cpp: test suite runner for posit complex addition
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// complex.cpp: test suite runner for complex (real, imag, conj) functions
// functions.cpp: test suite runner for complex (real, imag, conj) functions
//
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
// SPDX-License-Identifier: MIT
Expand Down
6 changes: 3 additions & 3 deletions static/takum/conversion/assignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void convert_ieee754(Real input) {
double v = input;
std::cout << "\nconvert native ieee754 value to takum\n";
std::cout << to_binary(input) << '\n';
std::cout << "fraction bits " << to_binary(fractionBits(v), 52, false) << '\n';
std::cout << "fraction bits " << to_binary(fractionBits(v), false, 52) << '\n';
std::cout << "value : " << v << '\n';
bool s = sign(v);
uint64_t S = sign(v) ? 1 : 0;
Expand Down Expand Up @@ -92,9 +92,9 @@ void convert_ieee754(Real input) {

std::cout << "S : " << S << '\n';
std::cout << "D : " << D << '\n';
std::cout << "R : " << to_binary(R, 3, false) << '\n';
std::cout << "R : " << to_binary(R, false, 3) << '\n';
std::cout << "A : " << (r == 0 ? "-" : to_binary(A, r, false)) << '\n';
std::cout << "F : " << to_binary(F,m,false) << '\n';
std::cout << "F : " << to_binary(F,false, m) << '\n';

uint64_t raw{ 0 };
raw |= (S << (nbits - 1));
Expand Down

0 comments on commit 4efbc00

Please sign in to comment.