[cxx-mem-model] compare_exchange implementation

Richard Henderson rth@redhat.com
Wed Oct 19 15:35:00 GMT 2011

On 10/18/2011 03:07 PM, Jakub Jelinek wrote:
> On Tue, Oct 18, 2011 at 06:03:16PM -0400, Andrew MacLeod wrote:
>> Here's the last of the missing intrinsics.   compare_exchange is
>> slightly different than the others since it doesn't map directly to
>> an rtl pattern. Its format is :
>>   bool __atomic_compare_exchange (T* mem, T* expected, T desired,
>> bool weak, memory_order success, memory_order failure)
>> note that the expected parameter is a pointer as well.  In the case
>> where false is returned, the value of expected is updated.
> I think the __sync_* way here was much better (two intrinsics instead of
> one, one bool-ish and one returning val).  With mandating T*expected
> you force it to be addressable, probably until expansion time at which point
> it will be just forced into memory, which is highly undesirable.

In one of Andrew's previous ideas he split _ace into two separate builtins:

  T __atomic_compare_exchange (T* mem, T oldval, T newval, ...);
  bool __atomic_compare_exchange_success (T);

where the input to __ace_success *must* be the ssa_name output of _ace.
We then use magic to wire up both results to the same rtl pattern.

We can still probably do something exactly like that, but Andrew is 
concerned about getting the generic user-level interface correct.


More information about the Gcc-patches mailing list