line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#pragma once |
2
|
|
|
|
|
|
|
#include |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#ifdef _MSC_VER |
5
|
|
|
|
|
|
|
# include |
6
|
|
|
|
|
|
|
#endif |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
namespace panda { |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
namespace detail { |
11
|
|
|
|
|
|
|
union check_endianess { unsigned x; unsigned char c; }; |
12
|
18
|
|
|
|
|
|
static const bool am_i_little = (check_endianess{1}).c; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#ifdef _MSC_VER |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
inline uint16_t swap_bytes16 (uint16_t x) { return _byteswap_ushort(x); } |
17
|
|
|
|
|
|
|
inline uint32_t swap_bytes32 (uint32_t x) { return _byteswap_ulong(x); } |
18
|
|
|
|
|
|
|
inline uint64_t swap_bytes64 (uint64_t x) { return _byteswap_uint64(x); } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && 0 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
inline uint16_t swap_bytes16 (uint16_t x) { return __builtin_swap_bytes16(x); } |
23
|
|
|
|
|
|
|
inline uint32_t swap_bytes32 (uint32_t x) { return __builtin_swap_bytes32(x); } |
24
|
|
|
|
|
|
|
inline uint64_t swap_bytes64 (uint64_t x) { return __builtin_swap_bytes64(x); } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#else |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
|
inline uint16_t swap_bytes16 (uint16_t x) { |
29
|
2
|
|
|
|
|
|
return ((x >> 8) & 0xff) | (x << 8); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
6
|
|
|
|
|
|
inline uint32_t swap_bytes32 (uint32_t x) { |
33
|
6
|
|
|
|
|
|
return ((x & 0xff000000) >> 24) | ((x & 0x00ff0000) >> 8) | ((x & 0x0000ff00) << 8) | (x << 24); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
|
inline uint64_t swap_bytes64 (uint64_t x) { |
37
|
|
|
|
|
|
|
union { uint64_t u64; uint32_t u32[2]; } v1, v2; |
38
|
2
|
|
|
|
|
|
v1.u64 = x; |
39
|
2
|
|
|
|
|
|
v2.u32[0] = swap_bytes32(v1.u32[1]); |
40
|
2
|
|
|
|
|
|
v2.u32[1] = swap_bytes32(v1.u32[0]); |
41
|
2
|
|
|
|
|
|
return v2.u64; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#endif |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
2
|
50
|
|
|
|
|
inline uint16_t h2be16 (uint16_t x) { return detail::am_i_little ? detail::swap_bytes16(x) : x; } |
49
|
|
|
|
|
|
|
inline uint16_t h2le16 (uint16_t x) { return detail::am_i_little ? x : detail::swap_bytes16(x); } |
50
|
2
|
50
|
|
|
|
|
inline uint16_t be2h16 (uint16_t x) { return detail::am_i_little ? detail::swap_bytes16(x) : x; } |
51
|
|
|
|
|
|
|
inline uint16_t le2h16 (uint16_t x) { return detail::am_i_little ? x : detail::swap_bytes16(x); } |
52
|
|
|
|
|
|
|
|
53
|
2
|
50
|
|
|
|
|
inline uint32_t h2be32 (uint32_t x) { return detail::am_i_little ? detail::swap_bytes32(x) : x; } |
54
|
|
|
|
|
|
|
inline uint32_t h2le32 (uint32_t x) { return detail::am_i_little ? x : detail::swap_bytes32(x); } |
55
|
2
|
50
|
|
|
|
|
inline uint32_t be2h32 (uint32_t x) { return detail::am_i_little ? detail::swap_bytes32(x) : x; } |
56
|
|
|
|
|
|
|
inline uint32_t le2h32 (uint32_t x) { return detail::am_i_little ? x : detail::swap_bytes32(x); } |
57
|
|
|
|
|
|
|
|
58
|
2
|
50
|
|
|
|
|
inline uint64_t h2be64 (uint64_t x) { return detail::am_i_little ? detail::swap_bytes64(x) : x; } |
59
|
|
|
|
|
|
|
inline uint64_t h2le64 (uint64_t x) { return detail::am_i_little ? x : detail::swap_bytes64(x); } |
60
|
2
|
50
|
|
|
|
|
inline uint64_t be2h64 (uint64_t x) { return detail::am_i_little ? detail::swap_bytes64(x) : x; } |
61
|
|
|
|
|
|
|
inline uint64_t le2h64 (uint64_t x) { return detail::am_i_little ? x : detail::swap_bytes64(x); } |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
// just to make templates simpler |
64
|
|
|
|
|
|
|
inline uint8_t h2be (uint8_t x) { return x; } |
65
|
|
|
|
|
|
|
inline uint8_t h2le (uint8_t x) { return x; } |
66
|
|
|
|
|
|
|
inline uint8_t be2h (uint8_t x) { return x; } |
67
|
|
|
|
|
|
|
inline uint8_t le2h (uint8_t x) { return x; } |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
inline uint16_t h2be (uint16_t x) { return h2be16(x); } |
70
|
|
|
|
|
|
|
inline uint16_t h2le (uint16_t x) { return h2le16(x); } |
71
|
|
|
|
|
|
|
inline uint16_t be2h (uint16_t x) { return be2h16(x); } |
72
|
|
|
|
|
|
|
inline uint16_t le2h (uint16_t x) { return le2h16(x); } |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
inline uint32_t h2be (uint32_t x) { return h2be32(x); } |
75
|
|
|
|
|
|
|
inline uint32_t h2le (uint32_t x) { return h2le32(x); } |
76
|
|
|
|
|
|
|
inline uint32_t be2h (uint32_t x) { return be2h32(x); } |
77
|
|
|
|
|
|
|
inline uint32_t le2h (uint32_t x) { return le2h32(x); } |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
inline uint64_t h2be (uint64_t x) { return h2be64(x); } |
80
|
|
|
|
|
|
|
inline uint64_t h2le (uint64_t x) { return h2le64(x); } |
81
|
|
|
|
|
|
|
inline uint64_t be2h (uint64_t x) { return be2h64(x); } |
82
|
|
|
|
|
|
|
inline uint64_t le2h (uint64_t x) { return le2h64(x); } |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |