From 1679ab937e131f29f6b5140e433179f55d70a864 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 5 Dec 2020 06:40:06 -0800 Subject: [PATCH] Reorder definitions to keep them near each other --- common/opthelpers.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/common/opthelpers.h b/common/opthelpers.h index 58578c15..8f16fd3f 100644 --- a/common/opthelpers.h +++ b/common/opthelpers.h @@ -7,7 +7,7 @@ #define HAS_BUILTIN(x) (0) #endif -#ifdef __GNUC__ +#if defined(__GNUC__) || HAS_BUILTIN(__builtin_expect) /* LIKELY optimizes the case where the condition is true. The condition is not * required to be true, but it can result in more optimal code for the true * path at the expense of a less optimal false path. @@ -15,25 +15,25 @@ #define LIKELY(x) (__builtin_expect(!!(x), !false)) /* The opposite of LIKELY, optimizing the case where the condition is false. */ #define UNLIKELY(x) (__builtin_expect(!!(x), false)) + +#else + +#define LIKELY(x) (!!(x)) +#define UNLIKELY(x) (!!(x)) +#endif + +#if HAS_BUILTIN(__builtin_assume) /* Unlike LIKELY, ASSUME requires the condition to be true or else it invokes * undefined behavior. It's essentially an assert without actually checking the * condition at run-time, allowing for stronger optimizations than LIKELY. */ -#if HAS_BUILTIN(__builtin_assume) #define ASSUME __builtin_assume -#else -#define ASSUME(x) do { if(!(x)) __builtin_unreachable(); } while(0) -#endif - -#else /* __GNUC__ */ - -#define LIKELY(x) (!!(x)) -#define UNLIKELY(x) (!!(x)) -#ifdef _MSC_VER +#elif defined(_MSC_VER) #define ASSUME __assume +#elif defined(__GNUC__) +#define ASSUME(x) do { if(!(x)) __builtin_unreachable(); } while(0) #else #define ASSUME(x) ((void)0) -#endif /* _MSC_VER */ -#endif /* __GNUC__ */ +#endif #endif /* OPTHELPERS_H */