[Bug libstdc++/88101] Implement P0528R3, C++20 cmpxchg and padding bits

andysem at mail dot ru gcc-bugzilla@gcc.gnu.org
Fri Dec 6 10:25:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88101

andysem at mail dot ru changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andysem at mail dot ru

--- Comment #1 from andysem at mail dot ru ---
I'd like to draw attention to the case of 80-bit long double on x86. When I
added support for it in Boost.Atomic I noticed that it would usually be passed
in an xmm register, where the lower 10 bytes contained value and the upper 6
contained undefined padding. Given that gcc stores and loads the full xmm
register, this means that clearing the storage prior to storing the value is
not enough (the random padding will be stored in the storage and break
cmpxchg16b). In Boost.Atomic I had to clear the padding after storing the
value, and this code is brittle because I have to know when long double value
is 10 bytes (note that sizeof(long double) returns 16 on x86-64 and 12 on
x86-32).

I don't know if anything was done about it in recent gcc versions. Maybe the
compiler could provide an intrinsic to clear any possible padding bits of a
type? That would be useful not only for long double, but for structs with
padding bits, because it allows to use memcpy to copy the value (which is
arguably more efficient) and only clear padding when accepting the value from
the user.


More information about the Gcc-bugs mailing list