imull fix (suggested by Robert J. Harley)
[qemu/qemu_0_9_1_stable.git] / bswap.h
blob0632a9d9af7d2335c2195140da479ae980071639
1 #ifndef BSWAP_H
2 #define BSWAP_H
4 #include "config-host.h"
6 #include <inttypes.h>
8 #ifdef HAVE_BYTESWAP_H
9 #include <byteswap.h>
10 #else
12 #define bswap_16(x) \
13 ({ \
14 uint16_t __x = (x); \
15 ((uint16_t)( \
16 (((uint16_t)(__x) & (uint16_t)0x00ffU) << 8) | \
17 (((uint16_t)(__x) & (uint16_t)0xff00U) >> 8) )); \
20 #define bswap_32(x) \
21 ({ \
22 uint32_t __x = (x); \
23 ((uint32_t)( \
24 (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
25 (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
26 (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
27 (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
30 #define bswap_64(x) \
31 ({ \
32 uint64_t __x = (x); \
33 ((uint64_t)( \
34 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
35 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
36 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
37 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
38 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
39 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
40 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
41 (uint64_t)(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \
44 #endif /* !HAVE_BYTESWAP_H */
46 #if defined(__alpha__) || defined (__ia64__)
47 #define HOST_LONG_BITS 64
48 #else
49 #define HOST_LONG_BITS 32
50 #endif
52 #define HOST_LONG_SIZE (HOST_LONG_BITS / 8)
54 static inline uint16_t bswap16(uint16_t x)
56 return bswap_16(x);
59 static inline uint32_t bswap32(uint32_t x)
61 return bswap_32(x);
64 static inline uint64_t bswap64(uint64_t x)
66 return bswap_64(x);
69 static inline void bswap16s(uint16_t *s)
71 *s = bswap16(*s);
74 static inline void bswap32s(uint32_t *s)
76 *s = bswap32(*s);
79 static inline void bswap64s(uint64_t *s)
81 *s = bswap64(*s);
84 #endif /* BSWAP_H */