eal: install all arch headers
[dpdk.git] / lib / librte_eal / common / include / arch / i686 / rte_byteorder.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _RTE_BYTEORDER_I686_H_
35 #define _RTE_BYTEORDER_I686_H_
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 #include "generic/rte_byteorder.h"
42
43 /*
44  * An architecture-optimized byte swap for a 16-bit value.
45  *
46  * Do not use this function directly. The preferred function is rte_bswap16().
47  */
48 static inline uint16_t rte_arch_bswap16(uint16_t _x)
49 {
50         register uint16_t x = _x;
51         asm volatile ("xchgb %b[x1],%h[x2]"
52                       : [x1] "=Q" (x)
53                       : [x2] "0" (x)
54                       );
55         return x;
56 }
57
58 /*
59  * An architecture-optimized byte swap for a 32-bit value.
60  *
61  * Do not use this function directly. The preferred function is rte_bswap32().
62  */
63 static inline uint32_t rte_arch_bswap32(uint32_t _x)
64 {
65         register uint32_t x = _x;
66         asm volatile ("bswap %[x]"
67                       : [x] "+r" (x)
68                       );
69         return x;
70 }
71
72 /*
73  * An architecture-optimized byte swap for a 64-bit value.
74  *
75   * Do not use this function directly. The preferred function is rte_bswap64().
76  */
77 /* Compat./Leg. mode */
78 static inline uint64_t rte_arch_bswap64(uint64_t x)
79 {
80         uint64_t ret = 0;
81         ret |= ((uint64_t)rte_arch_bswap32(x & 0xffffffffUL) << 32);
82         ret |= ((uint64_t)rte_arch_bswap32((x >> 32) & 0xffffffffUL));
83         return ret;
84 }
85
86 #ifndef RTE_FORCE_INTRINSICS
87 #define rte_bswap16(x) ((uint16_t)(__builtin_constant_p(x) ?            \
88                                    rte_constant_bswap16(x) :            \
89                                    rte_arch_bswap16(x)))
90
91 #define rte_bswap32(x) ((uint32_t)(__builtin_constant_p(x) ?            \
92                                    rte_constant_bswap32(x) :            \
93                                    rte_arch_bswap32(x)))
94
95 #define rte_bswap64(x) ((uint64_t)(__builtin_constant_p(x) ?            \
96                                    rte_constant_bswap64(x) :            \
97                                    rte_arch_bswap64(x)))
98 #else
99 /*
100  * __builtin_bswap16 is only available gcc 4.8 and upwards
101  */
102 #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
103 #define rte_bswap16(x) ((uint16_t)(__builtin_constant_p(x) ?            \
104                                    rte_constant_bswap16(x) :            \
105                                    rte_arch_bswap16(x)))
106 #endif
107 #endif
108
109 #define rte_cpu_to_le_16(x) (x)
110 #define rte_cpu_to_le_32(x) (x)
111 #define rte_cpu_to_le_64(x) (x)
112
113 #define rte_cpu_to_be_16(x) rte_bswap16(x)
114 #define rte_cpu_to_be_32(x) rte_bswap32(x)
115 #define rte_cpu_to_be_64(x) rte_bswap64(x)
116
117 #define rte_le_to_cpu_16(x) (x)
118 #define rte_le_to_cpu_32(x) (x)
119 #define rte_le_to_cpu_64(x) (x)
120
121 #define rte_be_to_cpu_16(x) rte_bswap16(x)
122 #define rte_be_to_cpu_32(x) rte_bswap32(x)
123 #define rte_be_to_cpu_64(x) rte_bswap64(x)
124
125 #ifdef __cplusplus
126 }
127 #endif
128
129 #endif /* _RTE_BYTEORDER_I686_H_ */