mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
core/compiler_hints: add assume() hint
This commit is contained in:
parent
bc517b5c47
commit
c1f63cafa8
@ -21,6 +21,7 @@
|
||||
#ifndef COMPILER_HINTS_H
|
||||
#define COMPILER_HINTS_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -164,6 +165,22 @@ extern "C" {
|
||||
*/
|
||||
#define unlikely(x) __builtin_expect((uintptr_t)(x), 0)
|
||||
|
||||
/**
|
||||
* @brief Behaves like an `assert()`, but tells the compiler that @p cond can
|
||||
* never be false.
|
||||
* This allows the compiler to optimize the code accordingly even when
|
||||
* `NDEBUG` is set / with `DEVELHELP=0`.
|
||||
*
|
||||
* @p cond being false will result in undefined behavior.
|
||||
*
|
||||
* @param[in] cond Condition that is guaranteed to be true
|
||||
*/
|
||||
#ifdef NDEBUG
|
||||
#define assume(cond) ((cond) ? (void)0 : UNREACHABLE())
|
||||
#else
|
||||
#define assume(cond) assert(cond)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user