mirror of
https://github.com/boostorg/atomic.git
synced 2026-02-02 20:32:09 +00:00
The standard says that arithmetic operations on atomic types must always produce a well-defined result in terms of two's complement arithmetic ([atomics.types.int]/7), which means integer owerflows are allowed and no trap representations are allowed. This requires that all internal arithmetics be done on unsigned integer types, even when the value type is a signed integer. The implementation now casts between signed and unsigned integers internally, performing zero or sign extension if the internal storage size is larger than the stored value. This should have roughly the same performance as before, although it mostly depends on the optimizer. The casting implementation currently relies on that the signed integer representation is two's complement on all supported platforms; other representations are not supported.