5 #define HAS_BUILTIN __has_builtin
7 #define HAS_BUILTIN(x) (0)
11 /* LIKELY optimizes the case where the condition is true. The condition is not
12 * required to be true, but it can result in more optimal code for the true
13 * path at the expense of a less optimal false path.
15 #define LIKELY(x) (__builtin_expect(!!(x), !false))
16 /* The opposite of LIKELY, optimizing the case where the condition is false. */
17 #define UNLIKELY(x) (__builtin_expect(!!(x), false))
18 /* Unlike LIKELY, ASSUME requires the condition to be true or else it invokes
19 * undefined behavior. It's essentially an assert without actually checking the
20 * condition at run-time, allowing for stronger optimizations than LIKELY.
22 #if HAS_BUILTIN(__builtin_assume)
23 #define ASSUME __builtin_assume
25 #define ASSUME(x) do { if(!(x)) __builtin_unreachable(); } while(0)
30 #define LIKELY(x) (!!(x))
31 #define UNLIKELY(x) (!!(x))
33 #define ASSUME __assume
35 #define ASSUME(x) ((void)0)
39 #endif /* OPTHELPERS_H */