From a15f9420cbfc8ff8d9f906a833843ab9f91370a0 Mon Sep 17 00:00:00 2001 From: Beman Date: Fri, 20 Mar 2015 08:59:47 -0400 Subject: [PATCH] Add fp_exhaustive_test. --- benchmark/Jamfile.v2 | 7 +- include/boost/endian/conversion.hpp | 4 +- test/fp_exhaustive_test.cpp | 86 +++++++++++++++++ test/msvc/endian.sln | 10 +- .../fp_exhaustive_test.vcxproj | 96 +++++++++++++++++++ 5 files changed, 199 insertions(+), 4 deletions(-) create mode 100644 test/fp_exhaustive_test.cpp create mode 100644 test/msvc/fp_exhaustive_test/fp_exhaustive_test.vcxproj diff --git a/benchmark/Jamfile.v2 b/benchmark/Jamfile.v2 index f61061a..5524500 100644 --- a/benchmark/Jamfile.v2 +++ b/benchmark/Jamfile.v2 @@ -22,4 +22,9 @@ exe "loop_time_test" : gcc:-march=native ; -install bin : speed_test loop_time_test ; +exe "fp_exhaustive_test" + : fp_exhaustive_test.cpp + : gcc:-march=native + ; + +install bin : speed_test loop_time_test fp_exhaustive_test ; diff --git a/include/boost/endian/conversion.hpp b/include/boost/endian/conversion.hpp index 5edba2c..73e9f34 100644 --- a/include/boost/endian/conversion.hpp +++ b/include/boost/endian/conversion.hpp @@ -171,8 +171,8 @@ namespace endian { T tmp(x); std::reverse( - reinterpret_cast(&tmp), - reinterpret_cast(&tmp) + sizeof(T)); + reinterpret_cast(&tmp), + reinterpret_cast(&tmp) + sizeof(T)); return tmp; } diff --git a/test/fp_exhaustive_test.cpp b/test/fp_exhaustive_test.cpp new file mode 100644 index 0000000..1774c98 --- /dev/null +++ b/test/fp_exhaustive_test.cpp @@ -0,0 +1,86 @@ +// fp_exhaustive_test.cpp ------------------------------------------------------------// + +// Copyright Beman Dawes 2015 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See library home page at http://www.boost.org/libs/endian + +//--------------------------------------------------------------------------------------// + +#include + +//#define BOOST_ENDIAN_LOG +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace boost::endian; +using std::cout; +using std::endl; +using std::hex; +using std::dec; +using std::numeric_limits; + + +namespace +{ +} // unnamed namespace + +//--------------------------------------------------------------------------------------// + +int cpp_main(int, char *[]) +{ +#ifdef BOOST_BIG_ENDIAN + cout << "platform is big endian\n"; +#else + cout << "platform is little endian\n"; +#endif + cout << "byte swap intrinsics: " BOOST_ENDIAN_INTRINSIC_MSG << endl; + +#ifdef BOOST_NO_CXX11_NUMERIC_LIMITS + cout << "BOOST_NO_CXX11_NUMERIC_LIMITS is defined" << endl; +#endif + + cout << "Iterations: " << endl; + + uint32_t i = 0; + do + { + if (i % 1000000 == 0) + cout << i << endl; + + float x = *reinterpret_cast(&i); + float rtx = endian_reverse(endian_reverse(x)); + if (!BOOST_TEST_MEM_EQ(x, rtx)) + { + float erx = endian_reverse(x); + cout << "i = 0X" << detail::to_hex(i) << "\n"; + cout << "x = 0X" << detail::to_hex(x) << "\n"; + cout << "erx = 0X" << detail::to_hex(erx) << "\n"; + cout << "rtx = 0X" << detail::to_hex(rtx) << "\n"; + //cout << "i = " << i << " [0X" << hex << i << dec << "], or " + // << *reinterpret_cast(&i) << " as float\n" + // "but endian_reverse(endian_reverse()) round-trip yields " + // << endian_reverse(endian_reverse(*reinterpret_cast(&i))) << "\n" + // ; +// erx = endian_reverse(x); + break; + } + ++i; + } while (i != 0); + + cout << "\n done" << endl; + + return ::boost::endian::report_errors(); +} + +#include diff --git a/test/msvc/endian.sln b/test/msvc/endian.sln index fa0ceca..2de57fc 100644 --- a/test/msvc/endian.sln +++ b/test/msvc/endian.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.22512.0 +VisualStudioVersion = 14.0.22609.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "endian_test", "endian_test\endian_test.vcxproj", "{74C201F3-8308-40BE-BC0F-24974DEAF405}" EndProject @@ -35,6 +35,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "deprecated_test", "deprecat EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "floating_point_test", "floating_point_test\floating_point_test.vcxproj", "{27E8FDC5-9669-4940-B24F-94B21FFEE649}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fp_exhaustive_test", "fp_exhaustive_test\fp_exhaustive_test.vcxproj", "{E19A89FE-D728-4705-A060-B85E7239984C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -161,6 +163,12 @@ Global {27E8FDC5-9669-4940-B24F-94B21FFEE649}.Release|Win32.ActiveCfg = Release|Win32 {27E8FDC5-9669-4940-B24F-94B21FFEE649}.Release|Win32.Build.0 = Release|Win32 {27E8FDC5-9669-4940-B24F-94B21FFEE649}.Release|x64.ActiveCfg = Release|Win32 + {E19A89FE-D728-4705-A060-B85E7239984C}.Debug|Win32.ActiveCfg = Debug|Win32 + {E19A89FE-D728-4705-A060-B85E7239984C}.Debug|Win32.Build.0 = Debug|Win32 + {E19A89FE-D728-4705-A060-B85E7239984C}.Debug|x64.ActiveCfg = Debug|Win32 + {E19A89FE-D728-4705-A060-B85E7239984C}.Release|Win32.ActiveCfg = Release|Win32 + {E19A89FE-D728-4705-A060-B85E7239984C}.Release|Win32.Build.0 = Release|Win32 + {E19A89FE-D728-4705-A060-B85E7239984C}.Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/msvc/fp_exhaustive_test/fp_exhaustive_test.vcxproj b/test/msvc/fp_exhaustive_test/fp_exhaustive_test.vcxproj new file mode 100644 index 0000000..85e9b89 --- /dev/null +++ b/test/msvc/fp_exhaustive_test/fp_exhaustive_test.vcxproj @@ -0,0 +1,96 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {E19A89FE-D728-4705-A060-B85E7239984C} + Win32Proj + fp_exhaustive_test + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file