Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
windows/endian.h
Go to the documentation of this file.
1
34#ifndef _endian_h_
35#define _endian_h_
36
37#include <stdint.h>
38#include <sys/param.h>
39
44static inline uint16_t __bswap_16(uint16_t x)
45{
46 return (((x & 0xff00) >> 8) | ((x & 0x00ff) << 8));
47}
48
53static inline uint32_t __bswap_32(uint32_t x)
54{
55 return (((x & 0xff000000) >> 24) | ((x & 0x00ff0000) >> 8) |
56 ((x & 0x0000ff00) << 8) | ((x & 0x000000ff) << 24));
57}
58
63static inline uint64_t __bswap_64(uint64_t x)
64{
65 return (((x & 0xff00000000000000ULL) >> 56) |
66 ((x & 0x00ff000000000000ULL) >> 40) |
67 ((x & 0x0000ff0000000000ULL) >> 24) |
68 ((x & 0x000000ff00000000ULL) >> 8) |
69 ((x & 0x00000000ff000000ULL) << 8) |
70 ((x & 0x0000000000ff0000ULL) << 24) |
71 ((x & 0x000000000000ff00ULL) << 40) |
72 ((x & 0x00000000000000ffULL) << 56));
73}
74
77#if CONFIG_ENDIAN_BIG
78 #define htobe16(x) (x)
79 #define htole16(x) __bswap_16 (x)
80 #define be16toh(x) (x)
81 #define le16toh(x) __bswap_16 (x)
82
83 #define htobe32(x) (x)
84 #define htole32(x) __bswap_32 (x)
85 #define be32toh(x) (x)
86 #define le32toh(x) __bswap_32 (x)
87
88 #define htobe64(x) (x)
89 #define htole64(x) __bswap_64 (x)
90 #define be64toh(x) (x)
91 #define le64toh(x) __bswap_64 (x)
92#else
94 #define htobe16(x) __bswap_16 (x)
96 #define htole16(x) (x)
98 #define be16toh(x) __bswap_16 (x)
100 #define le16toh(x) (x)
101
103 #define htobe32(x) __bswap_32 (x)
105 #define htole32(x) (x)
107 #define be32toh(x) __bswap_32 (x)
109 #define le32toh(x) (x)
110
112 #define htobe64(x) __bswap_64 (x)
114 #define htole64(x) (x)
116 #define be64toh(x) __bswap_64 (x)
118 #define le64toh(x) (x)
119#endif
120
121#endif /* _endian_h_ */
static uint64_t __bswap_64(uint64_t x)
Byte swap a 64 bit value.
static uint16_t __bswap_16(uint16_t x)
Byte swap a 16 bit value.
static uint32_t __bswap_32(uint32_t x)
Byte swap a 32 bit value.