1 /******************************************************************************
2 * Copyright (c) 2011 IBM Corporation
4 * This program and the accompanying materials
5 * are made available under the terms of the BSD License
6 * which accompanies this distribution, and is available at
7 * http://www.opensource.org/licenses/bsd-license.php
10 * IBM Corporation - initial implementation
11 *****************************************************************************/
14 * Common byteorder (endianness) macros
22 static inline uint16_t
25 return __builtin_bswap16(x);
28 static inline uint32_t
31 return __builtin_bswap32(x);
34 static inline uint64_t
37 return __builtin_bswap64(x);
41 bswap_16p (uint16_t *x)
43 *x = __builtin_bswap16(*x);
47 bswap_32p (uint32_t *x)
49 *x = __builtin_bswap32(*x);
53 bswap_64p (uint64_t *x)
55 *x = __builtin_bswap64(*x);
59 /* gcc defines __BIG_ENDIAN__ on big endian targets */
62 #define cpu_to_be16(x) (x)
63 #define cpu_to_be32(x) (x)
64 #define cpu_to_be64(x) (x)
66 #define be16_to_cpu(x) (x)
67 #define be32_to_cpu(x) (x)
68 #define be64_to_cpu(x) (x)
70 #define le16_to_cpu(x) bswap_16(x)
71 #define le32_to_cpu(x) bswap_32(x)
72 #define le64_to_cpu(x) bswap_64(x)
74 #define cpu_to_le16(x) bswap_16(x)
75 #define cpu_to_le32(x) bswap_32(x)
76 #define cpu_to_le64(x) bswap_64(x)
80 #define cpu_to_be16(x) bswap_16(x)
81 #define cpu_to_be32(x) bswap_32(x)
82 #define cpu_to_be64(x) bswap_64(x)
84 #define be16_to_cpu(x) bswap_16(x)
85 #define be32_to_cpu(x) bswap_32(x)
86 #define be64_to_cpu(x) bswap_64(x)
88 #define le16_to_cpu(x) (x)
89 #define le32_to_cpu(x) (x)
90 #define le64_to_cpu(x) (x)
92 #define cpu_to_le16(x) (x)
93 #define cpu_to_le32(x) (x)
94 #define cpu_to_le64(x) (x)
96 #endif /* __BIG_ENDIAN__ */
98 #endif /* BYTEORDER_H */