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:
parent
1c7300bb41
commit
75f666f6b3
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user