mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:12:57 +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
|
#ifndef COMPILER_HINTS_H
|
||||||
#define COMPILER_HINTS_H
|
#define COMPILER_HINTS_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -130,6 +132,24 @@ extern "C" {
|
|||||||
#define IS_CT_CONSTANT(expr) 0
|
#define IS_CT_CONSTANT(expr) 0
|
||||||
#endif
|
#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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user