Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions doc/configuring_boost.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ use those configuration macros, such use is acceptable. The configuration
macros are documented as to their purpose, usage, and limitations which makes
them usable by both Boost library and user code.

Boost [link config_info_macros informational] or [link config_helpers helper]
macros are designed for use by Boost users as well as for our own internal use.
Note however, that the [link config_features feature test] and
[link config_defects defect test] macros were designed for internal use by
Boost libraries, not user code, so they can change at any time (though no
gratuitous changes are made to them). Boost library problems resulting from
changes to the configuration macros are caught by the Boost regression tests,
so the Boost libraries are updated to account for those changes. By contrast,
Boost library user code can be adversely affected by changes to the macros
without warning. The best way to keep abreast of changes to the macros used in
user code is to monitor the discussions on the Boost developers list.
Boost [link config_info_macros informational], [link config_helpers helper] and
[link config_optimisation_macros optimiser-hint] macros are designed for use by
Boost users as well as for our own internal use. Note however, that the
[link config_features feature test] and [link config_defects defect test] macros
were designed for internal use by Boost libraries, not user code, so they can
change at any time (though no gratuitous changes are made to them). Boost
library problems resulting from changes to the configuration macros are caught
by the Boost regression tests, so the Boost libraries are updated to account
for those changes. By contrast, Boost library user code can be adversely
affected by changes to the macros without warning. The best way to keep
abreast of changes to the macros used in user code is to monitor the
discussions on the Boost developers list.

[endsect]

Expand Down
138 changes: 138 additions & 0 deletions doc/macro_reference.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,19 @@ If `BOOST_NO_CXX11_NOEXCEPT` is not defined (i.e. C++11 compliant compilers) the
``
]
]]
[[`BOOST_NOTHROW_LITE`][
A nothrow declaration that does not require insertion of runtime correctness checks (otherwise
required by the standard).
MSVC __declspec( nothrow )
GCC __attribute(( nothrow ))
others BOOST_NOEXCEPT_OR_NOTHROW
}}
[[`BOOST_OVERRIDE`][
C++11 override
}}
[[`BOOST_FINAL`][
C++11 final/MSVC sealed
}}
[[`BOOST_MSVC_ENABLE_2012_NOV_CTP`][
For Microsoft Visual C++ 2012, enable the C++11 features supplied by the
November 2012 Community Technology Preview. These features are not automatically
Expand Down Expand Up @@ -1138,6 +1151,12 @@ the arguments is itself a macro (see 16.3.1 in C++ standard). This is normally
used to create a mangled name in combination with a predefined macro such a
\_\_LINE__.
]]

[endsect]

[#config_optimisation_macros]

[section Compiler optimisation control and hints]
[[`BOOST_FORCEINLINE`][
This macro can be used in place of the `inline` keyword to instruct the compiler
that the function should always be inlined.
Expand Down Expand Up @@ -1210,6 +1229,125 @@ Usage example:
can be used to disable compiler warnings relating to unused types or variables.]]
]

[[`BOOST_ASSUME(X)``BOOST_ASSUME_UNCHECKED(X)`][
MSVC's __assume(X)
Clang's __builtin_assume(X)
]]
[[`BOOST_UNREACHABLE(X)``BOOST_UNREACHABLE_UNCHECKED(X)`][
MSVC's __assume(X)
Clang's __builtin_assume(X)
]]
[[`BOOST_NOVTABLE`][
MSVC/Clang+ms_extensions __declspec( novtable )
]]

[[`BOOST_ATTRIBUTES( ... )`][
GCC __attribute__(( __VA_ARGS__ ))
MSVC __declspec( __VA_ARGS__ )
]]

