diff --git a/doc/arithmetic.html b/doc/arithmetic.html index 17040dd..c150df3 100644 --- a/doc/arithmetic.html +++ b/doc/arithmetic.html @@ -75,7 +75,7 @@

Introduction

-

Header boost/endian/types.hpp +

Header boost/endian/arithmetic.hpp provides integer and floating point binary types with control over byte order, value type, size, and alignment. Typedefs provide easy-to-use names for common configurations.

@@ -102,7 +102,7 @@ arithmetic operators are +, +=, -, ^, ^=, <<, <<=, >>, >>=. Binary relational operators are ==, !=, <, <=, >, >=.

-

Automatic implicit conversion to the underlying value type is provided. An +

Automatic implicit conversion to the underlying value type is provided. A conversion constructor from the underlying value type is provided.

Example

The endian_example.cpp program writes a diff --git a/example/udt_conversion_example.cpp b/example/udt_conversion_example.cpp index 07186a5..0fda762 100644 --- a/example/udt_conversion_example.cpp +++ b/example/udt_conversion_example.cpp @@ -40,7 +40,8 @@ public: desc_[sizeof(desc_-1)] = '\0'; } - friend void reverse(UDT&); + friend UDT reverse_endianness(const UDT&); + friend void reverse_endianness_in_place(UDT&); private: int32_t id_; @@ -48,35 +49,36 @@ private: char desc_[56]; // '/0' }; -void reverse(UDT& x) +void reverse_endianness_in_place(UDT& x) { - reverse(x.id_); - reverse(x.value_); + reverse_endianness_in_place(x.id_); + reverse_endianness_in_place(x.value_); } int main(int, char* []) { UDT x(1, 1.2345f, "Bingo!"); - cout << std::hex; - cout << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; - reverse(x); - cout << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; + //cout << std::hex; + cout << "(1) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; - reverse(x); - cout << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; + reverse_endianness_in_place(x); + cout << "(2) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; - big_endian(x); - cout << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; + reverse_endianness_in_place(x); + cout << "(3) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; - little_endian(x); - cout << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; + reverse_in_place_unless_native_big(x); + cout << "(4) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; - convert(x); - cout << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; + reverse_in_place_unless_native_little(x); + cout << "(5) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; - convert(x, order::big, order::little); - cout << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; + conditional_reverse_in_place(x); + cout << "(6) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; + + runtime_conditional_reverse_in_place(x, order::big, order::little); + cout << "(7) " << x.id() << ' ' << x.value() << ' ' << x.desc() << endl; } #include diff --git a/example/use_cases.cpp b/example/use_cases.cpp index ab6b2ab..adb3844 100644 --- a/example/use_cases.cpp +++ b/example/use_cases.cpp @@ -9,65 +9,179 @@ #define _SCL_SECURE_NO_WARNINGS -#include - -#define BOOST_ENDIAN_LOG -#include +#include #include -#include -#include +#include #include // Maximize chance of name clashes for testing purposes using namespace boost::endian; -using namespace std; using std::cout; using std::endl; -//using boost::int8_t; -//using boost::uint8_t; -//using boost::int16_t; -//using boost::uint16_t; -//using boost::int32_t; -//using boost::uint32_t; -//using boost::int64_t; -//using boost::uint64_t; -namespace + +void read(void* data, std::size_t sz); // for exposition +void write(const void* data, std::size_t sz); // for exposition +const int32_t fee(100); // for exposition + +int main(int, char *[]) { -} // unnamed namespace + { + // Q: Should endian_buffer supply "value_type operator value_type() const noexcept"? + // A: No. The whole point of the endian_buffers is to prevent high-cost hidden + // conversions. If an implicit conversion operator is supplied, hidden conversions + // can occur. -int cpp_main(int, char *[]) -{ - cout << "byte swap intrinsics: " BOOST_ENDIAN_INTRINSIC_MSG << endl; + big_buf32_t v(5); + int32_t x; + x = v * v; // error: operator not defined & no conversion available + x = v.value() * v.value(); // OK, conversion visable. "cvt" or "native" better name? + + } - big_int32_t i1(1), i2(2), i3; - big_buf32_t b1(1), b2(2), b3; + { // Use case 1 - Conversion functions - cout << "endian buffer tests" << endl; - cout << "compute\n"; - i3 = i1 + 5; - cout << "test\n"; - BOOST_TEST(i3 == 6); - cout << "compute\n"; - i3 = i1 + i2; - cout << "test\n"; - BOOST_TEST(i3 == 3); + struct Record + { + uint32_t count; // big endian + int32_t value; // big endian + }; - cout << "endian integer tests" << endl; - cout << "compute\n"; - b3 = b1 + 5; - cout << "test\n"; - BOOST_TEST(b3 == 6); - cout << "compute\n"; - b3 = b1 + b2; - cout << "test\n"; - BOOST_TEST(b3 == 3); + Record rec; + read(&rec, sizeof(Record)); + uint32_t count = big(rec.count); + int32_t value = big(rec.value); + ++count; + value += fee; + + rec.count = big(count); + rec.value = big(value); + + write(&rec, sizeof(Record)); + } + + { // Use case 2 - Endian buffer types + + struct Record + { + big_ubuf32_t count; // big endian + big_buf32_t value; // big endian + }; + + Record rec; + + read(&rec, sizeof(Record)); + + uint32_t count = rec.count.value(); + int32_t value = rec.value.value(); + + ++count; + value += fee; + + rec.count = count; + rec.value = value; + + write(&rec, sizeof(Record)); + } + + { // Use case 3a - Endian arithmetic types + + struct Record + { + big_uint32_t count; // big endian + big_int32_t value; // big endian + }; + + Record rec; + + read(&rec, sizeof(Record)); + + ++rec.count; + rec.value += fee; + + write(&rec, sizeof(Record)); + } + + { // Use case 3b - Endian arithmetic types + + struct Record + { + big_uint32_t count; // big endian + big_int32_t value; // big endian + }; + + Record rec; + + read(&rec, sizeof(Record)); + + uint32_t count = rec.count; + int32_t value = rec.value; + + ++count; + value += fee; + + rec.count = count; + rec.value = value; + + write(&rec, sizeof(Record)); + } + + // Recommended approach when conversion time is not a concern + // + // Conversion time is not a concert with this application because the minimum + // possible number of conversions is performed and because I/O time will be + // much greater than conversion time. + + { + struct Record + { + big_uint32_t count; // big endian + big_int32_t value; // big endian + }; + + Record rec; + + read(&rec, sizeof(Record)); + + ++rec.count; + rec.value += fee; + + write(&rec, sizeof(Record)); + } + +// Recommended approach when conversion time is a concern + // + // Conversion time is a concert with this application because (1) any conversions + // performed in the loop will consume a great deal of time and because (2) + // computation time will be much greater than I/O time. + + { + struct Record + { + big_uint32_t count; // big endian + big_int32_t value; // big endian + }; + + Record rec; + + read(&rec, sizeof(Record)); + + uint32_t count = rec.count; + int32_t value = rec.value; + + for (long long i = 0; i < several_gazillion; ++i) // (1) + { + ... immensely complex computation using rec variables many times // (2) + } + + rec.count = count; + rec.value = value; + + write(&rec, sizeof(Record)); + } - return ::boost::report_errors(); } - -#include diff --git a/include/boost/endian/arithmetic.hpp b/include/boost/endian/arithmetic.hpp index 0072129..48198ec 100644 --- a/include/boost/endian/arithmetic.hpp +++ b/include/boost/endian/arithmetic.hpp @@ -383,13 +383,13 @@ namespace endian if ( endian_log ) std::cout << "big, aligned, " << n_bits << "-bits, construct(" << val << ")\n"; # endif - this->m_value = ::boost::endian::big_endian_value(val); + this->m_value = ::boost::endian::native_to_big(val); } # endif endian_arithmetic& operator=(T val) BOOST_NOEXCEPT { - this->m_value = ::boost::endian::big_endian_value(val); + this->m_value = ::boost::endian::native_to_big(val); return *this; } operator value_type() const BOOST_NOEXCEPT { return this->value(); } @@ -413,12 +413,12 @@ namespace endian if ( endian_log ) std::cout << "little, aligned, " << n_bits << "-bits, construct(" << val << ")\n"; # endif - this->m_value = ::boost::endian::little_endian_value(val); + this->m_value = ::boost::endian::native_to_little(val); } # endif endian_arithmetic& operator=(T val) BOOST_NOEXCEPT { - this->m_value = ::boost::endian::little_endian_value(val); + this->m_value = ::boost::endian::native_to_little(val); return *this; } operator value_type() const BOOST_NOEXCEPT { return this->value(); } diff --git a/include/boost/endian/buffers.hpp b/include/boost/endian/buffers.hpp index 55fa120..c89e307 100644 --- a/include/boost/endian/buffers.hpp +++ b/include/boost/endian/buffers.hpp @@ -516,27 +516,27 @@ namespace endian std::cout << "big, aligned, " << n_bits << "-bits, construct(" << val << ")\n"; # endif - m_value = ::boost::endian::big_endian_value(val); + m_value = ::boost::endian::native_to_big(val); } # endif endian_buffer& operator=(T val) BOOST_NOEXCEPT { - m_value = ::boost::endian::big_endian_value(val); + m_value = ::boost::endian::native_to_big(val); return *this; } //operator value_type() const BOOST_NOEXCEPT - //{ - // return ::boost::endian::big_endian_value(m_value); + //{ + // return ::boost::endian::big_to_native(m_value); //} value_type value() const BOOST_NOEXCEPT { # ifdef BOOST_ENDIAN_LOG if ( endian_log ) std::cout << "big, aligned, " << n_bits << "-bits, convert(" - << ::boost::endian::big_endian_value(m_value) << ")\n"; + << ::boost::endian::big_to_native(m_value) << ")\n"; # endif - return ::boost::endian::big_endian_value(m_value); + return ::boost::endian::big_to_native(m_value); } const char* data() const BOOST_NOEXCEPT {return reinterpret_cast(&m_value);} @@ -561,13 +561,13 @@ namespace endian std::cout << "little, aligned, " << n_bits << "-bits, construct(" << val << ")\n"; # endif - m_value = ::boost::endian::little_endian_value(val); + m_value = ::boost::endian::native_to_little(val); } # endif endian_buffer& operator=(T val) BOOST_NOEXCEPT { - m_value = ::boost::endian::little_endian_value(val); + m_value = ::boost::endian::native_to_little(val); return *this; } value_type value() const BOOST_NOEXCEPT @@ -575,9 +575,9 @@ namespace endian # ifdef BOOST_ENDIAN_LOG if ( endian_log ) std::cout << "little, aligned, " << n_bits << "-bits, convert(" - << ::boost::endian::little_endian_value(m_value) << ")\n"; + << ::boost::endian::little_to_native(m_value) << ")\n"; # endif - return ::boost::endian::little_endian_value(m_value); + return ::boost::endian::little_to_native(m_value); } const char* data() const BOOST_NOEXCEPT {return reinterpret_cast(&m_value);} diff --git a/include/boost/endian/conversion.hpp b/include/boost/endian/conversion.hpp index f6e3b98..bd5e7fc 100644 --- a/include/boost/endian/conversion.hpp +++ b/include/boost/endian/conversion.hpp @@ -72,6 +72,9 @@ namespace endian template inline Reversible native_to_big(Reversible x) BOOST_NOEXCEPT; // Returns: x if native endian order is big, otherwise reverse_endianness(x) + template + inline Reversible reverse_unless_native_big(Reversible x) BOOST_NOEXCEPT; + // Returns: x if native endian order is big, otherwise reverse_endianness(x) // reverse byte order unless native endianness is little template @@ -80,6 +83,9 @@ namespace endian template inline Reversible native_to_little(Reversible x) BOOST_NOEXCEPT; // Returns: x if native endian order is little, otherwise reverse_endianness(x) + template + inline Reversible reverse_unless_native_little(Reversible x) BOOST_NOEXCEPT; + // Returns: x if native endian order is little, otherwise reverse_endianness(x) // generic conditional reverse byte order template @@ -141,6 +147,9 @@ namespace endian template inline void native_to_big_in_place(Reversible& x) BOOST_NOEXCEPT; // Effects: none if native byte-order is big, otherwise reverse_endianness_in_place(x) + template + inline void reverse_in_place_unless_native_big(Reversible& x) BOOST_NOEXCEPT; + // Effects: none if native byte-order is big, otherwise reverse_endianness_in_place(x) // reverse in place unless native endianness is little template @@ -149,6 +158,9 @@ namespace endian template inline void native_to_little_in_place(Reversible& x) BOOST_NOEXCEPT; // Effects: none if native byte-order is little, otherwise reverse_endianness_in_place(x); + template + inline void reverse_in_place_unless_native_little(Reversible& x) BOOST_NOEXCEPT; + // Effects: none if native byte-order is little, otherwise reverse_endianness_in_place(x); // generic conditional reverse in place template @@ -264,7 +276,7 @@ namespace endian // suggested by Mathias Gaunard. Primary motivation for inclusion is to have an // independent implementation to test against. Secondary motivation is use by // floating-point reverse_endianness, but that use is likely to be replace by a - // more tailored floating-point algorithm. + // more tailored floating-point implementation. template inline T std_reverse_endianness(T x) BOOST_NOEXCEPT @@ -275,6 +287,16 @@ namespace endian reinterpret_cast(&tmp) + sizeof(T)); return tmp; } + + // conditional unaligned reverse copy, patterned after std::reverse_copy + template + inline void big_reverse_copy(T from, char* to) BOOST_NOEXCEPT; + template + inline void big_reverse_copy(const char* from, T& to) BOOST_NOEXCEPT; + template + inline void little_reverse_copy(T from, char* to) BOOST_NOEXCEPT; + template + inline void little_reverse_copy(const char* from, T& to) BOOST_NOEXCEPT; } // namespace detail inline float reverse_endianness(float x) BOOST_NOEXCEPT @@ -313,6 +335,16 @@ namespace endian # endif } + template + inline Reversible reverse_unless_native_big(Reversible x) BOOST_NOEXCEPT + { +# ifdef BOOST_BIG_ENDIAN + return x; +# else + return reverse_endianness(x); +# endif + } + template inline Reversible little_to_native(Reversible x) BOOST_NOEXCEPT { @@ -333,6 +365,16 @@ namespace endian # endif } + template + inline Reversible reverse_unless_native_little(Reversible x) BOOST_NOEXCEPT + { +# ifdef BOOST_LITTLE_ENDIAN + return x; +# else + return reverse_endianness(x); +# endif + } + namespace detail { // Primary template and specializations to support reverse_endianness(). @@ -408,7 +450,18 @@ namespace endian inline void native_to_big_in_place(Reversible&) BOOST_NOEXCEPT {} # else inline void native_to_big_in_place(Reversible& x) BOOST_NOEXCEPT - { reverse_endianness_in_place(x); } + { + reverse_endianness_in_place(x); + } +# endif + template +# ifdef BOOST_BIG_ENDIAN + inline void reverse_in_place_unless_native_big(Reversible&) BOOST_NOEXCEPT {} +# else + inline void reverse_in_place_unless_native_big(Reversible& x) BOOST_NOEXCEPT + { + reverse_endianness_in_place(x); + } # endif // reverse in place unless native endianness is little @@ -426,7 +479,18 @@ namespace endian inline void native_to_little_in_place(Reversible&) BOOST_NOEXCEPT {} # else inline void native_to_little_in_place(Reversible& x) BOOST_NOEXCEPT - { reverse_endianness_in_place(x); } + { + reverse_endianness_in_place(x); + } +# endif + template +# ifdef BOOST_LITTLE_ENDIAN + inline void reverse_in_place_unless_native_little(Reversible&) BOOST_NOEXCEPT {} +# else + inline void reverse_in_place_unless_native_little(Reversible& x) BOOST_NOEXCEPT + { + reverse_endianness_in_place(x); + } # endif namespace detail @@ -467,6 +531,59 @@ namespace endian reverse_endianness_in_place(x); } + + namespace detail + { + // general reverse_value function template implementation approach using std::reverse + // suggested by Mathias Gaunard + template + inline T reverse_value(T x) BOOST_NOEXCEPT + { + T tmp(x); + std::reverse( + reinterpret_cast(&tmp), + reinterpret_cast(&tmp) + sizeof(T)); + return tmp; + } + template + inline void big_reverse_copy(T from, char* to) BOOST_NOEXCEPT + { +# ifdef BOOST_BIG_ENDIAN + std::memcpy(to, reinterpret_cast(&from), sizeof(T)); +# else + std::reverse_copy(reinterpret_cast(&from), + reinterpret_cast(&from) + sizeof(T), to); +# endif + } + template + inline void big_reverse_copy(const char* from, T& to) BOOST_NOEXCEPT + { +# ifdef BOOST_BIG_ENDIAN + std::memcpy(reinterpret_cast(&to), from, sizeof(T)); +# else + std::reverse_copy(from, from + sizeof(T), reinterpret_cast(&to)); +# endif + } + template + inline void little_reverse_copy(T from, char* to) BOOST_NOEXCEPT + { +# ifdef BOOST_LITTLE_ENDIAN + std::memcpy(to, reinterpret_cast(&from), sizeof(T)); +# else + std::reverse_copy(reinterpret_cast(&from), + reinterpret_cast(&from) + sizeof(T), to); +# endif + } + template + inline void little_reverse_copy(const char* from, T& to) BOOST_NOEXCEPT + { +# ifdef BOOST_LITTLE_ENDIAN + std::memcpy(reinterpret_cast(&to), from, sizeof(T)); +# else + std::reverse_copy(from, from + sizeof(T), reinterpret_cast(&to)); +# endif + } + } // namespace detail } // namespace endian } // namespace boost diff --git a/name_changes.sed b/name_changes.sed new file mode 100644 index 0000000..2660777 --- /dev/null +++ b/name_changes.sed @@ -0,0 +1,9 @@ +# invoke: sed -r -i -f + +# name changes in arithmetic.hpp +s/(big|little|native)_(int|uint|float)(8|16|24|32|40|48|56|64)_t/\1_\2\3_ut/g +s/(big|little|native)_align_(int|uint|float)(8|16|24|32|40|48|56|64)_t/\1_\2\3_t/g + +# name changes in conversion.hpp +s/(big|little)_endian\(/reverse_in_place_unless_native_\1(/g +s/(big|little)_endian_value\(/reverse_unless_native_\1(/g diff --git a/test/benchmark.cpp b/test/benchmark.cpp index b6c734d..eabddbd 100644 --- a/test/benchmark.cpp +++ b/test/benchmark.cpp @@ -6,6 +6,7 @@ // http://www.boost.org/LICENSE_1_0.txt #define _CRT_SECURE_NO_WARNINGS +#define _SCL_SECURE_NO_WARNINGS #include #include diff --git a/test/buffer_test.cpp b/test/buffer_test.cpp index 69846ab..a6bd5a4 100644 --- a/test/buffer_test.cpp +++ b/test/buffer_test.cpp @@ -29,15 +29,15 @@ int cpp_main(int, char *[]) cout << "byte swap intrinsics: " BOOST_ENDIAN_INTRINSIC_MSG << endl; cout << " construct" << endl; - bel::big_buf32_t x(1122334455); + bel::big_int32_buf_t x(1122334455); cout << " assign from built-in integer" << endl; x = 1234567890; cout << " operator==(buffer, built-in)" << endl; -// bool b1(x == 1234567890); + bool b1(x.value() == 1234567890); + BOOST_TEST(b1); - // BOOST_TEST(x == 1234567890); cout << " done" << endl; return ::boost::report_errors(); diff --git a/test/endian_test.cpp b/test/endian_test.cpp index 1a44874..290522b 100644 --- a/test/endian_test.cpp +++ b/test/endian_test.cpp @@ -604,25 +604,25 @@ namespace { // aligned floating point types float big_float32_expected = (std::numeric_limits::max) (); - boost::endian::big_endian(big_float32_expected); + boost::endian::native_to_big_in_place(big_float32_expected); big_float32_t big_float32((std::numeric_limits::max) ()); VERIFY(std::memcmp(big_float32.data(), reinterpret_cast(&big_float32_expected), sizeof(float)) == 0); float little_float32_expected = (std::numeric_limits::max) (); - boost::endian::little_endian(little_float32_expected); + boost::endian::native_to_little_in_place(little_float32_expected); little_float32_t little_float32((std::numeric_limits::max) ()); VERIFY(std::memcmp(little_float32.data(), reinterpret_cast(&little_float32_expected), sizeof(float)) == 0); double big_float64_expected = (std::numeric_limits::max) (); - boost::endian::big_endian(big_float64_expected); + boost::endian::native_to_big_in_place(big_float64_expected); big_float64_t big_float64((std::numeric_limits::max) ()); VERIFY(std::memcmp(big_float64.data(), reinterpret_cast(&big_float64_expected), sizeof(double)) == 0); double little_float64_expected = (std::numeric_limits::max) (); - boost::endian::little_endian(little_float64_expected); + boost::endian::native_to_little_in_place(little_float64_expected); little_float64_t little_float64((std::numeric_limits::max) ()); VERIFY(std::memcmp(little_float64.data(), reinterpret_cast(&little_float64_expected), sizeof(double)) == 0); @@ -639,25 +639,25 @@ namespace // unaligned floating point types float big_float32un_expected = (std::numeric_limits::max) (); - boost::endian::big_endian(big_float32un_expected); + boost::endian::native_to_big_in_place(big_float32un_expected); big_float32_ut big_float32un((std::numeric_limits::max) ()); VERIFY(std::memcmp(big_float32un.data(), reinterpret_cast(&big_float32un_expected), sizeof(float)) == 0); float little_float32un_expected = (std::numeric_limits::max) (); - boost::endian::little_endian(little_float32un_expected); + boost::endian::native_to_little_in_place(little_float32un_expected); little_float32_ut little_float32un((std::numeric_limits::max) ()); VERIFY(std::memcmp(little_float32un.data(), reinterpret_cast(&little_float32un_expected), sizeof(float)) == 0); double big_float64un_expected = (std::numeric_limits::max) (); - boost::endian::big_endian(big_float64un_expected); + boost::endian::native_to_big_in_place(big_float64un_expected); big_float64_ut big_float64un((std::numeric_limits::max) ()); VERIFY(std::memcmp(big_float64un.data(), reinterpret_cast(&big_float64un_expected), sizeof(double)) == 0); double little_float64un_expected = (std::numeric_limits::max) (); - boost::endian::little_endian(little_float64un_expected); + boost::endian::native_to_little_in_place(little_float64un_expected); little_float64_ut little_float64un((std::numeric_limits::max) ()); VERIFY(std::memcmp(little_float64un.data(), reinterpret_cast(&little_float64un_expected), sizeof(double)) == 0); diff --git a/test/loop_time_test.cpp b/test/loop_time_test.cpp index 0c8c67f..d907565 100644 --- a/test/loop_time_test.cpp +++ b/test/loop_time_test.cpp @@ -101,14 +101,14 @@ namespace // cout << "***************Endian conversion approach...\n"; T x(0); boost::timer::cpu_timer t; - big_endian(x); + native_to_big_in_place(x); for (uint64_t i = 0; i < n; ++i) { x += static_cast(i); } - big_endian(x); + big_to_native_in_place(x); t.stop(); - big_endian(x); + native_to_big_in_place(x); if (x != total) throw std::logic_error("integer approach total != conversion approach total"); cout << "" << t.format(places, "%t") << " s"; diff --git a/test/msvc/endian.sln b/test/msvc/endian.sln index 38875dd..d311805 100644 --- a/test/msvc/endian.sln +++ b/test/msvc/endian.sln @@ -17,8 +17,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "benchmark", "benchmark\benc EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "converter_test", "converter_test\converter_test.vcxproj", "{EAE18F4D-AAF2-4C19-86FB-1144B5BD5993}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pair_test", "pair_test\pair_test.vcxproj", "{5223CCD9-F1D4-4778-9BFD-242533DFE380}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "udt_conversion_example", "udt_conversion_example\udt_conversion_example.vcxproj", "{27A53564-D32B-4A32-8A6E-2F3BD252EEBA}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "speed_test", "speed_test\speed_test.vcxproj", "{5407AF29-59E9-4DE2-9939-F067576F7868}" @@ -89,14 +87,6 @@ Global {EAE18F4D-AAF2-4C19-86FB-1144B5BD5993}.Release|Win32.Build.0 = Release|Win32 {EAE18F4D-AAF2-4C19-86FB-1144B5BD5993}.Release|x64.ActiveCfg = Release|x64 {EAE18F4D-AAF2-4C19-86FB-1144B5BD5993}.Release|x64.Build.0 = Release|x64 - {5223CCD9-F1D4-4778-9BFD-242533DFE380}.Debug|Win32.ActiveCfg = Debug|Win32 - {5223CCD9-F1D4-4778-9BFD-242533DFE380}.Debug|Win32.Build.0 = Debug|Win32 - {5223CCD9-F1D4-4778-9BFD-242533DFE380}.Debug|x64.ActiveCfg = Debug|x64 - {5223CCD9-F1D4-4778-9BFD-242533DFE380}.Debug|x64.Build.0 = Debug|x64 - {5223CCD9-F1D4-4778-9BFD-242533DFE380}.Release|Win32.ActiveCfg = Release|Win32 - {5223CCD9-F1D4-4778-9BFD-242533DFE380}.Release|Win32.Build.0 = Release|Win32 - {5223CCD9-F1D4-4778-9BFD-242533DFE380}.Release|x64.ActiveCfg = Release|x64 - {5223CCD9-F1D4-4778-9BFD-242533DFE380}.Release|x64.Build.0 = Release|x64 {27A53564-D32B-4A32-8A6E-2F3BD252EEBA}.Debug|Win32.ActiveCfg = Debug|Win32 {27A53564-D32B-4A32-8A6E-2F3BD252EEBA}.Debug|Win32.Build.0 = Debug|Win32 {27A53564-D32B-4A32-8A6E-2F3BD252EEBA}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/test/msvc/pair_test/pair_test.vcxproj b/test/msvc/pair_test/pair_test.vcxproj deleted file mode 100644 index 2d0c00f..0000000 --- a/test/msvc/pair_test/pair_test.vcxproj +++ /dev/null @@ -1,151 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {5223CCD9-F1D4-4778-9BFD-242533DFE380} - Win32Proj - pair_test - - - - Application - true - v140 - Unicode - - - Application - true - v140 - Unicode - - - Application - false - v140 - true - Unicode - - - Application - false - v140 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - - true - - - true - - - false - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/test/pair_test.cpp b/test/pair_test.cpp deleted file mode 100644 index 7c851e2..0000000 --- a/test/pair_test.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// pair_test.cpp ---------------------------------------------------------------------// - -// Copyright Beman Dawes 2013 - -// Distributed under the Boost Software License, Version 1.0. -// http://www.boost.org/LICENSE_1_0.txt - -//--------------------------------------------------------------------------------------// - -#include - -#include -#include -#include -#include -#include -#include - -using namespace boost::endian; -using std::cout; -using std::endl; -using boost::int16_t; -using boost::uint16_t; -using boost::int32_t; -using boost::uint32_t; -using boost::int64_t; -using boost::uint64_t; - -namespace -{ - - typedef std::pair MyPair; - - template - OS& operator<<(OS& os, MyPair my) - { - const char* first = reinterpret_cast(&my.first); - const char* second = reinterpret_cast(&my.second); - - os << std::hex - << int(*first) << ' ' << int(*(first+1)) << ", " - << int(*second) << ' ' << int(*(second+1)) << ' ' - << int(*(second+2)) << ' ' << int(*(second+3)) - << std::dec << std::endl; - return os; - } - -} // unnamed namespace - -//--------------------------------------------------------------------------------------// - -int cpp_main(int, char * []) -{ - cout << "pair_test" << endl << endl; - - MyPair x(0x0102, 0x01020304); - MyPair y(big_endian_value(x)); - MyPair z(little_endian_value(x)); - - cout << "native: " << x; - cout << " big: " << y; - cout << "little: " << z << endl; - - big_endian(x); - cout << " big: " << x; - reverse(x); - little_endian(x); - cout << "little: " << x << endl; - - convert(x, order::little, order::native); - y = MyPair(0, 0); - y = convert_value(x, order::native, order::big); - z = x; - little_endian(z); - cout << "native: " << x; - cout << " big: " << y; - cout << "little: " << z << endl; - - cout << " big: " << y; - convert(y); - cout << "little: " << y << endl; - convert(y); - - return ::boost::report_errors(); -} - -#include diff --git a/test/speed_test.cpp b/test/speed_test.cpp index c8adfc2..4f46835 100644 --- a/test/speed_test.cpp +++ b/test/speed_test.cpp @@ -99,60 +99,60 @@ namespace void test_big_int16() { cout << "16-bit aligned big endian"; - time(user::return_x_big_int16); - time(user::return_x_value_big_int16); - time(user::return_x_in_place_big_int16); - time(user::return_x_big_int16); + time(user::return_x_big_int16); + time(user::return_x_value_big_int16); + time(user::return_x_in_place_big_int16); + time(user::return_x_big_int16); cout << "\n"; } void test_little_int16() { cout << "16-bit aligned little endian"; - time(user::return_x_little_int16); - time(user::return_x_value_little_int16); - time(user::return_x_in_place_little_int16); - time(user::return_x_little_int16); + time(user::return_x_little_int16); + time(user::return_x_value_little_int16); + time(user::return_x_in_place_little_int16); + time(user::return_x_little_int16); cout << "\n"; } void test_big_int32() { cout << "32-bit aligned big endian"; - time(user::return_x_big_int32); - time(user::return_x_value_big_int32); - time(user::return_x_in_place_big_int32); - time(user::return_x_big_int32); + time(user::return_x_big_int32); + time(user::return_x_value_big_int32); + time(user::return_x_in_place_big_int32); + time(user::return_x_big_int32); cout << "\n"; } void test_little_int32() { cout << "32-bit aligned little endian"; - time(user::return_x_little_int32); - time(user::return_x_value_little_int32); - time(user::return_x_in_place_little_int32); - time(user::return_x_little_int32); + time(user::return_x_little_int32); + time(user::return_x_value_little_int32); + time(user::return_x_in_place_little_int32); + time(user::return_x_little_int32); cout << "\n"; } void test_big_int64() { cout << "64-bit aligned big endian"; - time(user::return_x_big_int64); - time(user::return_x_value_big_int64); - time(user::return_x_in_place_big_int64); - time(user::return_x_big_int64); + time(user::return_x_big_int64); + time(user::return_x_value_big_int64); + time(user::return_x_in_place_big_int64); + time(user::return_x_big_int64); cout << "\n"; } void test_little_int64() { cout << "64-bit aligned little endian"; - time(user::return_x_little_int64); - time(user::return_x_value_little_int64); - time(user::return_x_in_place_little_int64); - time(user::return_x_little_int64); + time(user::return_x_little_int64); + time(user::return_x_value_little_int64); + time(user::return_x_in_place_little_int64); + time(user::return_x_little_int64); cout << "\n"; } diff --git a/test/speed_test_functions.cpp b/test/speed_test_functions.cpp index 95904ff..d3a687d 100644 --- a/test/speed_test_functions.cpp +++ b/test/speed_test_functions.cpp @@ -20,31 +20,43 @@ namespace user { - int16_t return_x_big_int16(int16_t x, big_int16_t) BOOST_NOEXCEPT {return x;} - int16_t return_x_little_int16(int16_t x, little_int16_t) BOOST_NOEXCEPT {return x;} - int16_t return_x_value_big_int16(int16_t x, big_int16_t) BOOST_NOEXCEPT {return big_endian_value(x);} - int16_t return_x_value_little_int16(int16_t x, little_int16_t) BOOST_NOEXCEPT {return little_endian_value(x);} - int16_t return_x_in_place_big_int16(int16_t x, big_int16_t) BOOST_NOEXCEPT {big_endian(x);return x;} - int16_t return_x_in_place_little_int16(int16_t x, little_int16_t) BOOST_NOEXCEPT {little_endian(x);return x;} - int16_t return_y_big_int16(int16_t x, big_int16_t y) BOOST_NOEXCEPT {return y;} - int16_t return_y_little_int16(int16_t x, little_int16_t y) BOOST_NOEXCEPT {return y;} + int16_t return_x_big_int16(int16_t x, big_int16_ut) BOOST_NOEXCEPT {return x;} + int16_t return_x_little_int16(int16_t x, little_int16_ut) BOOST_NOEXCEPT {return x;} + int16_t return_x_value_big_int16(int16_t x, big_int16_ut) BOOST_NOEXCEPT + {return reverse_unless_native_big(x);} + int16_t return_x_value_little_int16(int16_t x, little_int16_ut) BOOST_NOEXCEPT + {return reverse_unless_native_little(x);} + int16_t return_x_in_place_big_int16(int16_t x, big_int16_ut) BOOST_NOEXCEPT + {reverse_in_place_unless_native_big(x);return x;} + int16_t return_x_in_place_little_int16(int16_t x, little_int16_ut) BOOST_NOEXCEPT + {reverse_in_place_unless_native_little(x);return x;} + int16_t return_y_big_int16(int16_t x, big_int16_ut y) BOOST_NOEXCEPT {return y;} + int16_t return_y_little_int16(int16_t x, little_int16_ut y) BOOST_NOEXCEPT {return y;} - int32_t return_x_big_int32(int32_t x, big_int32_t) BOOST_NOEXCEPT {return x;} - int32_t return_x_little_int32(int32_t x, little_int32_t) BOOST_NOEXCEPT {return x;} - int32_t return_x_value_big_int32(int32_t x, big_int32_t) BOOST_NOEXCEPT {return big_endian_value(x);} - int32_t return_x_value_little_int32(int32_t x, little_int32_t) BOOST_NOEXCEPT {return little_endian_value(x);} - int32_t return_x_in_place_big_int32(int32_t x, big_int32_t) BOOST_NOEXCEPT {big_endian(x);return x;} - int32_t return_x_in_place_little_int32(int32_t x, little_int32_t) BOOST_NOEXCEPT {little_endian(x);return x;} - int32_t return_y_big_int32(int32_t x, big_int32_t y) BOOST_NOEXCEPT {return y;} - int32_t return_y_little_int32(int32_t x, little_int32_t y) BOOST_NOEXCEPT {return y;} + int32_t return_x_big_int32(int32_t x, big_int32_ut) BOOST_NOEXCEPT {return x;} + int32_t return_x_little_int32(int32_t x, little_int32_ut) BOOST_NOEXCEPT {return x;} + int32_t return_x_value_big_int32(int32_t x, big_int32_ut) BOOST_NOEXCEPT + {return reverse_unless_native_big(x);} + int32_t return_x_value_little_int32(int32_t x, little_int32_ut) BOOST_NOEXCEPT + {return reverse_unless_native_little(x);} + int32_t return_x_in_place_big_int32(int32_t x, big_int32_ut) BOOST_NOEXCEPT + {reverse_in_place_unless_native_big(x);return x;} + int32_t return_x_in_place_little_int32(int32_t x, little_int32_ut) BOOST_NOEXCEPT + {reverse_in_place_unless_native_little(x);return x;} + int32_t return_y_big_int32(int32_t x, big_int32_ut y) BOOST_NOEXCEPT {return y;} + int32_t return_y_little_int32(int32_t x, little_int32_ut y) BOOST_NOEXCEPT {return y;} - int64_t return_x_big_int64(int64_t x, big_int64_t) BOOST_NOEXCEPT {return x;} - int64_t return_x_little_int64(int64_t x, little_int64_t) BOOST_NOEXCEPT {return x;} - int64_t return_x_value_big_int64(int64_t x, big_int64_t) BOOST_NOEXCEPT {return big_endian_value(x);} - int64_t return_x_value_little_int64(int64_t x, little_int64_t) BOOST_NOEXCEPT {return little_endian_value(x);} - int64_t return_x_in_place_big_int64(int64_t x, big_int64_t) BOOST_NOEXCEPT {big_endian(x);return x;} - int64_t return_x_in_place_little_int64(int64_t x, little_int64_t) BOOST_NOEXCEPT {little_endian(x);return x;} - int64_t return_y_big_int64(int64_t x, big_int64_t y) BOOST_NOEXCEPT {return y;} - int64_t return_y_little_int64(int64_t x, little_int64_t y) BOOST_NOEXCEPT {return y;} + int64_t return_x_big_int64(int64_t x, big_int64_ut) BOOST_NOEXCEPT {return x;} + int64_t return_x_little_int64(int64_t x, little_int64_ut) BOOST_NOEXCEPT {return x;} + int64_t return_x_value_big_int64(int64_t x, big_int64_ut) BOOST_NOEXCEPT + {return reverse_unless_native_big(x);} + int64_t return_x_value_little_int64(int64_t x, little_int64_ut) BOOST_NOEXCEPT + {return reverse_unless_native_little(x);} + int64_t return_x_in_place_big_int64(int64_t x, big_int64_ut) BOOST_NOEXCEPT + {reverse_in_place_unless_native_big(x);return x;} + int64_t return_x_in_place_little_int64(int64_t x, little_int64_ut) BOOST_NOEXCEPT + {reverse_in_place_unless_native_little(x);return x;} + int64_t return_y_big_int64(int64_t x, big_int64_ut y) BOOST_NOEXCEPT {return y;} + int64_t return_y_little_int64(int64_t x, little_int64_ut y) BOOST_NOEXCEPT {return y;} } diff --git a/test/speed_test_functions.hpp b/test/speed_test_functions.hpp index 4c1aa33..80eb6b9 100644 --- a/test/speed_test_functions.hpp +++ b/test/speed_test_functions.hpp @@ -24,32 +24,32 @@ namespace user using namespace boost; using namespace boost::endian; - int16_t return_x_big_int16(int16_t x, big_int16_t y) BOOST_NOEXCEPT; - int16_t return_x_little_int16(int16_t x, little_int16_t y) BOOST_NOEXCEPT; - int16_t return_x_value_big_int16(int16_t x, big_int16_t) BOOST_NOEXCEPT; - int16_t return_x_value_little_int16(int16_t x, little_int16_t y) BOOST_NOEXCEPT; - int16_t return_x_in_place_big_int16(int16_t x, big_int16_t y) BOOST_NOEXCEPT; - int16_t return_x_in_place_little_int16(int16_t x, little_int16_t y) BOOST_NOEXCEPT; - int16_t return_y_big_int16(int16_t x, big_int16_t y) BOOST_NOEXCEPT; - int16_t return_y_little_int16(int16_t x, little_int16_t y) BOOST_NOEXCEPT; + int16_t return_x_big_int16(int16_t x, big_int16_ut y) BOOST_NOEXCEPT; + int16_t return_x_little_int16(int16_t x, little_int16_ut y) BOOST_NOEXCEPT; + int16_t return_x_value_big_int16(int16_t x, big_int16_ut) BOOST_NOEXCEPT; + int16_t return_x_value_little_int16(int16_t x, little_int16_ut y) BOOST_NOEXCEPT; + int16_t return_x_in_place_big_int16(int16_t x, big_int16_ut y) BOOST_NOEXCEPT; + int16_t return_x_in_place_little_int16(int16_t x, little_int16_ut y) BOOST_NOEXCEPT; + int16_t return_y_big_int16(int16_t x, big_int16_ut y) BOOST_NOEXCEPT; + int16_t return_y_little_int16(int16_t x, little_int16_ut y) BOOST_NOEXCEPT; - int32_t return_x_big_int32(int32_t x, big_int32_t y) BOOST_NOEXCEPT; - int32_t return_x_little_int32(int32_t x, little_int32_t y) BOOST_NOEXCEPT; - int32_t return_x_value_big_int32(int32_t x, big_int32_t) BOOST_NOEXCEPT; - int32_t return_x_value_little_int32(int32_t x, little_int32_t y) BOOST_NOEXCEPT; - int32_t return_x_in_place_big_int32(int32_t x, big_int32_t y) BOOST_NOEXCEPT; - int32_t return_x_in_place_little_int32(int32_t x, little_int32_t y) BOOST_NOEXCEPT; - int32_t return_y_big_int32(int32_t x, big_int32_t y) BOOST_NOEXCEPT; - int32_t return_y_little_int32(int32_t x, little_int32_t y) BOOST_NOEXCEPT; + int32_t return_x_big_int32(int32_t x, big_int32_ut y) BOOST_NOEXCEPT; + int32_t return_x_little_int32(int32_t x, little_int32_ut y) BOOST_NOEXCEPT; + int32_t return_x_value_big_int32(int32_t x, big_int32_ut) BOOST_NOEXCEPT; + int32_t return_x_value_little_int32(int32_t x, little_int32_ut y) BOOST_NOEXCEPT; + int32_t return_x_in_place_big_int32(int32_t x, big_int32_ut y) BOOST_NOEXCEPT; + int32_t return_x_in_place_little_int32(int32_t x, little_int32_ut y) BOOST_NOEXCEPT; + int32_t return_y_big_int32(int32_t x, big_int32_ut y) BOOST_NOEXCEPT; + int32_t return_y_little_int32(int32_t x, little_int32_ut y) BOOST_NOEXCEPT; - int64_t return_x_big_int64(int64_t x, big_int64_t y) BOOST_NOEXCEPT; - int64_t return_x_little_int64(int64_t x, little_int64_t y) BOOST_NOEXCEPT; - int64_t return_x_value_big_int64(int64_t x, big_int64_t) BOOST_NOEXCEPT; - int64_t return_x_value_little_int64(int64_t x, little_int64_t y) BOOST_NOEXCEPT; - int64_t return_x_in_place_big_int64(int64_t x, big_int64_t y) BOOST_NOEXCEPT; - int64_t return_x_in_place_little_int64(int64_t x, little_int64_t y) BOOST_NOEXCEPT; - int64_t return_y_big_int64(int64_t x, big_int64_t y) BOOST_NOEXCEPT; - int64_t return_y_little_int64(int64_t x, little_int64_t y) BOOST_NOEXCEPT; + int64_t return_x_big_int64(int64_t x, big_int64_ut y) BOOST_NOEXCEPT; + int64_t return_x_little_int64(int64_t x, little_int64_ut y) BOOST_NOEXCEPT; + int64_t return_x_value_big_int64(int64_t x, big_int64_ut) BOOST_NOEXCEPT; + int64_t return_x_value_little_int64(int64_t x, little_int64_ut y) BOOST_NOEXCEPT; + int64_t return_x_in_place_big_int64(int64_t x, big_int64_ut y) BOOST_NOEXCEPT; + int64_t return_x_in_place_little_int64(int64_t x, little_int64_ut y) BOOST_NOEXCEPT; + int64_t return_y_big_int64(int64_t x, big_int64_ut y) BOOST_NOEXCEPT; + int64_t return_y_little_int64(int64_t x, little_int64_ut y) BOOST_NOEXCEPT; }