| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 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 |
| 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 |
| 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 |
| 41 |
|
| 42 |
#endif |
| 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 |
| 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 |
| 63 |
#endif |
| 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 |
| 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 |
| 81 |
#endif |
| 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 |
| 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 |
| 99 |
#endif |
| 100 |
#endif |