From b9b8b0521bb8cd91b708c2ef38ac2480ccac072e Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 29 Jun 2022 02:36:39 +0300 Subject: [PATCH] common: add unlikely()/likely() macros --- common/xash3d_types.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/common/xash3d_types.h b/common/xash3d_types.h index 71ceca77..ffc3faee 100644 --- a/common/xash3d_types.h +++ b/common/xash3d_types.h @@ -87,6 +87,16 @@ typedef uint64_t longtime_t; #define NORETURN #endif +#if defined(__has_builtin) +#if __has_builtin(__builtin_expect) +#define unlikely(x) __builtin_expect(x, 0) +#define likely(x) __builtin_expect(x, 1) +#else // __has_builtin(__builtin_expect) +#define unlikely(x) (x) +#define likely(x) (x) +#endif // __has_builtin(__builtin_expect) +#endif // defined(__has_builtin) + #ifdef XASH_BIG_ENDIAN #define LittleLong(x) (((int)(((x)&255)<<24)) + ((int)((((x)>>8)&255)<<16)) + ((int)(((x)>>16)&255)<<8) + (((x) >> 24)&255))