diff options
Diffstat (limited to '')
| -rw-r--r-- | src/common/common.h | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/common/common.h b/src/common/common.h index 418757855..2578d0010 100644 --- a/src/common/common.h +++ b/src/common/common.h | |||
| @@ -21,7 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | #define STACKALIGN | 22 | #define STACKALIGN |
| 23 | 23 | ||
| 24 | #if __cplusplus >= 201103 || defined(_MSC_VER) || defined(__GXX_EXPERIMENTAL_CXX0X__) | 24 | #if __cplusplus >= 201103L || defined(_MSC_VER) || defined(__GXX_EXPERIMENTAL_CXX0X__) |
| 25 | #define HAVE_CXX11_SYNTAX 1 | 25 | #define HAVE_CXX11_SYNTAX 1 |
| 26 | #endif | 26 | #endif |
| 27 | 27 | ||
| @@ -159,4 +159,48 @@ enum EMUSTATE_CHANGE | |||
| 159 | EMUSTATE_CHANGE_STOP | 159 | EMUSTATE_CHANGE_STOP |
| 160 | }; | 160 | }; |
| 161 | 161 | ||
| 162 | |||
| 163 | #ifdef _MSC_VER | ||
| 164 | #ifndef _XBOX | ||
| 165 | inline unsigned long long bswap64(unsigned long long x) { return _byteswap_uint64(x); } | ||
| 166 | inline unsigned int bswap32(unsigned int x) { return _byteswap_ulong(x); } | ||
| 167 | inline unsigned short bswap16(unsigned short x) { return _byteswap_ushort(x); } | ||
| 168 | #else | ||
| 169 | inline unsigned long long bswap64(unsigned long long x) { return __loaddoublewordbytereverse(0, &x); } | ||
| 170 | inline unsigned int bswap32(unsigned int x) { return __loadwordbytereverse(0, &x); } | ||
| 171 | inline unsigned short bswap16(unsigned short x) { return __loadshortbytereverse(0, &x); } | ||
| 172 | #endif | ||
| 173 | #else | ||
| 174 | // TODO: speedup | ||
| 175 | inline unsigned short bswap16(unsigned short x) { return (x << 8) | (x >> 8); } | ||
| 176 | inline unsigned int bswap32(unsigned int x) { return (x >> 24) | ((x & 0xFF0000) >> 8) | ((x & 0xFF00) << 8) | (x << 24);} | ||
| 177 | inline unsigned long long bswap64(unsigned long long x) {return ((unsigned long long)bswap32(x) << 32) | bswap32(x >> 32); } | ||
| 178 | #endif | ||
| 179 | |||
| 180 | inline float bswapf(float f) { | ||
| 181 | union { | ||
| 182 | float f; | ||
| 183 | unsigned int u32; | ||
| 184 | } dat1, dat2; | ||
| 185 | |||
| 186 | dat1.f = f; | ||
| 187 | dat2.u32 = bswap32(dat1.u32); | ||
| 188 | |||
| 189 | return dat2.f; | ||
| 190 | } | ||
| 191 | |||
| 192 | inline double bswapd(double f) { | ||
| 193 | union { | ||
| 194 | double f; | ||
| 195 | unsigned long long u64; | ||
| 196 | } dat1, dat2; | ||
| 197 | |||
| 198 | dat1.f = f; | ||
| 199 | dat2.u64 = bswap64(dat1.u64); | ||
| 200 | |||
| 201 | return dat2.f; | ||
| 202 | } | ||
| 203 | |||
| 204 | #include "swap.h" | ||
| 205 | |||
| 162 | #endif // _COMMON_H_ | 206 | #endif // _COMMON_H_ |