Author: manx
Date: Sun Mar 3 16:32:41 2024
New Revision: 20217
URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20217
Log:
[Ref] mpt/base/macros.hpp: Add MPT_ASSUME(expr) for C++23 [[assume(expr)]].
Modified:
trunk/OpenMPT/src/mpt/base/macros.hpp
Modified: trunk/OpenMPT/src/mpt/base/macros.hpp
==============================================================================
--- trunk/OpenMPT/src/mpt/base/macros.hpp Sun Mar 3 13:49:57 2024 (r20216)
+++ trunk/OpenMPT/src/mpt/base/macros.hpp Sun Mar 3 16:32:41 2024 (r20217)
@@ -152,4 +152,23 @@
+#if MPT_CXX_AT_LEAST(23)
+#define MPT_ASSUME(expr) [[assume(expr)]]
+#else // !C++23
+#if MPT_COMPILER_CLANG
+#define MPT_ASSUME(expr) __builtin_assume(expr)
+#endif
+#if MPT_COMPILER_MSVC
+#define MPT_ASSUME(expr) __assume(expr)
+#endif
+#if MPT_COMPILER_GCC
+#define MPT_ASSUME(expr) do { if (!expr) { __builtin_unreachable(); } } while(0)
+#endif
+#if !defined(MPT_ASSUME)
+#define MPT_ASSUME(expr) MPT_DISCARD(expr)
+#endif
+#endif // C++23
+
+
+
#endif // MPT_BASE_MACROS_HPP
|