intrinsic_test.cpp 921 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright Beman Dawes 2013
  2. // Copyright 2018 Peter Dimov
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // http://www.boost.org/LICENSE_1_0.txt
  5. #include <boost/endian/detail/intrinsic.hpp>
  6. #include <boost/core/lightweight_test.hpp>
  7. typedef unsigned short uint16;
  8. typedef unsigned int uint32;
  9. typedef unsigned long long uint64;
  10. int main()
  11. {
  12. std::cout << "BOOST_ENDIAN_INTRINSIC_MSG: " BOOST_ENDIAN_INTRINSIC_MSG << std::endl;
  13. #ifndef BOOST_ENDIAN_NO_INTRINSICS
  14. uint16 x2 = 0x1122U;
  15. uint16 y2 = BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_2(x2);
  16. BOOST_TEST_EQ( y2, 0x2211U );
  17. uint32 x4 = 0x11223344UL;
  18. uint32 y4 = BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_4(x4);
  19. BOOST_TEST_EQ( y4, 0x44332211UL );
  20. uint64 x8 = 0x1122334455667788U;
  21. uint64 y8 = BOOST_ENDIAN_INTRINSIC_BYTE_SWAP_8(x8);
  22. BOOST_TEST_EQ( y8, 0x8877665544332211ULL );
  23. #endif
  24. return boost::report_errors();
  25. }