diff --git a/core/lib/include/compiler_hints.h b/core/lib/include/compiler_hints.h index cc0543268c..aa600b7675 100644 --- a/core/lib/include/compiler_hints.h +++ b/core/lib/include/compiler_hints.h @@ -21,6 +21,8 @@ #ifndef COMPILER_HINTS_H #define COMPILER_HINTS_H +#include + #ifdef __cplusplus extern "C" { #endif @@ -130,6 +132,24 @@ extern "C" { #define IS_CT_CONSTANT(expr) 0 #endif +/** + * @brief Hint to the compiler that the condition @p x is likely taken + * + * @param[in] x Condition that is likely taken + * + * @return result of @p x + */ +#define likely(x) __builtin_expect((uintptr_t)(x), 1) + +/** + * @brief Hint to the compiler that the condition @p x is likely not taken + * + * @param[in] x Condition that is unlikely + * + * @return result of @p x + */ +#define unlikely(x) __builtin_expect((uintptr_t)(x), 0) + #ifdef __cplusplus } #endif