From 9aa7ce77e8aed80057c559d4bf926188c1cf7a32 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Fri, 8 Aug 2008 15:33:16 -0700 Subject: Mark assert() tests as unlikely This forces compiler to generate the more common code on the faster path. --- lib/zassert.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/zassert.h') diff --git a/lib/zassert.h b/lib/zassert.h index 79126760..123aee16 100644 --- a/lib/zassert.h +++ b/lib/zassert.h @@ -17,9 +17,17 @@ extern void _zlog_assert_failed (const char *assertion, const char *file, #define __ASSERT_FUNCTION NULL #endif -#define zassert(EX) ((void)((EX) ? 0 : \ - (_zlog_assert_failed(#EX, __FILE__, __LINE__, \ - __ASSERT_FUNCTION), 0))) +#ifdef __GNUC__ +#define UNLIKELY(EX) __builtin_expect(!!(EX), 0) +#define LIKELY(EX) __builtin_expect(!!(EX), 1) +#else +#define UNLIKELY(EX) (EX) +#define LIKELY(EX) (EX) +#endif + +#define zassert(EX) ((void)(UNLIKELY(EX) ? 0 : \ + (_zlog_assert_failed(#EX, __FILE__, __LINE__, \ + __ASSERT_FUNCTION), 0))) #undef assert #define assert(EX) zassert(EX) -- cgit v1.2.3