gatomic improvements
Submitted by Allison (desrt)
Link to original bug (#667191)
Description
gatomic could be improved by the addition of a couple of operations. We are specifically missing the following:
- bit set/reset and test-and-set/reset
- unconditional swap
We don't have support for either of these through GCC intrinsics except in the swap case where we see the following documentation:
type __sync_lock_test_and_set (type *ptr, type value, ...)
This builtin, as described by Intel, is not a traditional test-and-set
operation, but rather an atomic exchange operation. It writes value into
*ptr, and returns the previous contents of *ptr.
Many targets have only minimal support for such locks, and do not support
a full exchange operation. In this case, a target may support reduced
functionality here by which the only valid value to store is the
immediate constant 1. The exact value actually stored in *ptr is
implementation defined.
We could possibly whitelist that one on architectures where we know it to function properly and where we're not concerned about the difference between acquire and full barrier semantics. I believe this to be true on x86 because the only way this could be implemented is with a xchg instruction which always has an implicit lock prefix, which gives a full barrier.