summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorTillmann Karras <tilkax@gmail.com>2014-07-14 01:52:14 +0200
committerTillmann Karras <tilkax@gmail.com>2014-07-14 01:52:14 +0200
commitd398e9ef61f01b4b775ecc331ba207e30843dada (patch)
tree814fad94fcf8db16a8ffc712841735447a3eaf10 /Source/Core
parent16582a0459c63dda34af553aa293b8e3efa398b3 (diff)
Common: add macros for assisting branch prediction
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Common/Common.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/Source/Core/Common/Common.h b/Source/Core/Common/Common.h
index 232acf5e87..fa1cece364 100644
--- a/Source/Core/Common/Common.h
+++ b/Source/Core/Common/Common.h
@@ -15,7 +15,7 @@
#define __has_feature(x) 0
#endif
-// SVN version number
+// Git version number
extern const char *scm_desc_str;
extern const char *scm_branch_str;
extern const char *scm_rev_str;
@@ -37,6 +37,28 @@ extern const char *netplay_dolphin_ver;
#define UNUSED
#endif
+#if defined(__GNUC__) || __clang__
+ #define EXPECT(x, y) __builtin_expect(x, y)
+ #define LIKELY(x) __builtin_expect(!!(x), 1)
+ #define UNLIKELY(x) __builtin_expect(!!(x), 0)
+ // Careful, wrong assumptions result in undefined behavior!
+ #define UNREACHABLE __builtin_unreachable()
+ // Careful, wrong assumptions result in undefined behavior!
+ #define ASSUME(x) do { if (!x) __builtin_unreachable(); } while (0)
+#else
+ #define EXPECT(x, y) (x)
+ #define LIKELY(x) (x)
+ #define UNLIKELY(x) (x)
+ // Careful, wrong assumptions result in undefined behavior!
+ #define UNREACHABLE ASSUME(0)
+ #if defined(_MSC_VER)
+ // Careful, wrong assumptions result in undefined behavior!
+ #define ASSUME(x) __assume(x)
+ #else
+ #define ASSUME(x) do { void(x); } while (0)
+ #endif
+#endif
+
#define STACKALIGN
#if __cplusplus >= 201103 || defined(_MSC_VER) || defined(__GXX_EXPERIMENTAL_CXX0X__)