1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

core/compiler_hints: add likely() / unlikely() hints

This commit is contained in:
Benjamin Valentin 2023-01-16 15:10:33 +01:00
parent 1c7300bb41
commit 75f666f6b3

View File

@ -21,6 +21,8 @@
#ifndef COMPILER_HINTS_H
#define COMPILER_HINTS_H
#include <stdint.h>
#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