Changeset 36125 in vbox for trunk/src/recompiler/bswap.h
- Timestamp:
- Mar 1, 2011 4:49:42 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/recompiler/bswap.h
r13382 r36125 4 4 #include "config-host.h" 5 5 6 #ifndef _MSC_VER7 6 #include <inttypes.h> 8 #endif9 7 10 8 #ifdef HAVE_BYTESWAP_H 11 9 #include <byteswap.h> 12 #else13 #ifdef _MSC_VER14 static _inline uint16_t bswap_16(register uint16_t x)15 {16 return ((uint16_t)( \17 (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \18 (((uint16_t)(x) & (uint16_t)0xff00U) >> 8) )); \19 }20 21 static _inline uint32_t bswap_32(register uint32_t x) \22 { \23 return ((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) )); \28 }29 30 static _inline uint64_t bswap_64(register uint64_t x) \31 { \32 return ((uint64_t)( \33 (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \34 (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \35 (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \36 (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \37 (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \38 (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \39 (uint64_t)(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \40 (uint64_t)(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \41 }42 43 10 #else 44 11 … … 74 41 (uint64_t)(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \ 75 42 }) 76 #endif77 43 78 44 #endif /* !HAVE_BYTESWAP_H */ 79 45 80 46 #ifndef bswap16 /* BSD endian.h clash */ 81 #ifndef VBOX82 47 static inline uint16_t bswap16(uint16_t x) 83 #else84 DECLINLINE(uint16_t) bswap16(uint16_t x)85 #endif86 48 { 87 49 return bswap_16(x); … … 90 52 91 53 #ifndef bswap32 /* BSD endian.h clash */ 92 #ifndef VBOX93 54 static inline uint32_t bswap32(uint32_t x) 94 #else95 DECLINLINE(uint32_t) bswap32(uint32_t x)96 #endif97 55 { 98 56 return bswap_32(x); … … 101 59 102 60 #ifndef bswap64 /* BSD endian.h clash. */ 103 #ifndef VBOX104 61 static inline uint64_t bswap64(uint64_t x) 105 #else106 DECLINLINE(uint64_t) bswap64(uint64_t x)107 #endif108 62 { 109 63 return bswap_64(x); … … 111 65 #endif 112 66 113 #ifndef VBOX114 67 static inline void bswap16s(uint16_t *s) 115 #else116 DECLINLINE(void) bswap16s(uint16_t *s)117 #endif118 68 { 119 69 *s = bswap16(*s); 120 70 } 121 71 122 #ifndef VBOX123 72 static inline void bswap32s(uint32_t *s) 124 #else125 DECLINLINE(void) bswap32s(uint32_t *s)126 #endif127 73 { 128 74 *s = bswap32(*s); 129 75 } 130 76 131 #ifndef VBOX132 77 static inline void bswap64s(uint64_t *s) 133 #else134 DECLINLINE(void) bswap64s(uint64_t *s)135 #endif136 78 { 137 79 *s = bswap64(*s); … … 150 92 #endif 151 93 152 #ifndef VBOX153 94 #define CPU_CONVERT(endian, size, type)\ 154 95 static inline type endian ## size ## _to_cpu(type v)\ … … 181 122 *p = cpu_to_ ## endian ## size(v);\ 182 123 } 183 #else /* VBOX */184 #define CPU_CONVERT(endian, size, type)\185 DECLINLINE(type) endian ## size ## _to_cpu(type v)\186 {\187 return endian ## _bswap(v, size);\188 }\189 \190 DECLINLINE(type) cpu_to_ ## endian ## size(type v)\191 {\192 return endian ## _bswap(v, size);\193 }\194 \195 DECLINLINE(void) endian ## size ## _to_cpus(type *p)\196 {\197 endian ## _bswaps(p, size)\198 }\199 \200 DECLINLINE(void) cpu_to_ ## endian ## size ## s(type *p)\201 {\202 endian ## _bswaps(p, size)\203 }\204 \205 DECLINLINE(type) endian ## size ## _to_cpup(const type *p)\206 {\207 return endian ## size ## _to_cpu(*p);\208 }\209 \210 DECLINLINE(void) cpu_to_ ## endian ## size ## w(type *p, type v)\211 {\212 *p = cpu_to_ ## endian ## size(v);\213 }214 #endif /* VBOX */215 124 216 125 CPU_CONVERT(be, 16, uint16_t)
Note:
See TracChangeset
for help on using the changeset viewer.