Reorder definitions to keep them near each other

This commit is contained in:
Chris Robinson
2020-12-05 06:40:06 -08:00
parent 16c7d1816d
commit 1679ab937e
+13 -13
View File
@@ -7,7 +7,7 @@
#define HAS_BUILTIN(x) (0) #define HAS_BUILTIN(x) (0)
#endif #endif
#ifdef __GNUC__ #if defined(__GNUC__) || HAS_BUILTIN(__builtin_expect)
/* LIKELY optimizes the case where the condition is true. The condition is not /* 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 * 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. * path at the expense of a less optimal false path.
@@ -15,25 +15,25 @@
#define LIKELY(x) (__builtin_expect(!!(x), !false)) #define LIKELY(x) (__builtin_expect(!!(x), !false))
/* The opposite of LIKELY, optimizing the case where the condition is false. */ /* The opposite of LIKELY, optimizing the case where the condition is false. */
#define UNLIKELY(x) (__builtin_expect(!!(x), 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 /* Unlike LIKELY, ASSUME requires the condition to be true or else it invokes
* undefined behavior. It's essentially an assert without actually checking the * undefined behavior. It's essentially an assert without actually checking the
* condition at run-time, allowing for stronger optimizations than LIKELY. * condition at run-time, allowing for stronger optimizations than LIKELY.
*/ */
#if HAS_BUILTIN(__builtin_assume)
#define ASSUME __builtin_assume #define ASSUME __builtin_assume
#else #elif defined(_MSC_VER)
#define ASSUME(x) do { if(!(x)) __builtin_unreachable(); } while(0)
#endif
#else /* __GNUC__ */
#define LIKELY(x) (!!(x))
#define UNLIKELY(x) (!!(x))
#ifdef _MSC_VER
#define ASSUME __assume #define ASSUME __assume
#elif defined(__GNUC__)
#define ASSUME(x) do { if(!(x)) __builtin_unreachable(); } while(0)
#else #else
#define ASSUME(x) ((void)0) #define ASSUME(x) ((void)0)
#endif /* _MSC_VER */ #endif
#endif /* __GNUC__ */
#endif /* OPTHELPERS_H */ #endif /* OPTHELPERS_H */