forked from boostorg/endian
Add fp_exhaustive_test.
This commit is contained in:
@ -22,4 +22,9 @@ exe "loop_time_test"
|
||||
: <toolset>gcc:<cxxflags>-march=native
|
||||
;
|
||||
|
||||
install bin : speed_test loop_time_test ;
|
||||
exe "fp_exhaustive_test"
|
||||
: fp_exhaustive_test.cpp
|
||||
: <toolset>gcc:<cxxflags>-march=native
|
||||
;
|
||||
|
||||
install bin : speed_test loop_time_test fp_exhaustive_test ;
|
||||
|
@ -171,8 +171,8 @@ namespace endian
|
||||
{
|
||||
T tmp(x);
|
||||
std::reverse(
|
||||
reinterpret_cast<char*>(&tmp),
|
||||
reinterpret_cast<char*>(&tmp) + sizeof(T));
|
||||
reinterpret_cast<unsigned char*>(&tmp),
|
||||
reinterpret_cast<unsigned char*>(&tmp) + sizeof(T));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
86
test/fp_exhaustive_test.cpp
Normal file
86
test/fp_exhaustive_test.cpp
Normal file
@ -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 <boost/endian/detail/disable_warnings.hpp>
|
||||
|
||||
//#define BOOST_ENDIAN_LOG
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
#include <boost/endian/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <climits>
|
||||
#include <cstring>
|
||||
|
||||
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<const float*>(&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<const float*>(&i) << " as float\n"
|
||||
// "but endian_reverse(endian_reverse()) round-trip yields "
|
||||
// << endian_reverse(endian_reverse(*reinterpret_cast<const float*>(&i))) << "\n"
|
||||
// ;
|
||||
// erx = endian_reverse(x);
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
} while (i != 0);
|
||||
|
||||
cout << "\n done" << endl;
|
||||
|
||||
return ::boost::endian::report_errors();
|
||||
}
|
||||
|
||||
#include <boost/endian/detail/disable_warnings_pop.hpp>
|
@ -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
|
||||
|
96
test/msvc/fp_exhaustive_test/fp_exhaustive_test.vcxproj
Normal file
96
test/msvc/fp_exhaustive_test/fp_exhaustive_test.vcxproj
Normal file
@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{E19A89FE-D728-4705-A060-B85E7239984C}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>fp_exhaustive_test</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\common.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\common.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command />
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command />
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\fp_exhaustive_test.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
Reference in New Issue
Block a user