1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #ifndef _RTE_BYTEORDER_X86_H_
6 #define _RTE_BYTEORDER_X86_H_
13 #include <rte_common.h>
14 #include <rte_config.h>
15 #include "generic/rte_byteorder.h"
17 #ifndef RTE_BYTE_ORDER
18 #define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN
22 * An architecture-optimized byte swap for a 16-bit value.
24 * Do not use this function directly. The preferred function is rte_bswap16().
26 static inline uint16_t rte_arch_bswap16(uint16_t _x)
29 asm volatile ("xchgb %b[x1],%h[x2]"
37 * An architecture-optimized byte swap for a 32-bit value.
39 * Do not use this function directly. The preferred function is rte_bswap32().
41 static inline uint32_t rte_arch_bswap32(uint32_t _x)
44 asm volatile ("bswap %[x]"
50 #ifndef RTE_FORCE_INTRINSICS
51 #define rte_bswap16(x) ((uint16_t)(__builtin_constant_p(x) ? \
52 rte_constant_bswap16(x) : \
55 #define rte_bswap32(x) ((uint32_t)(__builtin_constant_p(x) ? \
56 rte_constant_bswap32(x) : \
59 #define rte_bswap64(x) ((uint64_t)(__builtin_constant_p(x) ? \
60 rte_constant_bswap64(x) : \
64 * __builtin_bswap16 is only available gcc 4.8 and upwards
66 #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
67 #define rte_bswap16(x) ((uint16_t)(__builtin_constant_p(x) ? \
68 rte_constant_bswap16(x) : \
73 #define rte_cpu_to_le_16(x) (x)
74 #define rte_cpu_to_le_32(x) (x)
75 #define rte_cpu_to_le_64(x) (x)
77 #define rte_cpu_to_be_16(x) rte_bswap16(x)
78 #define rte_cpu_to_be_32(x) rte_bswap32(x)
79 #define rte_cpu_to_be_64(x) rte_bswap64(x)
81 #define rte_le_to_cpu_16(x) (x)
82 #define rte_le_to_cpu_32(x) (x)
83 #define rte_le_to_cpu_64(x) (x)
85 #define rte_be_to_cpu_16(x) rte_bswap16(x)
86 #define rte_be_to_cpu_32(x) rte_bswap32(x)
87 #define rte_be_to_cpu_64(x) rte_bswap64(x)
90 #include "rte_byteorder_32.h"
92 #include "rte_byteorder_64.h"
99 #endif /* _RTE_BYTEORDER_X86_H_ */