4 * Copyright (C) IBM Corporation 2014.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of IBM Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* Inspired from FreeBSD src/sys/powerpc/include/endian.h
34 * Copyright (c) 1987, 1991, 1993
35 * The Regents of the University of California. All rights reserved.
38 #ifndef _RTE_BYTEORDER_PPC_64_H_
39 #define _RTE_BYTEORDER_PPC_64_H_
45 #include "generic/rte_byteorder.h"
48 * An architecture-optimized byte swap for a 16-bit value.
50 * Do not use this function directly. The preferred function is rte_bswap16().
52 static inline uint16_t rte_arch_bswap16(uint16_t _x)
54 return ((_x >> 8) | ((_x << 8) & 0xff00));
58 * An architecture-optimized byte swap for a 32-bit value.
60 * Do not use this function directly. The preferred function is rte_bswap32().
62 static inline uint32_t rte_arch_bswap32(uint32_t _x)
64 return ((_x >> 24) | ((_x >> 8) & 0xff00) | ((_x << 8) & 0xff0000) |
65 ((_x << 24) & 0xff000000));
69 * An architecture-optimized byte swap for a 64-bit value.
71 * Do not use this function directly. The preferred function is rte_bswap64().
74 static inline uint64_t rte_arch_bswap64(uint64_t _x)
76 return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) |
77 ((_x >> 8) & 0xff000000) | ((_x << 8) & (0xffULL << 32)) |
78 ((_x << 24) & (0xffULL << 40)) |
79 ((_x << 40) & (0xffULL << 48)) | ((_x << 56)));
82 #ifndef RTE_FORCE_INTRINSICS
83 #define rte_bswap16(x) ((uint16_t)(__builtin_constant_p(x) ? \
84 rte_constant_bswap16(x) : \
87 #define rte_bswap32(x) ((uint32_t)(__builtin_constant_p(x) ? \
88 rte_constant_bswap32(x) : \
91 #define rte_bswap64(x) ((uint64_t)(__builtin_constant_p(x) ? \
92 rte_constant_bswap64(x) : \
96 * __builtin_bswap16 is only available gcc 4.8 and upwards
98 #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)
99 #define rte_bswap16(x) ((uint16_t)(__builtin_constant_p(x) ? \
100 rte_constant_bswap16(x) : \
101 rte_arch_bswap16(x)))
105 /* Power 8 have both little endian and big endian mode
106 * Power 7 only support big endian
108 #ifndef RTE_ARCH_BIG_ENDIAN
110 #define rte_cpu_to_le_16(x) (x)
111 #define rte_cpu_to_le_32(x) (x)
112 #define rte_cpu_to_le_64(x) (x)
114 #define rte_cpu_to_be_16(x) rte_bswap16(x)
115 #define rte_cpu_to_be_32(x) rte_bswap32(x)
116 #define rte_cpu_to_be_64(x) rte_bswap64(x)
118 #define rte_le_to_cpu_16(x) (x)
119 #define rte_le_to_cpu_32(x) (x)
120 #define rte_le_to_cpu_64(x) (x)
122 #define rte_be_to_cpu_16(x) rte_bswap16(x)
123 #define rte_be_to_cpu_32(x) rte_bswap32(x)
124 #define rte_be_to_cpu_64(x) rte_bswap64(x)
128 #define rte_cpu_to_le_16(x) rte_bswap16(x)
129 #define rte_cpu_to_le_32(x) rte_bswap32(x)
130 #define rte_cpu_to_le_64(x) rte_bswap64(x)
132 #define rte_cpu_to_be_16(x) (x)
133 #define rte_cpu_to_be_32(x) (x)
134 #define rte_cpu_to_be_64(x) (x)
136 #define rte_le_to_cpu_16(x) rte_bswap16(x)
137 #define rte_le_to_cpu_32(x) rte_bswap32(x)
138 #define rte_le_to_cpu_64(x) rte_bswap64(x)
140 #define rte_be_to_cpu_16(x) (x)
141 #define rte_be_to_cpu_32(x) (x)
142 #define rte_be_to_cpu_64(x) (x)
149 #endif /* _RTE_BYTEORDER_PPC_64_H_ */