On Mon, 29 Jul 2013, Andrew MacLeod wrote:
I planned to do the work in gimplification... let the atomic decls through,
and during gimplification, loads or stores of an atomic decl would be
converted to the appropriate load or store builtin, and at the same time
recognize the 'decl = decl op value' expression and replace those as
appropriate with atomic_op_fetch operations. I had discussed this at some
length with Lawrence crowl and Jeffrey Yasskin some time ago.. At
gimplification time we no longer know whether the original form was
decl op= val or decl = decl op val;, but the decision was that it is ok to
recognize decl = decl op val and make that atomic.. it would still satisfy the
language requirements..
I think that's probably OK (though, is this a theorem of the formal
modelling work that has been done on the memory model?), but note it's not
just a decl but an arbitrary pointer dereference (the address of the
lvalue is only evaluated once, no matter how many compare-and-exchange
operations are needed), and the operation may end up looking like
*ptr = (convert to type of *ptr) ((promote) *ptr op (promote) val)
rather than a simple decl = decl op val. Or something more complicated if
the operation involves complex numbers - look at what gets for mixed real
/ complex arithmetic, for example. Given
_Atomic _Complex float f;
double d;
f += d;
the atomicity is for the whole complex number (and so the
compare-and-exchange needs to work on the whole number) although only the
real part is modified by the addition.