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 typedef uint16_t le16;
23 typedef uint32_t le32;
24 typedef uint64_t le64;
26 static inline uint16_t bswap_16 (uint16_t x)
28 return __builtin_bswap16(x);
31 static inline uint32_t bswap_32 (uint32_t x)
33 return __builtin_bswap32(x);
36 static inline uint64_t bswap_64 (uint64_t x)
38 return __builtin_bswap64(x);
41 static inline void bswap_16p (uint16_t *x)
43 *x = __builtin_bswap16(*x);
46 static inline void bswap_32p (uint32_t *x)
48 *x = __builtin_bswap32(*x);
51 static inline void bswap_64p (uint64_t *x)
53 *x = __builtin_bswap64(*x);
57 /* gcc defines __BIG_ENDIAN__ on big endian targets */
60 #define cpu_to_be16(x) (x)
61 #define cpu_to_be32(x) (x)
62 #define cpu_to_be64(x) (x)
64 #define be16_to_cpu(x) (x)
65 #define be32_to_cpu(x) (x)
66 #define be64_to_cpu(x) (x)
68 #define le16_to_cpu(x) bswap_16(x)
69 #define le32_to_cpu(x) bswap_32(x)
70 #define le64_to_cpu(x) bswap_64(x)
72 #define cpu_to_le16(x) bswap_16(x)
73 #define cpu_to_le32(x) bswap_32(x)
74 #define cpu_to_le64(x) bswap_64(x)
78 #define cpu_to_be16(x) bswap_16(x)
79 #define cpu_to_be32(x) bswap_32(x)
80 #define cpu_to_be64(x) bswap_64(x)
82 #define be16_to_cpu(x) bswap_16(x)
83 #define be32_to_cpu(x) bswap_32(x)
84 #define be64_to_cpu(x) bswap_64(x)
86 #define le16_to_cpu(x) (x)
87 #define le32_to_cpu(x) (x)
88 #define le64_to_cpu(x) (x)
90 #define cpu_to_le16(x) (x)
91 #define cpu_to_le32(x) (x)
92 #define cpu_to_le64(x) (x)
94 #endif /* __BIG_ENDIAN__ */
96 #endif /* BYTEORDER_H */