aboutsummaryrefslogtreecommitdiffstats
path: root/common/opthelpers.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2021-10-03 06:41:14 -0700
committerChris Robinson <[email protected]>2021-10-03 06:41:14 -0700
commit38d3ea35017944929f9d52a1c840ace68846fee9 (patch)
tree3e667cfd07130b4e09d21658fdf48ba0d9e89163 /common/opthelpers.h
parentc66e4f5bd447d2bb1a38446510bff87ada00fb9f (diff)
Make simpler likely/unlikely functions and use them in some places
Diffstat (limited to 'common/opthelpers.h')
-rw-r--r--common/opthelpers.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/common/opthelpers.h b/common/opthelpers.h
index bb0b63fe..87045739 100644
--- a/common/opthelpers.h
+++ b/common/opthelpers.h
@@ -13,13 +13,17 @@
* path at the expense of a less optimal false path.
*/
#define LIKELY(x) (__builtin_expect(!!(x), !false))
+constexpr bool likely(bool expr) { return __builtin_expect(expr, true); }
/* The opposite of LIKELY, optimizing the case where the condition is false. */
#define UNLIKELY(x) (__builtin_expect(!!(x), false))
+constexpr bool unlikely(bool expr) { return __builtin_expect(expr, false); }
#else
#define LIKELY(x) (!!(x))
#define UNLIKELY(x) (!!(x))
+constexpr bool likely(bool expr) { return expr; }
+constexpr bool unlikely(bool expr) { return expr; }
#endif
#if HAS_BUILTIN(__builtin_assume)