Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #614 from Tilka/branch_prediction
[RFC] Common: add macros for assisting branch prediction
  • Loading branch information
delroth committed Jul 14, 2014
2 parents 3f67ec0 + d398e9e commit dee6f22
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Source/Core/Common/Common.h
Expand Up @@ -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;
Expand All @@ -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__)
Expand Down

0 comments on commit dee6f22

Please sign in to comment.