mirror of
https://github.com/boostorg/endian.git
synced 2025-08-01 05:24:39 +02:00
Work in progress
git-svn-id: http://svn.boost.org/svn/boost/sandbox/endian@74330 b8fc166d-592f-0410-95f2-cb63ce0dd405
This commit is contained in:
157
boost/endian/conversion2.hpp
Normal file
157
boost/endian/conversion2.hpp
Normal file
@@ -0,0 +1,157 @@
|
||||
// boost/endian/conversion.hpp -------------------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 2010, 2011
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#ifndef BOOST_ENDIAN_CONVERSION2_HPP
|
||||
#define BOOST_ENDIAN_CONVERSION2_HPP
|
||||
|
||||
#include <boost/detail/endian.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
//
|
||||
// This header explores
|
||||
// -- value returning interface approach suggested by Phil Endecott.
|
||||
// -- additional reorder overloads for floating point types as requested by Vicente
|
||||
// Botet and others.
|
||||
// -- reorder implementation approach suggested by tymofey, with avoidance of
|
||||
// undefined behavior as suggested by Giovanni Piero Deretta, and a further
|
||||
// refinement suggested by Pyry Jahkola.
|
||||
// -- general reorder function template to meet requests for UDT support by
|
||||
// Vicente Botet and others.
|
||||
// -- general reorder function template implementation approach using std::reverse
|
||||
// suggested by Mathias Gaunard
|
||||
//
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
//------------------------------------- synopsis ---------------------------------------//
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace endian2
|
||||
{
|
||||
// reverse byte order (i.e. endianness)
|
||||
|
||||
inline int16_t reorder(int16_t x);
|
||||
inline int32_t reorder(int32_t x);
|
||||
inline int64_t reorder(int64_t x);
|
||||
inline uint16_t reorder(uint16_t x);
|
||||
inline uint32_t reorder(uint32_t x);
|
||||
inline uint64_t reorder(uint64_t x);
|
||||
|
||||
// TODO: Need implementation
|
||||
// TODO: Need to verify the return does not invoke undefined behavior (as might happen
|
||||
// if there are unutterable floating point values, such as happens with the unutterable
|
||||
// pointer values on some architectures
|
||||
inline float reorder(float x);
|
||||
inline double reorder(double x);
|
||||
|
||||
// TODO: Would pass by value be better for the following functions?
|
||||
|
||||
template <class T>
|
||||
inline T reorder(const T& x);
|
||||
|
||||
template <class T>
|
||||
inline T big(const T& x);
|
||||
// Return: x if native endianness is big, otherwise reorder(x);
|
||||
|
||||
template <class T>
|
||||
inline T little(const T& x);
|
||||
// Return: x if native endianness is little, otherwise reorder(x);
|
||||
|
||||
//----------------------------------- implementation -----------------------------------//
|
||||
|
||||
inline int16_t reorder(int16_t x)
|
||||
{
|
||||
return (static_cast<uint16_t>(x) << 8)
|
||||
| (static_cast<uint16_t>(x) >> 8);
|
||||
}
|
||||
|
||||
inline int32_t reorder(int32_t x)
|
||||
{
|
||||
uint32_t step16;
|
||||
step16 = static_cast<uint32_t>(x) << 16 | static_cast<uint32_t>(x) >> 16;
|
||||
return
|
||||
((static_cast<uint32_t>(step16) << 8) & 0xff00ff00)
|
||||
| ((static_cast<uint32_t>(step16) >> 8) & 0x00ff00ff);
|
||||
}
|
||||
|
||||
inline int64_t reorder(int64_t x)
|
||||
{
|
||||
return (static_cast<uint64_t>(x) << 56)
|
||||
| ((static_cast<uint64_t>(x) << 40) & 0x00ff000000000000ULL)
|
||||
| ((static_cast<uint64_t>(x) << 24) & 0x0000ff0000000000ULL)
|
||||
| ((static_cast<uint64_t>(x) << 8) & 0x000000ff00000000ULL)
|
||||
| ((static_cast<uint64_t>(x) >> 8) & 0x00000000ff000000ULL)
|
||||
| ((static_cast<uint64_t>(x) >> 24) & 0x0000000000ff0000ULL)
|
||||
| ((static_cast<uint64_t>(x) >> 40) & 0x000000000000ff00ULL)
|
||||
| (static_cast<uint64_t>(x) >> 56);
|
||||
}
|
||||
|
||||
inline uint16_t reorder(uint16_t x)
|
||||
{
|
||||
return (x << 8)
|
||||
| (x >> 8);
|
||||
}
|
||||
|
||||
inline uint32_t reorder(uint32_t x)
|
||||
{
|
||||
uint32_t step16;
|
||||
step16 = x << 16 | x >> 16;
|
||||
return
|
||||
((step16 << 8) & 0xff00ff00)
|
||||
| ((step16 >> 8) & 0x00ff00ff);
|
||||
}
|
||||
|
||||
inline uint64_t reorder(uint64_t x)
|
||||
{
|
||||
return (x << 56)
|
||||
| ((x << 40) & 0x00ff000000000000)
|
||||
| ((x << 24) & 0x0000ff0000000000)
|
||||
| ((x << 8) & 0x000000ff00000000)
|
||||
| ((x >> 8) & 0x00000000ff000000)
|
||||
| ((x >> 24) & 0x0000000000ff0000)
|
||||
| ((x >> 40) & 0x000000000000ff00)
|
||||
| (x >> 56);
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
inline T reorder(const T& x)
|
||||
{
|
||||
T tmp;
|
||||
std::reverse(
|
||||
reinterpret_cast<const char*>(&x),
|
||||
reinterpret_cast<const char*>(&x) + sizeof(T),
|
||||
reinterpret_cast<char*>(&tmp));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T big(const T& x)
|
||||
{
|
||||
# ifdef BOOST_BIG_ENDIAN
|
||||
return x;
|
||||
# else
|
||||
return reorder(x);
|
||||
# endif
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T little(const T& x)
|
||||
{
|
||||
# ifdef BOOST_LITTLE_ENDIAN
|
||||
return x;
|
||||
# else
|
||||
return reorder(x);
|
||||
# endif
|
||||
}
|
||||
|
||||
} // namespace endian2
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_ENDIAN_CONVERSION2_HPP
|
@@ -115,14 +115,27 @@ namespace
|
||||
|
||||
inline void in_place(int32_t& x)
|
||||
{
|
||||
x = ((x << 24) & 0xff000000) | ((x << 8) & 0x00ff0000) | ((x >> 24) & 0x000000ff)
|
||||
| ((x >> 8) & 0x0000ff00);
|
||||
x = (static_cast<uint32_t>(x) << 24)
|
||||
| ((static_cast<uint32_t>(x) << 8) & 0x00ff0000)
|
||||
| ((static_cast<uint32_t>(x) >> 8) & 0x0000ff00)
|
||||
| (static_cast<uint32_t>(x) >> 24);
|
||||
}
|
||||
|
||||
inline int32_t by_return(int32_t x)
|
||||
{
|
||||
return ((x << 24) & 0xff000000) | ((x << 8) & 0x00ff0000) | ((x >> 24) & 0x000000ff)
|
||||
| ((x >> 8) & 0x0000ff00);
|
||||
return (static_cast<uint32_t>(x) << 24)
|
||||
| ((static_cast<uint32_t>(x) << 8) & 0x00ff0000)
|
||||
| ((static_cast<uint32_t>(x) >> 8) & 0x0000ff00)
|
||||
| (static_cast<uint32_t>(x) >> 24);
|
||||
}
|
||||
|
||||
inline int32_t by_return_pyry(int32_t x)
|
||||
{
|
||||
uint32_t step16;
|
||||
step16 = static_cast<uint32_t>(x) << 16 | static_cast<uint32_t>(x) >> 16;
|
||||
return
|
||||
((static_cast<uint32_t>(step16) << 8) & 0xff00ff00)
|
||||
| ((static_cast<uint32_t>(step16) >> 8) & 0x00ff00ff);
|
||||
}
|
||||
|
||||
inline int32_t two_operand(int32_t x, int32_t& y)
|
||||
@@ -150,6 +163,12 @@ namespace
|
||||
return by_return(v);
|
||||
}
|
||||
|
||||
int32_t modify_by_return_pyry(int32_t x)
|
||||
{
|
||||
int32_t v(x);
|
||||
return by_return_pyry(v);
|
||||
}
|
||||
|
||||
void non_modify_assign(int32_t x, int32_t& y)
|
||||
{
|
||||
y = x;
|
||||
@@ -179,6 +198,7 @@ int main(int argc, char * argv[])
|
||||
overhead = benchmark(modify_noop, "modify no-op");
|
||||
benchmark(modify_in_place, "modify in place", overhead);
|
||||
benchmark(modify_by_return, "modify by return", overhead);
|
||||
benchmark(modify_by_return_pyry, "modify by return", overhead);
|
||||
#else
|
||||
overhead = benchmark(non_modify_assign, "non_modify_assign ");
|
||||
benchmark(non_modify_two_operand, "non_modify_two_operand", overhead);
|
||||
|
@@ -9,137 +9,57 @@
|
||||
|
||||
#include <boost/endian/detail/disable_warnings.hpp>
|
||||
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <boost/endian/conversion2.hpp>
|
||||
#include <boost/detail/lightweight_main.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace be = boost::endian;
|
||||
namespace be = boost::endian2;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void test_in_place_reorder()
|
||||
void test_reorder()
|
||||
{
|
||||
std::cout << "test_in_place_reorder...\n";
|
||||
std::cout << "test_reorder...\n";
|
||||
|
||||
boost::int64_t i64 = 0x0102030405060708LL;
|
||||
be::reorder(i64);
|
||||
BOOST_TEST_EQ(i64, 0x0807060504030201LL);
|
||||
be::reorder(i64);
|
||||
BOOST_TEST_EQ(i64, 0x0102030405060708LL);
|
||||
BOOST_TEST_EQ(be::reorder(i64), 0x0807060504030201LL);
|
||||
BOOST_TEST_EQ(be::reorder(be::reorder(i64)), i64);
|
||||
|
||||
i64 = 0xfefdfcfbfaf9f8f7LL;
|
||||
be::reorder(i64);
|
||||
BOOST_TEST_EQ(i64, static_cast<boost::int64_t>(0xf7f8f9fafbfcfdfeULL));
|
||||
be::reorder(i64);
|
||||
BOOST_TEST_EQ(i64, static_cast<boost::int64_t>(0xfefdfcfbfaf9f8f7ULL));
|
||||
BOOST_TEST_EQ(be::reorder(i64), static_cast<boost::int64_t>(0xf7f8f9fafbfcfdfeULL));
|
||||
BOOST_TEST_EQ(be::reorder(be::reorder(i64)), i64);
|
||||
|
||||
boost::int32_t i32 = 0x01020304;
|
||||
be::reorder(i32);
|
||||
BOOST_TEST_EQ(i32, 0x04030201);
|
||||
be::reorder(i32);
|
||||
BOOST_TEST_EQ(i32, 0x01020304);
|
||||
BOOST_TEST_EQ(be::reorder(i32), 0x04030201);
|
||||
BOOST_TEST_EQ(be::reorder(be::reorder(i32)), i32);
|
||||
|
||||
i32 = 0xfefdfcfb;
|
||||
be::reorder(i32);
|
||||
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfbfcfdfe));
|
||||
be::reorder(i32);
|
||||
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfefdfcfb));
|
||||
BOOST_TEST_EQ(be::reorder(i32), static_cast<boost::int32_t>(0xfbfcfdfe));
|
||||
BOOST_TEST_EQ(be::reorder(be::reorder(i32)), i32);
|
||||
|
||||
boost::int16_t i16 = 0x0102;
|
||||
be::reorder(i16);
|
||||
BOOST_TEST_EQ(i16, 0x0201);
|
||||
be::reorder(i16);
|
||||
BOOST_TEST_EQ(i16, 0x0102);
|
||||
BOOST_TEST_EQ(be::reorder(i16), 0x0201);
|
||||
BOOST_TEST_EQ(be::reorder(be::reorder(i16)), i16);
|
||||
|
||||
i16 = static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd));
|
||||
be::reorder(i16);
|
||||
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
|
||||
be::reorder(i16);
|
||||
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd)));
|
||||
BOOST_TEST_EQ(be::reorder(i16), static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
|
||||
BOOST_TEST_EQ(be::reorder(be::reorder(i16)), i16);
|
||||
|
||||
boost::uint64_t ui64 = 0x0102030405060708ULL;
|
||||
be::reorder(ui64);
|
||||
BOOST_TEST_EQ(ui64, 0x0807060504030201ULL);
|
||||
be::reorder(ui64);
|
||||
BOOST_TEST_EQ(ui64, 0x0102030405060708ULL);
|
||||
BOOST_TEST_EQ(be::reorder(ui64), 0x0807060504030201ULL);
|
||||
BOOST_TEST_EQ(be::reorder(be::reorder(ui64)), ui64);
|
||||
|
||||
boost::uint32_t ui32 = 0x01020304;
|
||||
be::reorder(ui32);
|
||||
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x04030201));
|
||||
be::reorder(ui32);
|
||||
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x01020304));
|
||||
BOOST_TEST_EQ(be::reorder(ui32), static_cast<boost::uint32_t>(0x04030201));
|
||||
BOOST_TEST_EQ(be::reorder(be::reorder(ui32)), ui32);
|
||||
|
||||
boost::uint16_t ui16 = 0x0102;
|
||||
be::reorder(ui16);
|
||||
BOOST_TEST_EQ(ui16, 0x0201);
|
||||
be::reorder(ui16);
|
||||
BOOST_TEST_EQ(ui16, static_cast<boost::uint16_t>(0x0102));
|
||||
BOOST_TEST_EQ(be::reorder(ui16), 0x0201);
|
||||
BOOST_TEST_EQ(be::reorder(be::reorder(ui16)), ui16);
|
||||
|
||||
std::cout << " test_in_place_reorder complete\n";
|
||||
}
|
||||
|
||||
void test_copying_reorder()
|
||||
{
|
||||
std::cout << "test_copying_reorder...\n";
|
||||
|
||||
boost::int64_t i64 = 0x0102030405060708LL, j64, k64;
|
||||
be::reorder(i64, j64);
|
||||
BOOST_TEST_EQ(j64, 0x0807060504030201LL);
|
||||
BOOST_TEST_EQ(i64, 0x0102030405060708LL);
|
||||
be::reorder(j64, k64);
|
||||
BOOST_TEST_EQ(k64, 0x0102030405060708LL);
|
||||
|
||||
i64 = 0xfefdfcfbfaf9f8f7LL;
|
||||
be::reorder(i64, j64);
|
||||
BOOST_TEST_EQ(j64, static_cast<boost::int64_t>(0xf7f8f9fafbfcfdfeLL));
|
||||
be::reorder(j64, k64);
|
||||
BOOST_TEST_EQ(k64, static_cast<boost::int64_t>(0xfefdfcfbfaf9f8f7LL));
|
||||
|
||||
boost::int32_t i32 = 0x01020304, j32, k32;
|
||||
be::reorder(i32, j32);
|
||||
BOOST_TEST_EQ(j32, 0x04030201);
|
||||
be::reorder(j32, k32);
|
||||
BOOST_TEST_EQ(k32, 0x01020304);
|
||||
|
||||
i32 = 0xfefdfcfb;
|
||||
be::reorder(i32, j32);
|
||||
BOOST_TEST_EQ(j32, static_cast<boost::int32_t>(0xfbfcfdfe));
|
||||
be::reorder(j32, k32);
|
||||
BOOST_TEST_EQ(k32, static_cast<boost::int32_t>(0xfefdfcfb));
|
||||
|
||||
boost::int16_t i16 = 0x0102, j16, k16;
|
||||
be::reorder(i16, j16);
|
||||
BOOST_TEST_EQ(j16, 0x0201);
|
||||
be::reorder(j16, k16);
|
||||
BOOST_TEST_EQ(k16, 0x0102);
|
||||
|
||||
i16 = static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd));
|
||||
be::reorder(i16, j16);
|
||||
BOOST_TEST_EQ(j16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
|
||||
be::reorder(j16, k16);
|
||||
BOOST_TEST_EQ(k16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd)));
|
||||
|
||||
boost::uint64_t ui64 = 0x0102030405060708ULL, uj64, uk64;
|
||||
be::reorder(ui64, uj64);
|
||||
BOOST_TEST_EQ(uj64, 0x0807060504030201ULL);
|
||||
be::reorder(uj64, uk64);
|
||||
BOOST_TEST_EQ(uk64, 0x0102030405060708ULL);
|
||||
|
||||
boost::uint32_t ui32 = 0x01020304, uj32, uk32;
|
||||
be::reorder(ui32, uj32);
|
||||
BOOST_TEST_EQ(uj32, static_cast<boost::uint32_t>(0x04030201));
|
||||
be::reorder(uj32, uk32);
|
||||
BOOST_TEST_EQ(uk32, static_cast<boost::uint32_t>(0x01020304));
|
||||
|
||||
boost::uint16_t ui16 = 0x0102, uj16, uk16;
|
||||
be::reorder(ui16, uj16);
|
||||
BOOST_TEST_EQ(uj16, 0x0201);
|
||||
be::reorder(uj16, uk16);
|
||||
BOOST_TEST_EQ(uk16, 0x0102);
|
||||
|
||||
std::cout << " test_copying_reorder complete\n";
|
||||
std::cout << " test_reorder complete\n";
|
||||
}
|
||||
|
||||
const boost::int64_t ni64 = 0x0102030405060708LL;
|
||||
@@ -198,231 +118,231 @@ namespace
|
||||
|
||||
void test_in_place_conditional_reorder()
|
||||
{
|
||||
std::cout << "test_in_place_conditional_reorder...\n";
|
||||
//std::cout << "test_in_place_conditional_reorder...\n";
|
||||
|
||||
boost::int64_t i64;
|
||||
//boost::int64_t i64;
|
||||
|
||||
i64 = ni64;
|
||||
be::native_to_big(i64);
|
||||
BOOST_TEST_EQ(i64, bi64);
|
||||
//i64 = ni64;
|
||||
//be::native_to_big(i64);
|
||||
//BOOST_TEST_EQ(i64, bi64);
|
||||
|
||||
i64 = ni64;
|
||||
be::native_to_little(i64);
|
||||
BOOST_TEST_EQ(i64, li64);
|
||||
//i64 = ni64;
|
||||
//be::native_to_little(i64);
|
||||
//BOOST_TEST_EQ(i64, li64);
|
||||
|
||||
i64 = bi64;
|
||||
be::big_to_native(i64);
|
||||
BOOST_TEST_EQ(i64, ni64);
|
||||
//i64 = bi64;
|
||||
//be::big_to_native(i64);
|
||||
//BOOST_TEST_EQ(i64, ni64);
|
||||
|
||||
i64 = li64;
|
||||
be::little_to_native(i64);
|
||||
BOOST_TEST_EQ(i64, ni64);
|
||||
//i64 = li64;
|
||||
//be::little_to_native(i64);
|
||||
//BOOST_TEST_EQ(i64, ni64);
|
||||
|
||||
boost::uint64_t ui64;
|
||||
//boost::uint64_t ui64;
|
||||
|
||||
ui64 = nui64;
|
||||
be::native_to_big(ui64);
|
||||
BOOST_TEST_EQ(ui64, bui64);
|
||||
//ui64 = nui64;
|
||||
//be::native_to_big(ui64);
|
||||
//BOOST_TEST_EQ(ui64, bui64);
|
||||
|
||||
ui64 = nui64;
|
||||
be::native_to_little(ui64);
|
||||
BOOST_TEST_EQ(ui64, lui64);
|
||||
//ui64 = nui64;
|
||||
//be::native_to_little(ui64);
|
||||
//BOOST_TEST_EQ(ui64, lui64);
|
||||
|
||||
ui64 = bui64;
|
||||
be::big_to_native(ui64);
|
||||
BOOST_TEST_EQ(ui64, nui64);
|
||||
//ui64 = bui64;
|
||||
//be::big_to_native(ui64);
|
||||
//BOOST_TEST_EQ(ui64, nui64);
|
||||
|
||||
ui64 = lui64;
|
||||
be::little_to_native(ui64);
|
||||
BOOST_TEST_EQ(ui64, nui64);
|
||||
//ui64 = lui64;
|
||||
//be::little_to_native(ui64);
|
||||
//BOOST_TEST_EQ(ui64, nui64);
|
||||
|
||||
boost::int32_t i32;
|
||||
//boost::int32_t i32;
|
||||
|
||||
i32 = ni32;
|
||||
be::native_to_big(i32);
|
||||
BOOST_TEST_EQ(i32, bi32);
|
||||
//i32 = ni32;
|
||||
//be::native_to_big(i32);
|
||||
//BOOST_TEST_EQ(i32, bi32);
|
||||
|
||||
i32 = ni32;
|
||||
be::native_to_little(i32);
|
||||
BOOST_TEST_EQ(i32, li32);
|
||||
//i32 = ni32;
|
||||
//be::native_to_little(i32);
|
||||
//BOOST_TEST_EQ(i32, li32);
|
||||
|
||||
i32 = bi32;
|
||||
be::big_to_native(i32);
|
||||
BOOST_TEST_EQ(i32, ni32);
|
||||
//i32 = bi32;
|
||||
//be::big_to_native(i32);
|
||||
//BOOST_TEST_EQ(i32, ni32);
|
||||
|
||||
i32 = li32;
|
||||
be::little_to_native(i32);
|
||||
BOOST_TEST_EQ(i32, ni32);
|
||||
//i32 = li32;
|
||||
//be::little_to_native(i32);
|
||||
//BOOST_TEST_EQ(i32, ni32);
|
||||
|
||||
boost::uint32_t ui32;
|
||||
//boost::uint32_t ui32;
|
||||
|
||||
ui32 = nui32;
|
||||
be::native_to_big(ui32);
|
||||
BOOST_TEST_EQ(ui32, bui32);
|
||||
//ui32 = nui32;
|
||||
//be::native_to_big(ui32);
|
||||
//BOOST_TEST_EQ(ui32, bui32);
|
||||
|
||||
ui32 = nui32;
|
||||
be::native_to_little(ui32);
|
||||
BOOST_TEST_EQ(ui32, lui32);
|
||||
//ui32 = nui32;
|
||||
//be::native_to_little(ui32);
|
||||
//BOOST_TEST_EQ(ui32, lui32);
|
||||
|
||||
ui32 = bui32;
|
||||
be::big_to_native(ui32);
|
||||
BOOST_TEST_EQ(ui32, nui32);
|
||||
//ui32 = bui32;
|
||||
//be::big_to_native(ui32);
|
||||
//BOOST_TEST_EQ(ui32, nui32);
|
||||
|
||||
ui32 = lui32;
|
||||
be::little_to_native(ui32);
|
||||
BOOST_TEST_EQ(ui32, nui32);
|
||||
//ui32 = lui32;
|
||||
//be::little_to_native(ui32);
|
||||
//BOOST_TEST_EQ(ui32, nui32);
|
||||
|
||||
boost::int16_t i16;
|
||||
//boost::int16_t i16;
|
||||
|
||||
i16 = ni16;
|
||||
be::native_to_big(i16);
|
||||
BOOST_TEST_EQ(i16, bi16);
|
||||
//i16 = ni16;
|
||||
//be::native_to_big(i16);
|
||||
//BOOST_TEST_EQ(i16, bi16);
|
||||
|
||||
i16 = ni16;
|
||||
be::native_to_little(i16);
|
||||
BOOST_TEST_EQ(i16, li16);
|
||||
//i16 = ni16;
|
||||
//be::native_to_little(i16);
|
||||
//BOOST_TEST_EQ(i16, li16);
|
||||
|
||||
i16 = bi16;
|
||||
be::big_to_native(i16);
|
||||
BOOST_TEST_EQ(i16, ni16);
|
||||
//i16 = bi16;
|
||||
//be::big_to_native(i16);
|
||||
//BOOST_TEST_EQ(i16, ni16);
|
||||
|
||||
i16 = li16;
|
||||
be::little_to_native(i16);
|
||||
BOOST_TEST_EQ(i16, ni16);
|
||||
//i16 = li16;
|
||||
//be::little_to_native(i16);
|
||||
//BOOST_TEST_EQ(i16, ni16);
|
||||
|
||||
boost::uint16_t ui16;
|
||||
//boost::uint16_t ui16;
|
||||
|
||||
ui16 = nui16;
|
||||
be::native_to_big(ui16);
|
||||
BOOST_TEST_EQ(ui16, bui16);
|
||||
//ui16 = nui16;
|
||||
//be::native_to_big(ui16);
|
||||
//BOOST_TEST_EQ(ui16, bui16);
|
||||
|
||||
ui16 = nui16;
|
||||
be::native_to_little(ui16);
|
||||
BOOST_TEST_EQ(ui16, lui16);
|
||||
//ui16 = nui16;
|
||||
//be::native_to_little(ui16);
|
||||
//BOOST_TEST_EQ(ui16, lui16);
|
||||
|
||||
ui16 = bui16;
|
||||
be::big_to_native(ui16);
|
||||
BOOST_TEST_EQ(ui16, nui16);
|
||||
//ui16 = bui16;
|
||||
//be::big_to_native(ui16);
|
||||
//BOOST_TEST_EQ(ui16, nui16);
|
||||
|
||||
ui16 = lui16;
|
||||
be::little_to_native(ui16);
|
||||
BOOST_TEST_EQ(ui16, nui16);
|
||||
|
||||
std::cout << " test_in_place_conditional_reorder complete\n";
|
||||
//ui16 = lui16;
|
||||
//be::little_to_native(ui16);
|
||||
//BOOST_TEST_EQ(ui16, nui16);
|
||||
//
|
||||
//std::cout << " test_in_place_conditional_reorder complete\n";
|
||||
}
|
||||
|
||||
void test_copying_conditional_reorder()
|
||||
{
|
||||
std::cout << "test_copying_conditional_reorder...\n";
|
||||
//std::cout << "test_copying_conditional_reorder...\n";
|
||||
|
||||
boost::int64_t i64, ti64;
|
||||
//boost::int64_t i64, ti64;
|
||||
|
||||
i64 = ni64;
|
||||
be::native_to_big(i64, ti64);
|
||||
BOOST_TEST_EQ(ti64, bi64);
|
||||
//i64 = ni64;
|
||||
//be::native_to_big(i64, ti64);
|
||||
//BOOST_TEST_EQ(ti64, bi64);
|
||||
|
||||
i64 = ni64;
|
||||
be::native_to_little(i64, ti64);
|
||||
BOOST_TEST_EQ(ti64, li64);
|
||||
//i64 = ni64;
|
||||
//be::native_to_little(i64, ti64);
|
||||
//BOOST_TEST_EQ(ti64, li64);
|
||||
|
||||
i64 = bi64;
|
||||
be::big_to_native(i64, ti64);
|
||||
BOOST_TEST_EQ(ti64, ni64);
|
||||
//i64 = bi64;
|
||||
//be::big_to_native(i64, ti64);
|
||||
//BOOST_TEST_EQ(ti64, ni64);
|
||||
|
||||
i64 = li64;
|
||||
be::little_to_native(i64, ti64);
|
||||
BOOST_TEST_EQ(ti64, ni64);
|
||||
//i64 = li64;
|
||||
//be::little_to_native(i64, ti64);
|
||||
//BOOST_TEST_EQ(ti64, ni64);
|
||||
|
||||
boost::uint64_t ui64, tui64;
|
||||
//boost::uint64_t ui64, tui64;
|
||||
|
||||
ui64 = nui64;
|
||||
be::native_to_big(ui64, tui64);
|
||||
BOOST_TEST_EQ(tui64, bui64);
|
||||
//ui64 = nui64;
|
||||
//be::native_to_big(ui64, tui64);
|
||||
//BOOST_TEST_EQ(tui64, bui64);
|
||||
|
||||
ui64 = nui64;
|
||||
be::native_to_little(ui64, tui64);
|
||||
BOOST_TEST_EQ(tui64, lui64);
|
||||
//ui64 = nui64;
|
||||
//be::native_to_little(ui64, tui64);
|
||||
//BOOST_TEST_EQ(tui64, lui64);
|
||||
|
||||
ui64 = bui64;
|
||||
be::big_to_native(ui64, tui64);
|
||||
BOOST_TEST_EQ(tui64, nui64);
|
||||
//ui64 = bui64;
|
||||
//be::big_to_native(ui64, tui64);
|
||||
//BOOST_TEST_EQ(tui64, nui64);
|
||||
|
||||
ui64 = lui64;
|
||||
be::little_to_native(ui64, tui64);
|
||||
BOOST_TEST_EQ(tui64, nui64);
|
||||
//ui64 = lui64;
|
||||
//be::little_to_native(ui64, tui64);
|
||||
//BOOST_TEST_EQ(tui64, nui64);
|
||||
|
||||
boost::int32_t i32, ti32;
|
||||
//boost::int32_t i32, ti32;
|
||||
|
||||
i32 = ni32;
|
||||
be::native_to_big(i32, ti32);
|
||||
BOOST_TEST_EQ(ti32, bi32);
|
||||
//i32 = ni32;
|
||||
//be::native_to_big(i32, ti32);
|
||||
//BOOST_TEST_EQ(ti32, bi32);
|
||||
|
||||
i32 = ni32;
|
||||
be::native_to_little(i32, ti32);
|
||||
BOOST_TEST_EQ(ti32, li32);
|
||||
//i32 = ni32;
|
||||
//be::native_to_little(i32, ti32);
|
||||
//BOOST_TEST_EQ(ti32, li32);
|
||||
|
||||
i32 = bi32;
|
||||
be::big_to_native(i32, ti32);
|
||||
BOOST_TEST_EQ(ti32, ni32);
|
||||
//i32 = bi32;
|
||||
//be::big_to_native(i32, ti32);
|
||||
//BOOST_TEST_EQ(ti32, ni32);
|
||||
|
||||
i32 = li32;
|
||||
be::little_to_native(i32, ti32);
|
||||
BOOST_TEST_EQ(ti32, ni32);
|
||||
//i32 = li32;
|
||||
//be::little_to_native(i32, ti32);
|
||||
//BOOST_TEST_EQ(ti32, ni32);
|
||||
|
||||
boost::uint32_t ui32, tui32;
|
||||
//boost::uint32_t ui32, tui32;
|
||||
|
||||
ui32 = nui32;
|
||||
be::native_to_big(ui32, tui32);
|
||||
BOOST_TEST_EQ(tui32, bui32);
|
||||
//ui32 = nui32;
|
||||
//be::native_to_big(ui32, tui32);
|
||||
//BOOST_TEST_EQ(tui32, bui32);
|
||||
|
||||
ui32 = nui32;
|
||||
be::native_to_little(ui32, tui32);
|
||||
BOOST_TEST_EQ(tui32, lui32);
|
||||
//ui32 = nui32;
|
||||
//be::native_to_little(ui32, tui32);
|
||||
//BOOST_TEST_EQ(tui32, lui32);
|
||||
|
||||
ui32 = bui32;
|
||||
be::big_to_native(ui32, tui32);
|
||||
BOOST_TEST_EQ(tui32, nui32);
|
||||
//ui32 = bui32;
|
||||
//be::big_to_native(ui32, tui32);
|
||||
//BOOST_TEST_EQ(tui32, nui32);
|
||||
|
||||
ui32 = lui32;
|
||||
be::little_to_native(ui32, tui32);
|
||||
BOOST_TEST_EQ(tui32, nui32);
|
||||
//ui32 = lui32;
|
||||
//be::little_to_native(ui32, tui32);
|
||||
//BOOST_TEST_EQ(tui32, nui32);
|
||||
|
||||
boost::int16_t i16, ti16;
|
||||
//boost::int16_t i16, ti16;
|
||||
|
||||
i16 = ni16;
|
||||
be::native_to_big(i16, ti16);
|
||||
BOOST_TEST_EQ(ti16, bi16);
|
||||
//i16 = ni16;
|
||||
//be::native_to_big(i16, ti16);
|
||||
//BOOST_TEST_EQ(ti16, bi16);
|
||||
|
||||
i16 = ni16;
|
||||
be::native_to_little(i16, ti16);
|
||||
BOOST_TEST_EQ(ti16, li16);
|
||||
//i16 = ni16;
|
||||
//be::native_to_little(i16, ti16);
|
||||
//BOOST_TEST_EQ(ti16, li16);
|
||||
|
||||
i16 = bi16;
|
||||
be::big_to_native(i16, ti16);
|
||||
BOOST_TEST_EQ(ti16, ni16);
|
||||
//i16 = bi16;
|
||||
//be::big_to_native(i16, ti16);
|
||||
//BOOST_TEST_EQ(ti16, ni16);
|
||||
|
||||
i16 = li16;
|
||||
be::little_to_native(i16, ti16);
|
||||
BOOST_TEST_EQ(ti16, ni16);
|
||||
//i16 = li16;
|
||||
//be::little_to_native(i16, ti16);
|
||||
//BOOST_TEST_EQ(ti16, ni16);
|
||||
|
||||
boost::uint16_t ui16, tui16;
|
||||
//boost::uint16_t ui16, tui16;
|
||||
|
||||
ui16 = nui16;
|
||||
be::native_to_big(ui16, tui16);
|
||||
BOOST_TEST_EQ(tui16, bui16);
|
||||
//ui16 = nui16;
|
||||
//be::native_to_big(ui16, tui16);
|
||||
//BOOST_TEST_EQ(tui16, bui16);
|
||||
|
||||
ui16 = nui16;
|
||||
be::native_to_little(ui16, tui16);
|
||||
BOOST_TEST_EQ(tui16, lui16);
|
||||
//ui16 = nui16;
|
||||
//be::native_to_little(ui16, tui16);
|
||||
//BOOST_TEST_EQ(tui16, lui16);
|
||||
|
||||
ui16 = bui16;
|
||||
be::big_to_native(ui16, tui16);
|
||||
BOOST_TEST_EQ(tui16, nui16);
|
||||
//ui16 = bui16;
|
||||
//be::big_to_native(ui16, tui16);
|
||||
//BOOST_TEST_EQ(tui16, nui16);
|
||||
|
||||
ui16 = lui16;
|
||||
be::little_to_native(ui16, tui16);
|
||||
BOOST_TEST_EQ(tui16, nui16);
|
||||
|
||||
//ui16 = lui16;
|
||||
//be::little_to_native(ui16, tui16);
|
||||
//BOOST_TEST_EQ(tui16, nui16);
|
||||
//
|
||||
std::cout << " test_copying_conditional_reorder complete\n";
|
||||
}
|
||||
|
||||
@@ -431,10 +351,8 @@ namespace
|
||||
int cpp_main(int, char * [])
|
||||
{
|
||||
std::cerr << std::hex;
|
||||
test_in_place_reorder();
|
||||
test_copying_reorder();
|
||||
test_reorder();
|
||||
test_in_place_conditional_reorder();
|
||||
test_copying_conditional_reorder();
|
||||
|
||||
return ::boost::report_errors();
|
||||
}
|
||||
|
@@ -70,7 +70,9 @@
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>BOOST_TWO_ARG;BOOST_ALL_NO_LIB;BOOST_ALL_DYN_LINK;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>BOOST_ALL_NO_LIB;BOOST_ALL_DYN_LINK;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AssemblerOutput>AssemblyAndSourceCode</AssemblerOutput>
|
||||
<AssemblerListingLocation>$(IntDir)</AssemblerListingLocation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.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>{6FAF820B-F436-46A2-A1DD-4A4B7025C3D0}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>conversion2_test</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</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>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</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>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\conversion2_test.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "conversion_test", "conversi
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "benchmark", "benchmark\benchmark.vcxproj", "{C9FEAE75-4DD9-44F5-B302-9910559A91BE}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "conversion2_test", "conversion2_test\conversion2_test.vcxproj", "{6FAF820B-F436-46A2-A1DD-4A4B7025C3D0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
@@ -49,6 +51,10 @@ Global
|
||||
{C9FEAE75-4DD9-44F5-B302-9910559A91BE}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{C9FEAE75-4DD9-44F5-B302-9910559A91BE}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{C9FEAE75-4DD9-44F5-B302-9910559A91BE}.Release|Win32.Build.0 = Release|Win32
|
||||
{6FAF820B-F436-46A2-A1DD-4A4B7025C3D0}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{6FAF820B-F436-46A2-A1DD-4A4B7025C3D0}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{6FAF820B-F436-46A2-A1DD-4A4B7025C3D0}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{6FAF820B-F436-46A2-A1DD-4A4B7025C3D0}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Reference in New Issue
Block a user