|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84679 - in trunk: boost/config boost/config/compiler libs/config/doc
From: andrey.semashev_at_[hidden]
Date: 2013-06-07 16:05:18
Author: andysem
Date: 2013-06-07 16:05:18 EDT (Fri, 07 Jun 2013)
New Revision: 84679
URL: http://svn.boost.org/trac/boost/changeset/84679
Log:
Added BOOST_NOINLINE, BOOST_LIKELY and BOOST_UNLIKELY macros.
Text files modified:
trunk/boost/config/compiler/clang.hpp | 8 ++++++++
trunk/boost/config/compiler/gcc.hpp | 8 ++++++--
trunk/boost/config/compiler/intel.hpp | 8 ++++++++
trunk/boost/config/suffix.hpp | 30 +++++++++++++++++++++++++++++-
trunk/libs/config/doc/macro_reference.qbk | 28 ++++++++++++++++++++++++++++
5 files changed, 79 insertions(+), 3 deletions(-)
Modified: trunk/boost/config/compiler/clang.hpp
==============================================================================
--- trunk/boost/config/compiler/clang.hpp Fri Jun 7 15:03:49 2013 (r84678)
+++ trunk/boost/config/compiler/clang.hpp 2013-06-07 16:05:18 EDT (Fri, 07 Jun 2013) (r84679)
@@ -26,6 +26,14 @@
#define BOOST_HAS_NRVO
+// Branch prediction hints
+#if defined(__has_builtin)
+#if __has_builtin(__builtin_expect)
+#define BOOST_LIKELY(x) __builtin_expect(x, 1)
+#define BOOST_UNLIKELY(x) __builtin_expect(x, 0)
+#endif
+#endif
+
// Clang supports "long long" in all compilation modes.
#define BOOST_HAS_LONG_LONG
Modified: trunk/boost/config/compiler/gcc.hpp
==============================================================================
--- trunk/boost/config/compiler/gcc.hpp Fri Jun 7 15:03:49 2013 (r84678)
+++ trunk/boost/config/compiler/gcc.hpp 2013-06-07 16:05:18 EDT (Fri, 07 Jun 2013) (r84679)
@@ -118,6 +118,10 @@
#define BOOST_HAS_NRVO
#endif
+// Branch prediction hints
+#define BOOST_LIKELY(x) __builtin_expect(x, 1)
+#define BOOST_UNLIKELY(x) __builtin_expect(x, 0)
+
//
// Dynamic shared object (DSO) and dynamic-link library (DLL) support
//
@@ -135,7 +139,7 @@
# endif
# define BOOST_SYMBOL_VISIBLE __attribute__((visibility("default")))
#else
-// config/platform/win32.hpp will define BOOST_SYMBOL_EXPORT, etc., unless already defined
+// config/platform/win32.hpp will define BOOST_SYMBOL_EXPORT, etc., unless already defined
# define BOOST_SYMBOL_EXPORT
#endif
@@ -158,7 +162,7 @@
//
// We disable this if the compiler is really nvcc as it
// doesn't actually support __int128 as of CUDA_VERSION=5000
-// even though it defines __SIZEOF_INT128__.
+// even though it defines __SIZEOF_INT128__.
// See https://svn.boost.org/trac/boost/ticket/8048
// Only re-enable this for nvcc if you're absolutely sure
// of the circumstances under which it's supported:
Modified: trunk/boost/config/compiler/intel.hpp
==============================================================================
--- trunk/boost/config/compiler/intel.hpp Fri Jun 7 15:03:49 2013 (r84678)
+++ trunk/boost/config/compiler/intel.hpp 2013-06-07 16:05:18 EDT (Fri, 07 Jun 2013) (r84679)
@@ -154,6 +154,14 @@
# define BOOST_HAS_NRVO
#endif
+// Branch prediction hints
+// I'm not sure 8.0 was the first version to support these builtins,
+// update the condition if the version is not accurate. (Andrey Semashev)
+#if defined(__GNUC__) && BOOST_INTEL_CXX_VERSION >= 800
+#define BOOST_LIKELY(x) __builtin_expect(x, 1)
+#define BOOST_UNLIKELY(x) __builtin_expect(x, 0)
+#endif
+
//
// versions check:
// we don't support Intel prior to version 5.0:
Modified: trunk/boost/config/suffix.hpp
==============================================================================
--- trunk/boost/config/suffix.hpp Fri Jun 7 15:03:49 2013 (r84678)
+++ trunk/boost/config/suffix.hpp 2013-06-07 16:05:18 EDT (Fri, 07 Jun 2013) (r84679)
@@ -632,7 +632,7 @@
// Set some default values GPU support
//
# ifndef BOOST_GPU_ENABLED
-# define BOOST_GPU_ENABLED
+# define BOOST_GPU_ENABLED
# endif
// BOOST_FORCEINLINE ---------------------------------------------//
@@ -648,6 +648,34 @@
# endif
#endif
+// BOOST_NOINLINE ---------------------------------------------//
+// Macro to use in place of 'inline' to prevent a function to be inlined
+#if !defined(BOOST_NOINLINE)
+# if defined(_MSC_VER)
+# define BOOST_NOINLINE __declspec(noinline)
+# elif defined(__GNUC__) && __GNUC__ > 3
+ // Clang also defines __GNUC__ (as 4)
+# define BOOST_NOINLINE __attribute__ ((__noinline__))
+# else
+# define BOOST_NOINLINE
+# endif
+#endif
+
+// Branch prediction hints
+// These macros are intended to wrap conditional expressions that yield true or false
+//
+// if (BOOST_LIKELY(var == 10))
+// {
+// // the most probable code here
+// }
+//
+#if !defined(BOOST_LIKELY)
+# define BOOST_LIKELY(x) x
+#endif
+#if !defined(BOOST_UNLIKELY)
+# define BOOST_UNLIKELY(x) x
+#endif
+
//
// Set BOOST_NO_DECLTYPE_N3276 when BOOST_NO_DECLTYPE is defined
//
Modified: trunk/libs/config/doc/macro_reference.qbk
==============================================================================
--- trunk/libs/config/doc/macro_reference.qbk Fri Jun 7 15:03:49 2013 (r84678)
+++ trunk/libs/config/doc/macro_reference.qbk 2013-06-07 16:05:18 EDT (Fri, 07 Jun 2013) (r84679)
@@ -1003,6 +1003,34 @@
Consider defining it to `inline` before including the Boost.Config header in order to be
able to debug errors more easily.
]]
+[[`BOOST_NOINLINE`][
+This macro can be used in place of the `inline` keyword to instruct the compiler
+that a function should never be inlined. One should typically use this macro
+to mark functions that are unlikely to be called, such as error handling routines.
+
+Usage example:
+``
+ BOOST_NOINLINE void handle_error(const char* descr)
+ {
+ // ...
+ }
+``
+]]
+[[`BOOST_LIKELY(X)`
+ `BOOST_UNLIKELY(X)`][
+These macros communicate to the compiler that the conditional expression `X` is likely
+or unlikely to yield a positive result. The expression should result in a boolean value.
+The result of the macro is an integer or boolean value equivalent to the result of `X`.
+
+The macros are intended to be used in branching statements. The additional hint they provide
+can be used by the compiler to arrange the compiled code of the branches more effectively.
+
+Usage example:
+``
+ if (BOOST_UNLIKELY(ptr == NULL))
+ handle_error("ptr is NULL");
+``
+]]
]
[endsect]
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk