summaryrefslogtreecommitdiff
path: root/src/common/common.h
diff options
context:
space:
mode:
authorbunnei <ericbunnie@gmail.com>2014-05-22 22:54:56 -0400
committerbunnei <ericbunnie@gmail.com>2014-05-22 22:54:56 -0400
commit1de7e8cbe4ee9aab3bc920721a90ef63537771b8 (patch)
tree4aae70232dc6d148af003a4d9f1c4f76aff5467b /src/common/common.h
parent9592d61037d05dc53b454644671a441788996208 (diff)
parent204c6bfeca2d3bccfe6602699c0b3420f88aaf07 (diff)
Merge branch 'master' of https://github.com/bunnei/citra
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 @@
#define STACKALIGN
-#if __cplusplus >= 201103 || defined(_MSC_VER) || defined(__GXX_EXPERIMENTAL_CXX0X__)
+#if __cplusplus >= 201103L || defined(_MSC_VER) || defined(__GXX_EXPERIMENTAL_CXX0X__)
#define HAVE_CXX11_SYNTAX 1
#endif
@@ -159,4 +159,48 @@ enum EMUSTATE_CHANGE
EMUSTATE_CHANGE_STOP
};
+
+#ifdef _MSC_VER
+#ifndef _XBOX
+inline unsigned long long bswap64(unsigned long long x) { return _byteswap_uint64(x); }
+inline unsigned int bswap32(unsigned int x) { return _byteswap_ulong(x); }
+inline unsigned short bswap16(unsigned short x) { return _byteswap_ushort(x); }
+#else
+inline unsigned long long bswap64(unsigned long long x) { return __loaddoublewordbytereverse(0, &x); }
+inline unsigned int bswap32(unsigned int x) { return __loadwordbytereverse(0, &x); }
+inline unsigned short bswap16(unsigned short x) { return __loadshortbytereverse(0, &x); }
+#endif
+#else
+// TODO: speedup
+inline unsigned short bswap16(unsigned short x) { return (x << 8) | (x >> 8); }
+inline unsigned int bswap32(unsigned int x) { return (x >> 24) | ((x & 0xFF0000) >> 8) | ((x & 0xFF00) << 8) | (x << 24);}
+inline unsigned long long bswap64(unsigned long long x) {return ((unsigned long long)bswap32(x) << 32) | bswap32(x >> 32); }
+#endif
+
+inline float bswapf(float f) {
+ union {
+ float f;
+ unsigned int u32;
+ } dat1, dat2;
+
+ dat1.f = f;
+ dat2.u32 = bswap32(dat1.u32);
+
+ return dat2.f;
+}
+
+inline double bswapd(double f) {
+ union {
+ double f;
+ unsigned long long u64;
+ } dat1, dat2;
+
+ dat1.f = f;
+ dat2.u64 = bswap64(dat1.u64);
+
+ return dat2.f;
+}
+
+#include "swap.h"
+
#endif // _COMMON_H_