[cfe-commits] [PATCH] atomic operation builtins, part 1

Andrew MacLeod amacleod at redhat.com
Tue Oct 11 18:15:56 PDT 2011


On 10/07/2011 08:03 PM, Eli Friedman wrote:
>>
>> I believe gcc is using __sync_mem_* instead of __atomic_* for their
>> builtins, although they're using __atomic_* for the library that
>> handles maybe-not-lock-free calls:
>> http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary.  I've cc'ed Andrew
>> MacLeod who's actually deciding this, in the hope that both compilers
>> can use the same intrinsics.
> Okay, I can wait to hear back.

Actually, Im renaming the __sync_mem routines to be __atomic to match 
the external routines.  They were originally __sync_mem because they 
built on the original __sync routines, but I think we're better off long 
term with the __atomic prefix to match everything up.

I've also decided after thinking about it during the weekend (it was a 
long weekend here in canada... sorry for the delays getting back to you 
guys), to tweak and simplify the GCC intrinsic interface slightly.   
(well, thats my plan right now anyway, this week will tell the tale :-)

The intrinsics and the external library don't match up exactly, I don't 
know if thats a problem or not.    Is your intent/hope/desire to have 
GCC and llvm have the exact same intrinsics as well as call the same 
library routines?

I've updated the last section of that wiki page to explicitly lay out 
what I'm thinking:

http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary#GCC_intrinsics



>>
>> This should probably have triggered an error earlier in the frontend.
>> If that's impossible, comment why?
> We don't actually check the value of the order argument in Sema
> because it can be a variable... so an assert here would be fragile.  I
> can add a comment.

Which I find incredibly annoying.  GCC has currently taken the approach 
that
   a) if the memory_order parameter turns out not to be a compile time 
constant, and
   b) it *is* always lock free (meaning it can generate instructions 
rather than calls)
we simply inline the operation using memory_order_seq_cst rather than 
having to go through a switch to figure out which one.

Maybe that will be reverted down the road, but my current take is that 
its not something that is going to happen very often, and when it does, 
it's probably not very critical.  Its easy to revert later if it can be 
demonstrated that its worthwhile.

Andrew



More information about the cfe-commits mailing list