Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / include / byteorder.h
1 /******************************************************************************
2  * Copyright (c) 2011 IBM Corporation
3  * All rights reserved.
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
8  *
9  * Contributors:
10  *     IBM Corporation - initial implementation
11  *****************************************************************************/
12
13 /*
14  * Common byteorder (endianness) macros
15  */
16
17 #ifndef BYTEORDER_H
18 #define BYTEORDER_H
19
20 #include <stdint.h>
21
22 static inline uint16_t
23 bswap_16 (uint16_t x)
24 {
25         return __builtin_bswap16(x);
26 }
27
28 static inline uint32_t
29 bswap_32 (uint32_t x)
30 {
31         return __builtin_bswap32(x);
32 }
33
34 static inline uint64_t
35 bswap_64 (uint64_t x)
36 {
37         return __builtin_bswap64(x);
38 }
39
40 static inline void
41 bswap_16p (uint16_t *x)
42 {
43         *x = __builtin_bswap16(*x);
44 }
45
46 static inline void
47 bswap_32p (uint32_t *x)
48 {
49         *x = __builtin_bswap32(*x);
50 }
51
52 static inline void
53 bswap_64p (uint64_t *x)
54 {
55         *x = __builtin_bswap64(*x);
56 }
57
58
59 /* gcc defines __BIG_ENDIAN__ on big endian targets */
60 #ifdef __BIG_ENDIAN__
61
62 #define cpu_to_be16(x) (x)
63 #define cpu_to_be32(x) (x)
64 #define cpu_to_be64(x) (x)
65
66 #define be16_to_cpu(x) (x)
67 #define be32_to_cpu(x) (x)
68 #define be64_to_cpu(x) (x)
69
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)
73
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)
77
78 #else
79
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)
83
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)
87
88 #define le16_to_cpu(x) (x)
89 #define le32_to_cpu(x) (x)
90 #define le64_to_cpu(x) (x)
91
92 #define cpu_to_le16(x) (x)
93 #define cpu_to_le32(x) (x)
94 #define cpu_to_le64(x) (x)
95
96 #endif  /* __BIG_ENDIAN__ */
97
98 #endif  /* BYTEORDER_H */