Debian Codegraph @

include/endianness.h

raw
1 #ifndef ENDIANNESS_H
2 #define ENDIANNESS_H
3
4 #ifndef __LITTLE_ENDIAN
5 #define __LITTLE_ENDIAN 1234
6 #endif
7
8 #ifndef __BIG_ENDIAN
9 #define __BIG_ENDIAN 4321
10 #endif
11
12 #ifndef __BYTE_ORDER
13 #ifdef __LITTLE_ENDIAN__
14 #define __BYTE_ORDER __LITTLE_ENDIAN
15 #else
16 #ifdef __BIG_ENDIAN__
17 #define __BYTE_ORDER __BIG_ENDIAN
18 #endif
19 #endif
20 #endif
21
22 #ifndef be16toh
23 #if __BYTE_ORDER == __BIG_ENDIAN
24 #define be16toh(x) (x)
25 #else
26 #define be16toh(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
27 #endif
28 #endif
29
30 #ifndef htobe16
31 #define htobe16 be16toh
32 #endif
33
34 #ifndef le16toh
35 #if __BYTE_ORDER == __BIG_ENDIAN
36 #define le16toh(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
37 #else
38 #define le16toh(x) (x)
39 #endif
40 #endif
41
42 #ifndef htole16
43 #define htole16 le16toh
44 #endif
45
46 #ifndef __bswap_32
47 #define __bswap_32(x) ((((x) & 0xFF000000) >> 24) \
48 | (((x) & 0x00FF0000) >> 8) \
49 | (((x) & 0x0000FF00) << 8) \
50 | (((x) & 0x000000FF) << 24))
51 #endif
52
53 #ifndef be32toh
54 #if __BYTE_ORDER == __BIG_ENDIAN
55 #define be32toh(x) (x)
56 #else
57 #define be32toh(x) __bswap_32(x)
58 #endif
59 #endif
60
61 #ifndef htobe32
62 #define htobe32 be32toh
63 #endif
64
65 #ifndef le32toh
66 #if __BYTE_ORDER == __BIG_ENDIAN
67 #define le32toh(x) __bswap_32(x)
68 #else
69 #define le32toh(x) (x)
70 #endif
71 #endif
72
73 #ifndef htole32
74 #define htole32 le32toh
75 #endif
76
77 #ifndef __bswap_64
78 #define __bswap_64(x) ((((x) & 0xFF00000000000000ull) >> 56) \
79 | (((x) & 0x00FF000000000000ull) >> 40) \
80 | (((x) & 0x0000FF0000000000ull) >> 24) \
81 | (((x) & 0x000000FF00000000ull) >> 8) \
82 | (((x) & 0x00000000FF000000ull) << 8) \
83 | (((x) & 0x0000000000FF0000ull) << 24) \
84 | (((x) & 0x000000000000FF00ull) << 40) \
85 | (((x) & 0x00000000000000FFull) << 56))
86 #endif
87
88 #ifndef htobe64
89 #if __BYTE_ORDER == __BIG_ENDIAN
90 #define htobe64(x) (x)
91 #else
92 #define htobe64(x) __bswap_64(x)
93 #endif
94 #endif
95
96 #ifndef be64toh
97 #define be64toh htobe64
98 #endif
99
100 #ifndef le64toh
101 #if __BYTE_ORDER == __LITTLE_ENDIAN
102 #define le64toh(x) (x)
103 #else
104 #define le64toh(x) __bswap_64(x)
105 #endif
106 #endif
107
108 #ifndef htole64
109 #define htole64 le64toh
110 #endif
111
112 #if (defined(__BIG_ENDIAN__) \
113 && !defined(__FLOAT_WORD_ORDER__)) \
114 || (defined(__FLOAT_WORD_ORDER__) \
115 && __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
116 #define float_bswap64(x) __bswap_64(x)
117 #define float_bswap32(x) __bswap_32(x)
118 #else
119 #define float_bswap64(x) (x)
120 #define float_bswap32(x) (x)
121 #endif
122
123 #endif /* ENDIANNESS_H */