summaryrefslogtreecommitdiff
path: root/AK/Platform.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-30 11:43:25 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-30 11:43:25 +0200
commit888e35f0fed393e8496414e5c285cf4ca4788f67 (patch)
treeaa88e2b38bcb7cbb82adb0c0420401b7cb19dcf0 /AK/Platform.h
parentf1a8fb1e88f902c9af2f1b18e6375c0b75f7e711 (diff)
downloadserenity-888e35f0fed393e8496414e5c285cf4ca4788f67.zip
AK: Add ALWAYS_INLINE, NEVER_INLINE and FLATTEN macros
It's tedious to write (and look at) [[gnu::always_inline]] etc. :^)
Diffstat (limited to 'AK/Platform.h')
-rw-r--r--AK/Platform.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/AK/Platform.h b/AK/Platform.h
index 6763f641c2..df72a1cd09 100644
--- a/AK/Platform.h
+++ b/AK/Platform.h
@@ -36,6 +36,21 @@
#define ARCH(arch) (defined(AK_ARCH_##arch) && AK_ARCH_##arch)
+#ifdef ALWAYS_INLINE
+#undef ALWAYS_INLINE
+#endif
+#define ALWAYS_INLINE [[gnu::always_inline]] inline
+
+#ifdef NEVER_INLINE
+#undef NEVER_INLINE
+#endif
+#define NEVER_INLINE [[gnu::noinline]]
+
+#ifdef FLATTEN
+#undef FLATTEN
+#endif
+#define FLATTEN [[gnu::flatten]]
+
// FIXME: Re-enable this when we can figure out why Clang gets confused about "unknown"
#if 0
# define CONSUMABLE(initial_state) __attribute__((consumable(initial_state)))
@@ -70,7 +85,7 @@ inline int open_with_path_length(const char* path, size_t path_length, int optio
#endif
template<typename T>
-[[gnu::always_inline]] inline T convert_between_host_and_network(T value)
+ALWAYS_INLINE T convert_between_host_and_network(T value)
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
if constexpr (sizeof(T) == 8)
@@ -86,7 +101,7 @@ template<typename T>
#endif
}
-[[gnu::always_inline]] inline int count_trailing_zeroes_32(unsigned int val)
+ALWAYS_INLINE int count_trailing_zeroes_32(unsigned int val)
{
#if defined(__GNUC__) || defined(__clang__)
return __builtin_ctz(val);