diff options
author | Chris Robinson <[email protected]> | 2021-12-18 05:19:22 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-12-18 05:19:22 -0800 |
commit | a88803f21e1b44633de1aa5e068df8e9f371c2c2 (patch) | |
tree | a56b805f164965d55e8529a2c56afb155e29fe0d /common | |
parent | 0a87828b4134e7bde65a8f2e2e2b98519ca891d3 (diff) |
Simplify and combine a couple macros
Diffstat (limited to 'common')
-rw-r--r-- | common/opthelpers.h | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/common/opthelpers.h b/common/opthelpers.h index 87045739..5e6f54cf 100644 --- a/common/opthelpers.h +++ b/common/opthelpers.h @@ -8,23 +8,23 @@ #endif #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. +/* likely() optimizes for 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. */ -#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)) +/* The opposite of likely(), optimizing for the case where the condition is + * 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 +#define LIKELY(x) (likely(x)) +#define UNLIKELY(x) (unlikely(x)) #if HAS_BUILTIN(__builtin_assume) /* Unlike LIKELY, ASSUME requires the condition to be true or else it invokes |