Commit Graph

28 Commits

Author SHA1 Message Date
Andrey Semashev
b2594ecbc0 Disable all pointer arithmetic tests on UBSAN. 2019-10-13 10:34:58 +03:00
Andrey Semashev
0d8ea24351 Added a workaround for clang UBSAN failures.
Clang UBSAN considers an UB subtracting from a null pointer, which is
required for one of the tests. Disable that test when UBSAN is enabled.
2019-10-13 01:33:43 +03:00
Andrey Semashev
4c2fc16ab1 Work around signed overflow on min value negation.
This should fix UBSAN failures.
2019-10-12 21:20:33 +03:00
Andrey Semashev
b990132e85 Added casts to silence MSVC warnings about lost FP precision of constants. 2018-02-18 13:57:32 +03:00
Andrey Semashev
e081674ce9 Use FP numbers in FP tests. 2018-02-14 03:19:09 +03:00
Andrey Semashev
edef50f042 Added support for atomic floating point operations.
The support includes:

- The standard fetch_add/fetch_sub operations.
- Extra operations: (fetch_/opaque_)negate, (opaque_)add/sub.
- Extra capability macros: BOOST_ATOMIC_FLOAT/DOUBLE/LONG_DOUBLE_LOCK_FREE.

The atomic operations are currently implemented on top of the integer-based
backends and thus are mostly CAS-based. The CAS operations perform binary
comparisons, and as such have different behavior wrt. special FP values like
NaN and signed zero than normal C++.

The support for floating point types is optional and can be disabled by
defining BOOST_ATOMIC_NO_FLOATING_POINT. This can be useful if on a certain
platform parameters of the floating point types cannot be deduced from the
compiler-defined or system macros (in which case the compilation fails).

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0020r6.html
2018-02-13 03:36:35 +03:00
Andrey Semashev
92c57ac1e4 Added atomic operations that return the result of the operation.
These operations are useful for two reasons. First, they are needed by
atomic<> interface as the pre-increment/decrement and add/subtract operators
need to perform the corresponding arithmetics and return the actual result while
not exhibiting UB in case of overflow. This means that the operation must be
performed on the unsigned storage type in the backend. Second, the (op)_and_test
operations on ARM and PowerPC can be implemented in a more generic way on top of
the operations that return the result. And since we have those operations
internally, why not expose them to users.

Added tests and docs for the new operations. Also, added docs for the recently
added scoped names of the memory_order enum values.

Also, added a specialized "emulated" backend for the extra operations. This
backend makes better use of the fact that the operations are lock-protected
by avoiding any CAS-based loops.
2018-02-11 00:56:23 +03:00
Andrey Semashev
9fd085c59f Added negate_and_test and complement_and_test ops.
As the names suggest, the methods perform the corresponding operation and test
if the result is not zero.

Also, for the emulated fetch_complement, take care of integral promotion, which
could mess up the storage bits that were not part of the value on backends
where the storage is larger than the value. This could in turn break CAS on
the atomic value as it compares the whole storage.
2018-02-04 00:13:27 +03:00
Andrey Semashev
b24cea0af1 Changed the result of (op)_and_test operations to the opposite.
This makes the result of (op)_and_test more consistent with other
methods such as test_and_set and bit_test_and_set, as well as the
methods used in the C++ standard library.

This is a breaking change. The users are able to define
BOOST_ATOMIC_HIGHLIGHT_OP_AND_TEST macro to generate warnings on each
use of the changed functions. This will help users to port from Boost
1.66 to newer Boost releases.

More info at:

https://github.com/boostorg/atomic/issues/11
http://boost.2283326.n4.nabble.com/atomic-op-and-test-naming-
tc4701445.html
2018-01-28 20:50:12 +03:00
Andrey Semashev
573732ea4a Added a workaround for libstdc++ not specializing numeric_limits for __int128 in strict mode. 2017-07-29 18:13:27 +03:00
Andrey Semashev
a980d1c3ba Attempt to work around absent opereator<< for __int128 in some libstdc++ versions. 2017-07-20 23:46:54 +03:00
Andrey Semashev
c172831e5d Added a workaround for gcc on PPC not providing operator<< for __int128. 2017-07-17 01:15:04 +03:00
Andrey Semashev
5b28e12f1d Fixed tests to accommodate MSVC bugs and improved diagnostics.
Fixed incorrect calculation of the min distance limit for arithmetic tests.

Moved some of the arithmetic tests to a separate function because
otherwise MSVC-10 for x64 generated broken code (the code would use
garbage values in registers to pass arguments to
add_and_test/sub_and_test).

Added output operators and employed newer test macros that output compared
values in case of test failure.
2017-07-11 23:00:52 +03:00
Andrey Semashev
3622ce85c7 Updated test to avoid signed overflows when add_and_test/sub_and_test is
called on pointer types.
2017-07-11 23:00:52 +03:00
Andrey Semashev
65d0d557f1 Fixed a test constant, added a few more checks. 2017-07-11 23:00:52 +03:00
Andrey Semashev
158a114325 Corrected test constants. 2017-07-11 23:00:52 +03:00
Andrey Semashev
add6f5640c Added tests for the new operations. 2017-07-11 23:00:52 +03:00
Andrey Semashev
ca151bedb4 Fixed warnings about left-shifting negative signed integers. 2017-05-22 15:21:22 +03:00
Andrey Semashev
11c785768c Updated to reflect changes from P0558R1 accepted into C++17.
1. Expose value_type and difference_type (where present) to user's code.

2. Prohibit arithmetic operations on pointers to non-object types. In
   particular, arithmetic operations such as fetch_add/fetch_sub will no longer
   compile for pointers to cv void, pointers to functions and pointers to
   non-static class members.

Also, use C++11 <type_traits> when possible instead of Boost.TypeTraits to
reduce dependencies. Cleaned up value_arg_type internal type usage for more
efficient argument passing.
2017-04-01 18:29:26 +03:00
Andrey Semashev
ff91811c1a Fixes #10994. Fixed compilation with gcc 4.4 when cmpxchg16b is used. 2015-08-17 23:27:37 +03:00
Andrey Semashev
b1bb36c5b3 Only use intptr_t when available. Only test integer overflows/underflows for unsigned integers (the behavior is undefined for signed ints anyway). This should silence compiler warnings as well. 2015-08-17 22:25:19 +03:00
Andrey Semashev
7b1d722d94 Ported tests to core/lightweight_test.hpp.
Boost.Test was dropped due to instability and long-standing differences between develop and master branches. We don't use most of its features anyway.
2015-01-25 18:50:58 +03:00
Andrey Semashev
4dee330229 Added support for types with non-trivial default constructors. 2014-07-07 22:40:41 +04:00
Andrey Semashev
625c3c3a2e Compilation fixes. Added public headers for atomic_flag and atomic. 2014-04-20 17:26:42 +04:00
Andrey Semashev
55e8b16a12 Fixed compilation with gcc 4.4. Optimized code for gcc older than 4.7 and also added support for 128-bit atomic ops. Completed transition to defaulted and deleted functions.
[SVN r84801]
2013-06-16 13:40:11 +00:00
Tim Blechmann
96b44933f0 atomic: provide additive functionality for atomic<void*>
fixes #8501

[SVN r84190]
2013-05-08 04:45:38 +00:00
Tim Blechmann
764db51b6d atomic: adapt for constexpr and noexcept
Signed-off-by: Tim Blechmann <tim@klingt.org>

[SVN r82870]
2013-02-14 12:32:41 +00:00
Helge Bahmann
131b70c1fa atomic: initial import
[SVN r79348]
2012-07-08 11:21:45 +00:00