aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-12-05 06:40:06 -0800
committerChris Robinson <[email protected]>2020-12-05 06:40:06 -0800
commit1679ab937e131f29f6b5140e433179f55d70a864 (patch)
treefed98026e88e6cac337ffd7848121775873511e8
parent16c7d1816dfd72e1b4172b852a4fc676ed3cf2bf (diff)
Reorder definitions to keep them near each other
-rw-r--r--common/opthelpers.h26
1 files 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 */