2
0
mirror of https://github.com/boostorg/atomic.git synced 2026-02-02 20:32:09 +00:00
Commit Graph

184 Commits

Author SHA1 Message Date
Andrey Semashev
ceadfbcea2 Use may_alias attribute to silence gcc warnings about breaking strict aliasing.
We need to mark the uint32_t and uint64_t that are used to load parts of the
double-width values into registers.
2018-02-03 23:20:39 +03:00
Andrey Semashev
9768684841 Added specialized implementation of (op)_and_test operations on PowerPC. 2018-02-03 22:31:50 +03:00
Andrey Semashev
5a04508961 Added specialized implementation of (op)_and_test operations on ARM. 2018-02-03 22:01:13 +03:00
Andrey Semashev
701b5c863b Updated copyright. 2018-02-03 21:49:00 +03:00
Andrey Semashev
5f80667cd3 Minor optimization. 2018-02-03 21:21:19 +03:00
Andrey Semashev
90e4a3ebc0 Updated formatting. 2018-02-03 01:10:24 +03:00
Andrey Semashev
c91cb67396 Fixed incorrect code generated by clang for 32-bit x86 PIC.
The compiler, surprisingly, uses ebx for memory operands, which messed up the
save/restore logic in asm blocks, resulting the memory operand (which was
supposed to be the pointer to the atomic storage) being incorrect.

First, clang (and, apparently, recent gcc as well) are able to deal with ebx
around the asm blocks by themselves, which makes it unnecessary to save/restore
the register in the asm blocks. Therefore, for those compilers we now use the
non-PIC branch in PIC mode as well. This sidesteps the original problem with
clang.

Second, since we can't be sure if other compilers are able to pull the same
trick, the PIC branches of code have been updated to avoid any memory operand
constraints and use the explicitly calculated pointer in a register instead. We
also no longer use a scratch slot on the stack to save ebx but instead use esi
for that, which is also conveniently used for one of the inputs. This should
be slightly faster as well. The downside is that we're possibly wasting one
register for storing the pointer to the storage, but there seem to be no way
around it.
2018-02-03 00:46:07 +03:00
Andrey Semashev
13845129c4 Extended the workaround for missing support for ax:dx pairs in asm statements.
Apparently, gcc versions up to 4.6, inclusively, have problems allocating
eax:edx register pairs in asm statements for 32-bit x86 targets. Included those
compilers in the existing workaround.

Also, for clang removed the use of __sync-based workarounds for exchange()
implementation and use the asm branch with the workaround. It should produce
a more efficient code.
2018-02-02 16:19:37 +03:00
Andrey Semashev
2631ef968e Removed the code that relied on implied zero displacements in x86 asm.
Clang failed to compile such code. Given that gcc 7 also complained about
missing displacements in memory operands, this trick is no longer effective
with newer compilers.

Instead, the assembler code have been refactored to avoid having to specify
any displacements at all, offloading this work to the compiler. We hope that
the compiler will be smart enough to not overallocate registers for every
memory operand used in the inline assembler. At least, recent gcc and clang are
able to do this and generate code comparable to what was achieved previously.

Additionally, it was possible to reduce assembler code in several places by
removing mov instructions setting up input registers or handling the results.
Instead, we now rely on the compiler doing this work to satisfy assembler block
constraints.

In 32-bit load and store, improved support for targets with SSE but not SSE2.
It is possible to use SSE to do the loads/stores. Also, the scratch xmm register
is now picked by the compiler.
2018-01-30 02:55:40 +03:00
Andrey Semashev
1ec5090b33 Fixed DCAS not being lock-free on 32-bit x86 target with clang.
Clang has a bug of not advertising support for atomics implemented via
cmpxchg8b, even if the instruction is enabled in the command line. We have
to workaround the same problem with cmpxchg16b on 64-bit x86 as well, so
we apply the same approach here - we implement all atomic ops through DCAS
ourselves.

This fix adds a check for cmpxchg8b to capabilities definition.
2018-01-29 20:03:40 +03:00
Andrey Semashev
10c61bb25d Converted memory_order to scoped enum on C++11 and later.
This follows the change expected in C++2a, which has been accepted into
N4713 (proposal P0439). The old memory order constants are still
available for backward compatibility.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0439r0.html
2018-01-29 00:38:44 +03:00
Andrey Semashev
9c8bca1d01 Added a missing assert that consume is prohibited in atomic_flag::clear. 2018-01-28 23:23:08 +03:00
Andrey Semashev
04064a4427 Marked pointer (op)_and_test operations with BOOST_ATOMIC_DETAIL_HIGHLIGHT_OP_AND_TEST. 2018-01-28 23:15:06 +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
d826930e86 Added support for returning values in flags from asm blocks for gcc x86 backend. 2017-09-02 19:30:55 +03:00
Andrey Semashev
f2aae8936a Avoid passing storage types via template parameters as it generates warnings about dropping attributes in gcc 7. 2017-09-02 19:17:27 +03:00
Andrey Semashev
1972f1c96e Added support for returning values in flags from asm blocks in x86 DCAS. 2017-09-02 19:07:20 +03:00
Andrey Semashev
87a904edf4 Updated DCAS compatibility with gcc 7 on x86-64.
Gcc 7 removed support for __atomic intrinsics on 16-byte operands on x86-64 and
instead always generates library calls to libatomic, thus breaking user's code
compilation due to having to link with the library. Also, the assembler tends
to generate warnings when implicit zero displacement is used in memory operands.
2017-09-02 17:47:13 +03:00
Andrey Semashev
fbe1e8baf2 Revert "Revert "Use BOOST_MAY_ALIAS from Boost.Config.""
This reverts commit 06c36dce48.
2017-08-26 15:10:15 +03:00
Andrey Semashev
06c36dce48 Revert "Use BOOST_MAY_ALIAS from Boost.Config."
This reverts commit bbd32145ef.

This is a temporary revert until Boost.Config is merged to master.
2017-08-24 13:17:44 +03:00
Andrey Semashev
bbd32145ef Use BOOST_MAY_ALIAS from Boost.Config. 2017-07-29 16:54:52 +03:00
Andrey Semashev
6a5928759a Added extra ops for PPC. Added 8 and 16-bit ops for PPC8+.
The new implementation of 8 and 16-bit ops uses the lbarx/stbcx and
lharx/sthcx instructions available in Power8 and later architectures.
This allows to use smaller storage types, similar to those used by
compiler intrinsics.

Also added detection of 128-bit instructions lqarx/stqcx, which can
later be used to implement 128-bit ops.
2017-07-17 00:39:20 +03:00
Andrey Semashev
c4f757d6bb Added extra ops implementation for ARM on gcc. 2017-07-16 18:15:18 +03:00
Andrey Semashev
a41cdf093e Extracted common hardware capabilities macros to separate headers.
Also refactored ARM hwcaps detection a bit and fixed compilation for
generic ARMv7, which does not provide 64-bit ldrexd/strexd.
2017-07-14 22:43:19 +03:00
Andrey Semashev
b2c6d37a1a Added byte/word-wide implementations of atomic ops on ARM.
Use ldrexb/w and strexb/w on ARMv7 and later to implement byte/word-wide
atomic ops. On the older ARM versions we still have to use 32-bit
widening implementation.

Also allowed immediate constants in some of the operations to improve
generated code.

Common ARM code extracted to a separate header to reuse with extra ops.
2017-07-14 19:25:01 +03:00
Andrey Semashev
ffb529c4c3 Silence MSVC warnings. 2017-07-11 23:00:52 +03:00
Andrey Semashev
4f38bb4f85 Added opaque variants of negate and complement ops for MSVC. 2017-07-11 23:00:52 +03:00
Andrey Semashev
538b411c4a Added MSVC backend for extra operations. 2017-07-11 23:00:52 +03:00
Andrey Semashev
d375cf0dff Modified 8 and 16-bit CAS loops to employ register renaming. 2017-07-11 23:00:52 +03:00
Andrey Semashev
e30c54754b Replaced fixed temporary register in CAS loops with a temporary variable
This allows for more flexibility in register allocation and potentially
more efficient code. Also, the temporary register was not exactly
customizable in the previous code, so it should have been cleaned up
anyway.
2017-07-11 23:00:52 +03:00
Andrey Semashev
537656d67d Reworked extra operations definition.
In order to support more flexible definition of the extra operations for
different platforms, define extra_operations as an addon to the existing
operations template. The extra_operations template will be used only by
the non-standard operations added by Boost.Atomic.
2017-07-11 23:00:52 +03:00
Andrey Semashev
6d7c0ec2ee Added generic implementation of extended ops. Reorganized platform macros. 2017-07-11 23:00:52 +03:00
Andrey Semashev
17ebc37de8 Fixed incorrect asm constraints. Also optimized 64-bit asm to allow 32-bit immediates. 2017-07-11 23:00:52 +03:00
Andrey Semashev
ce42659b6d Fixed compilation issues and incorrect use of cmpxchg. Added extended ops to the interface. 2017-07-11 23:00:52 +03:00
Andrey Semashev
42024329d7 Corrected constant constraints for bit test ops. 2017-07-11 23:00:52 +03:00
Andrey Semashev
5c554ee284 Preliminary version of extended atomic ops for x86. 2017-07-11 23:00:52 +03:00
Andrey Semashev
a6b01a8429 Disable cast-based implementation for MSVC because it generates broken code sometimes. 2017-07-11 23:00:02 +03:00
Andrey Semashev
b23c406f94 Converted Unicode characters in comments to ASCII. 2017-06-25 16:22:44 +03:00
Andrey Semashev
4ee227c6f2 Simplified use of __has_attribute. Also use __may_alias__ instead of may_alias. 2017-05-29 12:02:04 +03:00
Andrey Semashev
0786398120 Silence bogus gcc warnings about missing struct member initializers. 2017-05-29 11:49:27 +03:00
Andrey Semashev
be5ed8a1c5 Fixed compilation with gcc <= 4.9. Renamed BOOST_ATOMIC_DETAIL_STORAGE_MAY_ALIAS to BOOST_ATOMIC_DETAIL_STORAGE_TYPE_MAY_ALIAS as it is a more precise naming. 2017-05-27 18:11:06 +03:00
Andrey Semashev
7919698b2a Changed is_lock_free() implementation to always use is_always_lock_free.
This is to follow C++17, which says is_lock_free(), for any object of a given
atomic<> type, must return values consistent with is_always_lock_free.
2017-05-25 13:38:39 +03:00
Andrey Semashev
b7dba02b73 In addition to compiler checks for may_alias support, use __has_attribute as well. 2017-05-25 12:54:34 +03:00
Andrey Semashev
7c6917948d Use BOOST_INTEL_CXX_VERSION instead of __INTEL_COMPILER to use workarounds for compiler bugs present in Boost.Config. 2017-05-21 21:44:20 +03:00
Andrey Semashev
11967cc8e2 Mark storage type capable of aliasing other types and simplify CAS when possible
This is an attempt to improve generated code in the calling application that
involves CAS in a tight loop. The neccessity to cast between the value type and
the storage type for the `expected` argument results in inefficient code
that involves copying of the expected value and also saving the CAS result on
the stack. This has been observed at least with gcc 6.3 with a tight loop
on the user's side.

When we can ensure that the storage type can safely alias other types, and the
value type has the same size as the storage type, we can simplify CAS by
performing type punning on the `expected` reference instead of copying it back
and forth.
2017-05-21 17:50:16 +03:00
Andrey Semashev
cf3c4a2d5a Fixed a typo. 2017-04-04 15:54:53 +03:00
Andrey Semashev
f1dc715e41 Added __ARM_ARCH_8A__ to the preprocessor check for ARM. 2017-04-04 15:53:18 +03:00
Andrey Semashev
6d40529a58 Switch back to Boost.TypeTraits for integral traits because libstdc++ doesn't consider __int128 an integral type. 2017-04-03 15:11:30 +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
a67cc1b055 Corrected register usage in x86 DCAS asm blocks.
In some of the asm blocks eax was modified as a result of cmpxchg8b but that
was not reflected in the register constraints. This could cause incorrect code
being generated.
2017-01-08 18:09:12 +03:00