migration/rdma: Silence qemu_rdma_reg_control()
[qemu/armbru.git] / include / exec / tswap.h
blob68944a880ba287b2f4d15aac0e17829f04668cb4
1 /*
2 * Macros for swapping a value if the endianness is different
3 * between the target and the host.
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
8 #ifndef TSWAP_H
9 #define TSWAP_H
11 #include "hw/core/cpu.h"
12 #include "qemu/bswap.h"
15 * If we're in target-specific code, we can hard-code the swapping
16 * condition, otherwise we have to do (slower) run-time checks.
18 #ifdef NEED_CPU_H
19 #define target_needs_bswap() (HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN)
20 #else
21 #define target_needs_bswap() (target_words_bigendian() != HOST_BIG_ENDIAN)
22 #endif
24 static inline uint16_t tswap16(uint16_t s)
26 if (target_needs_bswap()) {
27 return bswap16(s);
28 } else {
29 return s;
33 static inline uint32_t tswap32(uint32_t s)
35 if (target_needs_bswap()) {
36 return bswap32(s);
37 } else {
38 return s;
42 static inline uint64_t tswap64(uint64_t s)
44 if (target_needs_bswap()) {
45 return bswap64(s);
46 } else {
47 return s;
51 static inline void tswap16s(uint16_t *s)
53 if (target_needs_bswap()) {
54 *s = bswap16(*s);
58 static inline void tswap32s(uint32_t *s)
60 if (target_needs_bswap()) {
61 *s = bswap32(*s);
65 static inline void tswap64s(uint64_t *s)
67 if (target_needs_bswap()) {
68 *s = bswap64(*s);
72 #endif /* TSWAP_H */