From 833903e7ef3bee3e0a8ddf61583c73b7f22476e3 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 24 Aug 2005 17:42:01 +0000 Subject: [PATCH] branch optimization to reduce the cost of asserts --- stepmania/src/global.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/stepmania/src/global.h b/stepmania/src/global.h index 6ac7dd73c8..6537ab3ad7 100644 --- a/stepmania/src/global.h +++ b/stepmania/src/global.h @@ -53,6 +53,15 @@ #include #endif +/* Branch optimizations: */ +#if defined(__GNUC__) +#define likely(x) (!!__builtin_expect((x), 1)) +#define unlikely(x) (!!__builtin_expect((x), 0)) +#else +#define likely(x) (x) +#define unlikely(x) (x) +#endif + #if defined(NEED_CSTDLIB_WORKAROUND) #define llabs ::llabs #endif @@ -91,7 +100,7 @@ void NORETURN sm_crash( const char *reason = "Internal error" ); * exception in most cases we expect never to happen (but not in cases that * we do expect, such as DSound init failure.) */ #define FAIL_M(MESSAGE) { CHECKPOINT_M(MESSAGE); sm_crash(MESSAGE); } -#define ASSERT_M(COND, MESSAGE) { if(!(COND)) { FAIL_M(MESSAGE); } } +#define ASSERT_M(COND, MESSAGE) { if(unlikely(!(COND))) { FAIL_M(MESSAGE); } } #define ASSERT(COND) ASSERT_M((COND), "Assertion '" #COND "' failed") void ShowWarning( const char *file, int line, const char *message ); // don't pull in LOG here