mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-14 10:37:29 +00:00
lib: add OPTIMIZE + assume() to compiler.h
Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
parent
f7288f1515
commit
111a04f740
@ -33,6 +33,9 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
# define _CONSTRUCTOR(x) constructor(x)
|
# define _CONSTRUCTOR(x) constructor(x)
|
||||||
# define _DEPRECATED(x) deprecated(x)
|
# define _DEPRECATED(x) deprecated(x)
|
||||||
|
# if __has_builtin(assume)
|
||||||
|
# define assume(x) __builtin_assume(x)
|
||||||
|
# endif
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
|
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
|
||||||
# define _RET_NONNULL , returns_nonnull
|
# define _RET_NONNULL , returns_nonnull
|
||||||
@ -44,12 +47,28 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
|
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
|
||||||
# define _DEPRECATED(x) deprecated(x)
|
# define _DEPRECATED(x) deprecated(x)
|
||||||
|
# define assume(x) do { if (!(x)) __builtin_unreachable(); } while (0)
|
||||||
|
#endif
|
||||||
|
#if __GNUC__ < 5
|
||||||
|
# define __has_attribute(x) 0
|
||||||
#endif
|
#endif
|
||||||
#if __GNUC__ >= 7
|
#if __GNUC__ >= 7
|
||||||
# define _FALLTHROUGH __attribute__((fallthrough));
|
# define _FALLTHROUGH __attribute__((fallthrough));
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __has_attribute(hot)
|
||||||
|
# define _OPTIMIZE_HOT __attribute__((hot))
|
||||||
|
#else
|
||||||
|
# define _OPTIMIZE_HOT
|
||||||
|
#endif
|
||||||
|
#if __has_attribute(optimize)
|
||||||
|
# define _OPTIMIZE_O3 __attribute__((optimize("3")))
|
||||||
|
#else
|
||||||
|
# define _OPTIMIZE_O3
|
||||||
|
#endif
|
||||||
|
#define OPTIMIZE _OPTIMIZE_O3 _OPTIMIZE_HOT
|
||||||
|
|
||||||
#if !defined(__GNUC__)
|
#if !defined(__GNUC__)
|
||||||
#error module code needs GCC visibility extensions
|
#error module code needs GCC visibility extensions
|
||||||
#elif __GNUC__ < 4
|
#elif __GNUC__ < 4
|
||||||
@ -85,6 +104,9 @@ extern "C" {
|
|||||||
#ifndef _DEPRECATED
|
#ifndef _DEPRECATED
|
||||||
#define _DEPRECATED(x) deprecated
|
#define _DEPRECATED(x) deprecated
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef assume
|
||||||
|
#define assume(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* pure = function does not modify memory & return value is the same if
|
/* pure = function does not modify memory & return value is the same if
|
||||||
* memory hasn't changed (=> allows compiler to optimize)
|
* memory hasn't changed (=> allows compiler to optimize)
|
||||||
|
Loading…
Reference in New Issue
Block a user