summaryrefslogtreecommitdiff
path: root/src/common/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/common.h')
-rw-r--r--src/common/common.h46
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
165inline unsigned long long bswap64(unsigned long long x) { return _byteswap_uint64(x); }
166inline unsigned int bswap32(unsigned int x) { return _byteswap_ulong(x); }
167inline unsigned short bswap16(unsigned short x) { return _byteswap_ushort(x); }
168#else
169inline unsigned long long bswap64(unsigned long long x) { return __loaddoublewordbytereverse(0, &x); }
170inline unsigned int bswap32(unsigned int x) { return __loadwordbytereverse(0, &x); }
171inline unsigned short bswap16(unsigned short x) { return __loadshortbytereverse(0, &x); }
172#endif
173#else
174// TODO: speedup
175inline unsigned short bswap16(unsigned short x) { return (x << 8) | (x >> 8); }
176inline unsigned int bswap32(unsigned int x) { return (x >> 24) | ((x & 0xFF0000) >> 8) | ((x & 0xFF00) << 8) | (x << 24);}
177inline unsigned long long bswap64(unsigned long long x) {return ((unsigned long long)bswap32(x) << 32) | bswap32(x >> 32); }
178#endif
179
180inline 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
192inline 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_