[[`BOOST_RESTRICTED_FUNCTION_L1``BOOST_RESTRICTED_FUNCTION_L2``BOOST_RESTRICTED_FUNCTION_L3`][
(function attributes)
L1 - MSVC noalias - parameters, first level parameter indirections (read & write), no global references
L2 - GCC pure - parameters, first level parameter indirections (read only), global reads
L3 - GCC const - parameters (no indirections and global references)
https://msdn.microsoft.com/en-us/library/k649tyc7.aspx
http://stackoverflow.com/questions/2798188/pure-const-function-attributes-in-different-compilers
https://lwn.net/Articles/285332
https://pimiddy.wordpress.com/2012/04/20/pure-functions-in-cc
]]
[[`BOOST_RESTRICTED_FUNCTION_RETURN`][
(function attribute)
MSVC restrict
GCC malloc
https://msdn.microsoft.com/en-us/library/8bcxafdh.aspx
]]
[[`BOOST_HOT`][
(function attribute)
hot function - optimise for speed and/or group appropriately
}}
[[`BOOST_COLD`][
(function attribute)
cold function - optimise for size and/or group appropriately
]]
[[`BOOST_EXCEPTIONLESS`][
(function attribute)
BOOST_NOTHROW_LITE as an attribute.
]]
[[`BOOST_DOES_NOT_RETURN`][
(function attribute)
BOOST_NORETURN as an attribute.
]]
[[`BOOST_WARN_UNUSED_RESULT`][
(function attribute)
Make the compiler issue a warning if the result of a call to the decorated function is not examined.
]]

[[`BOOST_THREAD_LOCAL_POD`][
Compiler specific keyword for pre-C++11 'thread local' POD-only values/objects.
]]

[[`BOOST_OPTIMIZE_FOR_SPEED_BEGIN()`
`BOOST_OPTIMIZE_FOR_SPEED_END()`
`BOOST_OPTIMIZE_FOR_SIZE_BEGIN()`
`BOOST_OPTIMIZE_FOR_SIZE_END()`][
Mark a group of functions as hot or cold
]]

[[`BOOST_FAST_MATH_ON_BEGIN()`
`BOOST_FAST_MATH_ON_END()`
`BOOST_FAST_MATH_OFF_BEGIN()`
`BOOST_FAST_MATH_OFF_END()`][
Mark a group of functions as using relaxed ("fast") or strict
("slow") floating point semantics
]]

[[`BOOST_CC_CDECL`
`BOOST_CC_STDCALL`
`BOOST_CC_FASTCALL`
`BOOST_CC_VECTORCALL`
`BOOST_CC_STACK`
`BOOST_CC_REG`
`BOOST_CC_REG_ABI`
`BOOST_CC_PP_LIST`][
Function calling conventions
CDECL -> __cdecl
STCALL -> __stdcall
FASTCALL -> __fastcall
VECTORCALL -> __vectorcall
STACK -> stack based
REG -> register based
REG_ABI -> 'minimal' register based cc supported by all compilers and/or architectures for a given target (e.g. sseregparm is supported by GCC but not Clang or __vectorcall is supported only by MSVC12 or later and with at least SSE2 enabled), IOW a cc safe to use on ABI boundaries
PP_LIST -> a Boost.PP list of all calling conventions supported by the current compiler in the current compilation context (useful for automatic generation of template specialisations)s
]]

[[`BOOST_RESTRICTED`
`BOOST_RESTRICTED_PTR`
`BOOST_RESTRICTED_REF`
`BOOST_RESTRICTED_THIS`
][
Some compilers support the restrict keyword only on pointers (e.g MSVC prior to Visual Studio 2015) while some even support restricted this pointers (for member functions) as well as restricted references (e.g. GCC and Clang).
If BOOST_RESTRICTED is defined then the compiler supports all of the aboce (and the said macro can be used in all circumstances). BOOST_RESTRICTED_PTR, BOOST_RESTRICTED_REF and BOOST_RESTRICTED_THIS are defined in any case.
]]

