Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74331 - in sandbox/endian: boost/endian libs/endian/test
From: bdawes_at_[hidden]
Date: 2011-09-09 16:03:14


Author: bemandawes
Date: 2011-09-09 16:03:13 EDT (Fri, 09 Sep 2011)
New Revision: 74331
URL: http://svn.boost.org/trac/boost/changeset/74331

Log:
Test complete for [u]int16_t[n]_t overloads
Text files modified:
   sandbox/endian/boost/endian/conversion2.hpp | 32 ++--
   sandbox/endian/libs/endian/test/conversion2_test.cpp | 257 ++++-----------------------------------
   2 files changed, 45 insertions(+), 244 deletions(-)

Modified: sandbox/endian/boost/endian/conversion2.hpp
==============================================================================
--- sandbox/endian/boost/endian/conversion2.hpp (original)
+++ sandbox/endian/boost/endian/conversion2.hpp 2011-09-09 16:03:13 EDT (Fri, 09 Sep 2011)
@@ -82,14 +82,12 @@
 
   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);
+ uint64_t step32, step16;
+ step32 = static_cast<uint64_t>(x) << 32 | static_cast<uint64_t>(x) >> 32;
+ step16 = (step32 & 0x0000FFFF0000FFFF) << 16
+ | (step32 & 0xFFFF0000FFFF0000) >> 16;
+ return static_cast<int64_t>((step16 & 0x00FF00FF00FF00FF) << 8
+ | (step16 & 0xFF00FF00FF00FF00) >> 8);
   }
 
   inline uint16_t reorder(uint16_t x)
@@ -109,14 +107,12 @@
 
   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);
+ uint64_t step32, step16;
+ step32 = x << 32 | x >> 32;
+ step16 = (step32 & 0x0000FFFF0000FFFF) << 16
+ | (step32 & 0xFFFF0000FFFF0000) >> 16;
+ return (step16 & 0x00FF00FF00FF00FF) << 8
+ | (step16 & 0xFF00FF00FF00FF00) >> 8;
   }
 
 
@@ -132,7 +128,7 @@
   }
 
   template <class T>
- inline T big(const T& x)
+ inline T big(const T& x)
   {
 # ifdef BOOST_BIG_ENDIAN
       return x;
@@ -142,7 +138,7 @@
   }
 
   template <class T>
- inline T little(const T& x)
+ inline T little(const T& x)
   {
 # ifdef BOOST_LITTLE_ENDIAN
       return x;

Modified: sandbox/endian/libs/endian/test/conversion2_test.cpp
==============================================================================
--- sandbox/endian/libs/endian/test/conversion2_test.cpp (original)
+++ sandbox/endian/libs/endian/test/conversion2_test.cpp 2011-09-09 16:03:13 EDT (Fri, 09 Sep 2011)
@@ -116,234 +116,39 @@
   const boost::uint16_t lui16 = 0x0102;
 # endif
 
- void test_in_place_conditional_reorder()
+ void test_conditional_reorder()
   {
- //std::cout << "test_in_place_conditional_reorder...\n";
+ std::cout << "test_conditional_reorder...\n";
 
- //boost::int64_t i64;
+ BOOST_TEST_EQ(be::big(ni64), bi64);
+ BOOST_TEST_EQ(be::big(ni32), bi32);
+ BOOST_TEST_EQ(be::big(ni16), bi16);
+ BOOST_TEST_EQ(be::big(nui64), bui64);
+ BOOST_TEST_EQ(be::big(nui32), bui32);
+ BOOST_TEST_EQ(be::big(nui16), bui16);
+
+ BOOST_TEST_EQ(be::little(ni64), li64);
+ BOOST_TEST_EQ(be::little(ni32), li32);
+ BOOST_TEST_EQ(be::little(ni16), li16);
+ BOOST_TEST_EQ(be::little(nui64), lui64);
+ BOOST_TEST_EQ(be::little(nui32), lui32);
+ BOOST_TEST_EQ(be::little(nui16), lui16);
+
+ BOOST_TEST_EQ(be::big(be::big(ni64)), ni64);
+ BOOST_TEST_EQ(be::big(be::big(ni32)), ni32);
+ BOOST_TEST_EQ(be::big(be::big(ni16)), ni16);
+ BOOST_TEST_EQ(be::big(be::big(nui64)), nui64);
+ BOOST_TEST_EQ(be::big(be::big(nui32)), nui32);
+ BOOST_TEST_EQ(be::big(be::big(nui16)), nui16);
+
+ BOOST_TEST_EQ(be::little(be::little(ni64)), ni64);
+ BOOST_TEST_EQ(be::little(be::little(ni32)), ni32);
+ BOOST_TEST_EQ(be::little(be::little(ni16)), ni16);
+ BOOST_TEST_EQ(be::little(be::little(nui64)), nui64);
+ BOOST_TEST_EQ(be::little(be::little(nui32)), nui32);
+ BOOST_TEST_EQ(be::little(be::little(nui16)), nui16);
 
- //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 = bi64;
- //be::big_to_native(i64);
- //BOOST_TEST_EQ(i64, ni64);
-
- //i64 = li64;
- //be::little_to_native(i64);
- //BOOST_TEST_EQ(i64, ni64);
-
- //boost::uint64_t ui64;
-
- //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 = bui64;
- //be::big_to_native(ui64);
- //BOOST_TEST_EQ(ui64, nui64);
-
- //ui64 = lui64;
- //be::little_to_native(ui64);
- //BOOST_TEST_EQ(ui64, nui64);
-
- //boost::int32_t i32;
-
- //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 = bi32;
- //be::big_to_native(i32);
- //BOOST_TEST_EQ(i32, ni32);
-
- //i32 = li32;
- //be::little_to_native(i32);
- //BOOST_TEST_EQ(i32, ni32);
-
- //boost::uint32_t ui32;
-
- //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 = bui32;
- //be::big_to_native(ui32);
- //BOOST_TEST_EQ(ui32, nui32);
-
- //ui32 = lui32;
- //be::little_to_native(ui32);
- //BOOST_TEST_EQ(ui32, nui32);
-
- //boost::int16_t i16;
-
- //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 = bi16;
- //be::big_to_native(i16);
- //BOOST_TEST_EQ(i16, ni16);
-
- //i16 = li16;
- //be::little_to_native(i16);
- //BOOST_TEST_EQ(i16, ni16);
-
- //boost::uint16_t ui16;
-
- //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 = 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";
- }
-
- void test_copying_conditional_reorder()
- {
- //std::cout << "test_copying_conditional_reorder...\n";
-
- //boost::int64_t i64, ti64;
-
- //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 = 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);
-
- //boost::uint64_t ui64, tui64;
-
- //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 = 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);
-
- //boost::int32_t i32, ti32;
-
- //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 = 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);
-
- //boost::uint32_t ui32, tui32;
-
- //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 = 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);
-
- //boost::int16_t i16, ti16;
-
- //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 = 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);
-
- //boost::uint16_t ui16, tui16;
-
- //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 = 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);
- //
- std::cout << " test_copying_conditional_reorder complete\n";
+ std::cout << " test_conditional_reorder complete\n";
   }
 
 } // unnamed namespace
@@ -352,7 +157,7 @@
 {
   std::cerr << std::hex;
   test_reorder();
- test_in_place_conditional_reorder();
+ test_conditional_reorder();
 
   return ::boost::report_errors();
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk