You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
P0528R3 Atomic Compare-And-Exchange With Padding Bits
P1123R0 Atomic Compare-And-Exchange With Padding Bits For atomic_ref
__builtin_zero_non_value_bits non-atomically zeros non-value bits in types such as
structX
{
int a;
char b;
// 3 bytes padding for 32-bit int
};
or
structY
{
int a: 7;
// 25 bits of padding for 32-bit int
};
For std::atomic it can be used in constructor and in store and exchange.
So compare_exchange_* would be able to use bitwise comparison, as non-value bits are always zeros
For std::atomic_ref non-atomically zeroing in constructor is apparently not an option due to possible concurrent atomic_ref instances.
Still, __builtin_zero_non_value_bits can be used.
For lock-free atomics, compute the mask as follows:
Extended Description
MSVC implements __builtin_zero_non_value_bits intrinsic.
This is needed to implement C++2a features:
__builtin_zero_non_value_bits non-atomically zeros non-value bits in types such as
or
For std::atomic it can be used in constructor and in store and exchange.
So compare_exchange_* would be able to use bitwise comparison, as non-value bits are always zeros
For std::atomic_ref non-atomically zeroing in constructor is apparently not an option due to possible concurrent atomic_ref instances.
Still, __builtin_zero_non_value_bits can be used.
For lock-free atomics, compute the mask as follows:
Then implement compare_exchange as follows:
For lock-based atomic_ref just apply
__builtin_zero_non_value_bits
both to target (under the lock) and comparand (possibly not under the lock)std::atomic_ref
method can also be used for std::atomic too for unification.Note that:
__builtin_zero_non_value_bits
should also work in compile time in constexpr constructorThe text was updated successfully, but these errors were encountered: