Debian Codegraph @

usr/lib/common/aix/endian.h

raw symbols SCIP
1 /*
2 * COPYRIGHT (c) International Business Machines Corp. 2024
3 *
4 * This program is provided under the terms of the Common Public License,
5 * version 1.0 (CPL-1.0). Any use, reproduction or distribution for this
6 * software constitutes recipient's acceptance of CPL-1.0 terms which can be
7 * found in the file LICENSE file or at
8 * https://opensource.org/licenses/cpl1.0.php
9 */
10 #ifndef GENERIC_AIX_BYTESWAP_H
11 #define GENERIC_AIX_BYTESWAP_H
12
13 #include <inttypes.h>
14 #include <sys/machine.h>
15
16 #ifndef bswap_16
17 # define bswap_16(x) \
18 ((uint16_t)((((uint16_t) (x) & 0xff00) >> 8) | \
19 (((uint16_t) (x) & 0x00ff) << 8)))
20 #endif /* !bswap_16 */
21
22 #ifndef bswap_32
23 # define bswap_32(x) \
24 ((uint32_t)((((uint32_t) (x) & 0xff000000) >> 24) | \
25 (((uint32_t) (x) & 0x00ff0000) >> 8) | \
26 (((uint32_t) (x) & 0x0000ff00) << 8) | \
27 (((uint32_t) (x) & 0x000000ff) << 24)))
28 #endif /* !bswap_32 */
29
30 #ifndef bswap_64
31 # define bswap_64(x) \
32 ((uint64_t)((((uint64_t) (x) & 0xff00000000000000ULL) >> 56) | \
33 (((uint64_t) (x) & 0x00ff000000000000ULL) >> 40) | \
34 (((uint64_t) (x) & 0x0000ff0000000000ULL) >> 24) | \
35 (((uint64_t) (x) & 0x000000ff00000000ULL) >> 8) | \
36 (((uint64_t) (x) & 0x00000000ff000000ULL) << 8) | \
37 (((uint64_t) (x) & 0x0000000000ff0000ULL) << 24) | \
38 (((uint64_t) (x) & 0x000000000000ff00ULL) << 40) | \
39 (((uint64_t) (x) & 0x00000000000000ffULL) << 56)))
40 #endif /* !bswap_64 */
41
42 #endif /* GENERIC_AIX_BYTESWAP_H */
43
44 #ifndef GENERIC_AIX_ENDIAN_H
45 #define GENERIC_AIX_ENDIAN_H
46
47 #ifndef htobe16
48 # if __BIG_ENDIAN__
49
50 # define htobe16(x) (x)
51 # define htole16(x) bswap_16(x)
52 # define be16toh(x) (x)
53 # define le16toh(x) bswap_16(x)
54
55 # else /* __BIG_ENDIAN__ */
56
57 # define htobe16(x) bswap_16(x)
58 # define htole16(x) (x)
59 # define be16toh(x) bswap_16(x)
60 # define le16toh(x) (x)
61
62 # endif /* __BIG_ENDIAN__ */
63 #endif /* !htobe16 */
64
65 #ifndef htobe32
66 # if __BIG_ENDIAN__
67
68 # define htobe32(x) (x)
69 # define htole32(x) bswap_32(x)
70 # define be32toh(x) (x)
71 # define le32toh(x) bswap_32(x)
72
73 # else /* __BIG_ENDIAN__ */
74
75 # define htobe32(x) bswap_32(x)
76 # define htole32(x) (x)
77 # define be32toh(x) bswap_32(x)
78 # define le32toh(x) (x)
79
80 # endif /* __BIG_ENDIAN__ */
81 #endif /* !htobe32 */
82
83 #ifndef htobe64
84 # if __BIG_ENDIAN__
85
86 # define htobe64(x) (x)
87 # define htole64(x) bswap_64(x)
88 # define be64toh(x) (x)
89 # define le64toh(x) bswap_64(x)
90
91 #else /* __BIG_ENDIAN__ */
92
93 # define htobe64(x) bswap_64(x)
94 # define htole64(x) (x)
95 # define be64toh(x) bswap_64(x)
96 # define le64toh(x) (x)
97
98 # endif /* __BIG_ENDIAN__ */
99 #endif /* !htobe64 */
100 #endif /* GENERIC_AIX_ENDIAN_H */