1 #ifndef VTESTBED_BASE_BYTE_ORDER_HH 2 #define VTESTBED_BASE_BYTE_ORDER_HH 7 #include <vtestbed/config/endian.hh> 22 template <>
inline void swap<2>(integer<2>::type& n) {
23 #if defined(VTB_HAVE_BUILTIN_BSWAP16) 24 n = __builtin_bswap16(n);
26 n = ((n & 0xff00)>>8) | ((n & 0x00ff)<<8);
30 template <>
inline void swap<4>(integer<4>::type& n) {
31 #if defined(VTB_HAVE_BUILTIN_BSWAP32) 32 n = __builtin_bswap32(n);
34 n = ((n & UINT32_C(0xff000000)) >> 24) |
35 ((n & UINT32_C(0x00ff0000)) >> 8) |
36 ((n & UINT32_C(0x0000ff00)) << 8) |
37 ((n & UINT32_C(0x000000ff)) << 24);
41 template <>
inline void swap<8>(integer<8>::type& n) {
42 #if defined(VTB_HAVE_BUILTIN_BSWAP64) 43 n = __builtin_bswap64(n);
45 n = ((n & UINT64_C(0xff00000000000000)) >> 56) |
46 ((n & UINT64_C(0x00ff000000000000)) >> 40) |
47 ((n & UINT64_C(0x0000ff0000000000)) >> 24) |
48 ((n & UINT64_C(0x000000ff00000000)) >> 8) |
49 ((n & UINT64_C(0x00000000ff000000)) << 8) |
50 ((n & UINT64_C(0x0000000000ff0000)) << 24) |
51 ((n & UINT64_C(0x000000000000ff00)) << 40) |
52 ((n & UINT64_C(0x00000000000000ff)) << 56);
61 typename integer<
sizeof(T)>::type integral;
62 char bytes[
sizeof(T)];
64 #if defined(VTB_LITTLE_ENDIAN) 65 ::vtb::base::swap<sizeof(T)>(this->integral);
74 #endif // vim:filetype=cpp