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

source code of boost/libs/endian/test/intrinsic_test.cpp