On Wed, 14 Apr 2021 at 16:54, JF Bastien <cxx@jfbastien.com> wrote:
>For atomics with padding, C++20 adopted the following change (and I expect that compilers will implement it in previous versions as well): http://wg21.link/P0528

I also don't understand P0528, I'm afraid - maybe I'm missing too much C++ context.  It says:

"Because compare-and-exchange acts on an object’s value representation, padding bits that never participate in the object’s value representation are ignored.  As a consequence, the following code is guaranteed to avoid spurious failure: [ compare_exchange_strong of a struct with padding]" 

In the case where the compare_exchange_strong is done with a hardware compare-exchange instruction (which will examine padding), how would that be implemented?   By having the implementation first do another read of the object's padding to combine with the expected value to form something that can be compare-exchange'd ?

And where implemented with an LL/SC loop, by putting a padding-aware comparison inside the loop?

best,

Peter