34 #ifndef _RTE_BYTEORDER_H_
35 #define _RTE_BYTEORDER_H_
47 #ifdef RTE_EXEC_ENV_BSDAPP
48 #include <sys/endian.h>
56 #define RTE_BIG_ENDIAN 1
57 #define RTE_LITTLE_ENDIAN 2
58 #if defined __BYTE_ORDER__
59 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
60 #define RTE_BYTE_ORDER RTE_BIG_ENDIAN
61 #elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
62 #define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN
64 #elif defined __BYTE_ORDER
65 #if __BYTE_ORDER == __BIG_ENDIAN
66 #define RTE_BYTE_ORDER RTE_BIG_ENDIAN
67 #elif __BYTE_ORDER == __LITTLE_ENDIAN
68 #define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN
70 #elif defined __BIG_ENDIAN__
71 #define RTE_BYTE_ORDER RTE_BIG_ENDIAN
72 #elif defined __LITTLE_ENDIAN__
73 #define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN
82 static inline uint16_t
83 rte_constant_bswap16(uint16_t x)
85 return (uint16_t)(((x & 0x00ffU) << 8) |
86 ((x & 0xff00U) >> 8));
95 static inline uint32_t
96 rte_constant_bswap32(uint32_t x)
98 return ((x & 0x000000ffUL) << 24) |
99 ((x & 0x0000ff00UL) << 8) |
100 ((x & 0x00ff0000UL) >> 8) |
101 ((x & 0xff000000UL) >> 24);
110 static inline uint64_t
111 rte_constant_bswap64(uint64_t x)
113 return ((x & 0x00000000000000ffULL) << 56) |
114 ((x & 0x000000000000ff00ULL) << 40) |
115 ((x & 0x0000000000ff0000ULL) << 24) |
116 ((x & 0x00000000ff000000ULL) << 8) |
117 ((x & 0x000000ff00000000ULL) >> 8) |
118 ((x & 0x0000ff0000000000ULL) >> 24) |
119 ((x & 0x00ff000000000000ULL) >> 40) |
120 ((x & 0xff00000000000000ULL) >> 56);
206 #ifdef RTE_FORCE_INTRINSICS
207 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
208 #define rte_bswap16(x) __builtin_bswap16(x)
211 #define rte_bswap32(x) __builtin_bswap32(x)
213 #define rte_bswap64(x) __builtin_bswap64(x)