This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[cxx-mem-model] compare_exchange implementation



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.

Instead of providing a complex rtl pattern to try to match this, instead all that is required is to provide a compare_and_swap routine, which this builtin will then add some wrapper code around to match the required functionality.

there are 2 rtl patterns it looks for,
  atomic_compare_and_swap_weak and
  atomic_compare_and_swap_strong

both are of the form

QImode atomicCAS (mem(O), current_val(O), expected(I), desired(I), memorymodel(const int))

When neither of these patterns are present, the implementation defaults to using __sync_val_compare_and_swap to provide the implementation.

New tests have been added as well.

Bootstraps and no new regressions on x86_64-unknown-linux-gnu

so a bit of different rtl hacking around in there for me... does everything look OK? it seems to work :-) Actual pattern implementation and debugging will happen later when we actually write custom patterns for all these rather than defaulting to the current seq-cst patterns.

Andrew

Attachment: cmpxchg2.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]