[[`BOOST_HAS_MAY_ALIAS`
`BOOST_MAY_ALIAS`
`BOOST_HAS_UNION_TYPE_PUNNING_TRICK`
`BOOST_NO_STRICT_ALIASING`
][
If BOOST_HAS_MAY_ALIAS is defined, BOOST_MAY_ALIAS has a non-empty definition (i.e. the compiler provides a special attribute to mark types and/or variables as possibly aliasing other objects which it otherwise should not alias according to the standard aliasing rules).
BOOST_HAS_UNION_TYPE_PUNNING_TRICK -> compiler provides (the expected) defined semantics for type punning through a union
BOOST_NO_STRICT_ALIASING -> compiler does not use the strict aliasing rules at all (and thus allows any form of type punning)
]]

[[`BOOST_OVERRIDABLE_SYMBOL`
`BOOST_OVERRIDABLE_MEMBER_SYMBOL`
`BOOST_OVERRIDABLE_FUNCTION`
][
MSVC __declspec( selectany ) for data, __declspec( noinline ) inline for functions
GCC __attribute(( weak ))
]]

[endsect]

[#config_info_macros]
Expand Down
32 changes: 26 additions & 6 deletions include/boost/config/compiler/clang.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// (C) Copyright Douglas Gregor 2010
// (C) Copyright Domagoj Saric 2015
//
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
Expand All @@ -8,6 +9,8 @@

// Clang compiler setup.

#include "gcc_compatible.hpp"

#define BOOST_HAS_PRAGMA_ONCE

// Detecting `-fms-extension` compiler flag assuming that _MSC_VER defined when that flag is used.
Expand All @@ -20,7 +23,11 @@
// clang reports a compiler error. So the only workaround found is:

#ifndef __has_extension
#define __has_extension __has_feature
# define __has_extension __has_feature
#endif

#ifndef __has_declspec_attribute
# define __has_declspec_attribute(x) 0
#endif

#ifndef __has_attribute
Expand Down Expand Up @@ -56,14 +63,27 @@

#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)
#if __has_builtin( __builtin_assume )
# define BOOST_ASSUME_UNCHECKED( condition ) __builtin_assume( condition )
#endif

#define BOOST_OVERRIDE override
#define BOOST_FINAL final

// Requires -fms-extensions
#if __has_declspec_attribute( novtable )
#define BOOST_NOVTABLE __declspec( novtable )
#endif

#if defined( __SSE2__ ) && __has_attribute( vectorcall )
# undef BOOST_CC_REG
# define BOOST_CC_REG __attribute__(( vectorcall ))
#endif

// No support for fast-math and size<->speed optimisation macros/pragmas yet...
// http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-April/061527.html
// http://comments.gmane.org/gmane.comp.compilers.clang.devel/28958

// Clang supports "long long" in all compilation modes.
#define BOOST_HAS_LONG_LONG

Expand Down
59 changes: 55 additions & 4 deletions include/boost/config/compiler/gcc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

// GNU C++ compiler setup.

#include "gcc_compatible.hpp"

//
// Define BOOST_GCC so we know this is "real" GCC and not some pretender:
//
Expand Down Expand Up @@ -91,10 +93,6 @@
//
#define BOOST_HAS_NRVO

// 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
//
Expand Down Expand Up @@ -130,6 +128,59 @@
# endif
#endif

//
// final & override keywords
//
#if ( ( __GNUC__ * 10 ) + __GNUC_MINOR__ ) >= 47
# define BOOST_OVERRIDE override
# define BOOST_FINAL final
#endif

#ifdef __i386__
# undef BOOST_CC_REG
# define BOOST_CC_REG __attribute__(( regparm( 3 ), stdcall, sseregparm ))
#endif

#if ( ( ( __GNUC__ * 10 ) + __GNUC_MINOR__ ) >= 44 )
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41201
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52144
#define BOOST_OPTIMIZE_FOR_SPEED_BEGIN() \
_Pragma( "push" ) \
_Pragma( "GCC push_options" ) \
_Pragma( "GCC optimize ( \"O3\" )" ) \
_Pragma( "arm" )

#define BOOST_OPTIMIZE_FOR_SPEED_END() \
_Pragma( "GCC pop_options" ) \
_Pragma( "pop" )

#define BOOST_OPTIMIZE_FOR_SIZE_BEGIN() \
_Pragma( "push" ) \
_Pragma( "GCC push_options" ) \
_Pragma( "GCC optimize ( \"Os\" )" ) \
_Pragma( "thumb" )

#define BOOST_OPTIMIZE_FOR_SIZE_END BOOST_OPTIMIZE_FOR_SPEED_END


// http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-April/061527.html
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50782
#define BOOST_FAST_MATH_ON() _Pragma( "GCC optimize ( \"associative-math\" )" )
#define BOOST_FAST_MATH_OFF() _Pragma( "GCC optimize ( \"no-associative-math\" )" )

#define BOOST_FAST_MATH_ON_BEGIN() \
_Pragma( "GCC push_options" ) \
BOOST_FAST_MATH_ON()

#define BOOST_FAST_MATH_ON_END() _Pragma( "GCC pop_options" )

#define BOOST_FAST_MATH_OFF_BEGIN() \
_Pragma( "GCC push_options" ) \
BOOST_FAST_MATH_OFF()

#define BOOST_FAST_MATH_OFF_END() _Pragma( "GCC pop_options" )
#endif

//
// Recent GCC versions have __int128 when in 64-bit mode.
//
Expand Down
60 changes: 60 additions & 0 deletions include/boost/config/compiler/gcc_compatible.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
////////////////////////////////////////////////////////////////////////////////
///
/// \file gcc_compatible.hpp
/// ------------------------
///
/// Definitions shared between GCC and its 'compatibles'/'emulators' (e.g.
/// Clang)
///
/// (c) Copyright Domagoj Saric 2015 - 2016.
///
/// Use, modification and distribution are subject to the
/// Boost Software License, Version 1.0. (See accompanying file
/// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
///
/// See http://www.boost.org for most recent version.
///
////////////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------

// Branch prediction hints
#define BOOST_LIKELY( x ) __builtin_expect( x, true )
#define BOOST_UNLIKELY( x ) __builtin_expect( x, false )

#define BOOST_UNREACHABLE_UNCHECKED() __builtin_unreachable()

#define BOOST_ATTRIBUTES( ... ) __attribute__(( __VA_ARGS__ ))
#define BOOST_RESTRICTED_FUNCTION_L1
#define BOOST_RESTRICTED_FUNCTION_L2 pure
#define BOOST_RESTRICTED_FUNCTION_L3 const
#define BOOST_RESTRICTED_FUNCTION_RETURN malloc
#define BOOST_HOT hot
#define BOOST_COLD cold
#define BOOST_EXCEPTIONLESS nothrow
#define BOOST_DOES_NOT_RETURN noreturn
#define BOOST_WARN_UNUSED_RESULT warn_unused_result

#ifdef __i386__
# define BOOST_CC_CDECL __attribute__(( cdecl ))
# define BOOST_CC_FASTCALL __attribute__(( fastcall ))
# define BOOST_CC_STDCALL __attribute__(( stdcall ))
# define BOOST_CC_STACK BOOST_CC_STDCALL
# define BOOST_CC_REG_ABI __attribute__(( regparm( 3 ), stdcall ))
# define BOOST_CC_REG BOOST_CC_REG_ABI
#endif

#define BOOST_NOTHROW_LITE __attribute__(( nothrow ))

#define BOOST_THREAD_LOCAL_POD __thread

#define BOOST_RESTRICTED __restrict__

#define BOOST_MAY_ALIAS __attribute__(( may_alias ))

#define BOOST_HAS_UNION_TYPE_PUNNING_TRICK

#define BOOST_OVERRIDABLE_SYMBOL __attribute__(( weak ))
#define BOOST_OVERRIDABLE_MEMBER_SYMBOL BOOST_OVERRIDABLE_SYMBOL
#define BOOST_OVERRIDABLE_FUNCTION BOOST_OVERRIDABLE_SYMBOL

//------------------------------------------------------------------------------
Loading