summaryrefslogtreecommitdiff
path: root/lib/compiler.h
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@users.noreply.github.com>2019-06-07 11:23:16 -0400
committerGitHub <noreply@github.com>2019-06-07 11:23:16 -0400
commit9f9307c95369f667d209a5a6bd2fd24f44af1cb6 (patch)
tree3fd696fa7642094d30625a3073c50c49d4db8fe0 /lib/compiler.h
parent9c2bdd70826a616b3c50e780be5dceeaa9b10925 (diff)
parent874035be4e65a889525b0380ce686b64e7ff5bb0 (diff)
Merge pull request #4480 from opensourcerouting/inet_ntop
inet_ntop but faster
Diffstat (limited to 'lib/compiler.h')
-rw-r--r--lib/compiler.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/compiler.h b/lib/compiler.h
index 7509428220..9ce91e3361 100644
--- a/lib/compiler.h
+++ b/lib/compiler.h
@@ -33,6 +33,9 @@ extern "C" {
#endif
# define _CONSTRUCTOR(x) constructor(x)
# define _DEPRECATED(x) deprecated(x)
+# if __has_builtin(assume)
+# define assume(x) __builtin_assume(x)
+# endif
#elif defined(__GNUC__)
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
# define _RET_NONNULL , returns_nonnull
@@ -44,12 +47,28 @@ extern "C" {
#endif
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
# 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
#if __GNUC__ >= 7
# define _FALLTHROUGH __attribute__((fallthrough));
#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__)
#error module code needs GCC visibility extensions
#elif __GNUC__ < 4
@@ -85,6 +104,9 @@ extern "C" {
#ifndef _DEPRECATED
#define _DEPRECATED(x) deprecated
#endif
+#ifndef assume
+#define assume(x)
+#endif
/* pure = function does not modify memory & return value is the same if
* memory hasn't changed (=> allows compiler to optimize)