Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2010-2014 Intel Corporation 3 : : */ 4 : : 5 : : #ifndef _RTE_BYTEORDER_X86_H_ 6 : : #define _RTE_BYTEORDER_X86_H_ 7 : : 8 : : #ifdef __cplusplus 9 : : extern "C" { 10 : : #endif 11 : : 12 : : #include <stdint.h> 13 : : #include <rte_common.h> 14 : : #include <rte_config.h> 15 : : #include "generic/rte_byteorder.h" 16 : : 17 : : #ifndef RTE_BYTE_ORDER 18 : : #define RTE_BYTE_ORDER RTE_LITTLE_ENDIAN 19 : : #endif 20 : : 21 : : #ifndef RTE_FORCE_INTRINSICS 22 : : /* 23 : : * An architecture-optimized byte swap for a 16-bit value. 24 : : * 25 : : * Do not use this function directly. The preferred function is rte_bswap16(). 26 : : */ 27 : 0 : static inline uint16_t rte_arch_bswap16(uint16_t _x) 28 : : { 29 : : uint16_t x = _x; 30 : 2123461 : asm volatile ("xchgb %b[x1],%h[x2]" 31 : : : [x1] "=Q" (x) 32 : : : [x2] "0" (x) 33 : : ); 34 : 0 : return x; 35 : : } 36 : : 37 : : /* 38 : : * An architecture-optimized byte swap for a 32-bit value. 39 : : * 40 : : * Do not use this function directly. The preferred function is rte_bswap32(). 41 : : */ 42 : 0 : static inline uint32_t rte_arch_bswap32(uint32_t _x) 43 : : { 44 : : uint32_t x = _x; 45 : 3122059 : asm volatile ("bswap %[x]" 46 : : : [x] "+r" (x) 47 : : ); 48 : 0 : return x; 49 : : } 50 : : 51 : : #define rte_bswap16(x) ((uint16_t)(__builtin_constant_p(x) ? \ 52 : : rte_constant_bswap16(x) : \ 53 : : rte_arch_bswap16(x))) 54 : : 55 : : #define rte_bswap32(x) ((uint32_t)(__builtin_constant_p(x) ? \ 56 : : rte_constant_bswap32(x) : \ 57 : : rte_arch_bswap32(x))) 58 : : 59 : : #define rte_bswap64(x) ((uint64_t)(__builtin_constant_p(x) ? \ 60 : : rte_constant_bswap64(x) : \ 61 : : rte_arch_bswap64(x))) 62 : : 63 : : #ifdef RTE_ARCH_I686 64 : : #include "rte_byteorder_32.h" 65 : : #else 66 : : #include "rte_byteorder_64.h" 67 : : #endif 68 : : #endif 69 : : 70 : : #define rte_cpu_to_le_16(x) (x) 71 : : #define rte_cpu_to_le_32(x) (x) 72 : : #define rte_cpu_to_le_64(x) (x) 73 : : 74 : : #define rte_cpu_to_be_16(x) rte_bswap16(x) 75 : : #define rte_cpu_to_be_32(x) rte_bswap32(x) 76 : : #define rte_cpu_to_be_64(x) rte_bswap64(x) 77 : : 78 : : #define rte_le_to_cpu_16(x) (x) 79 : : #define rte_le_to_cpu_32(x) (x) 80 : : #define rte_le_to_cpu_64(x) (x) 81 : : 82 : : #define rte_be_to_cpu_16(x) rte_bswap16(x) 83 : : #define rte_be_to_cpu_32(x) rte_bswap32(x) 84 : : #define rte_be_to_cpu_64(x) rte_bswap64(x) 85 : : 86 : : #ifdef __cplusplus 87 : : } 88 : : #endif 89 : : 90 : : #endif /* _RTE_BYTEORDER_X86_H_ */