[cfe-dev] [libcxx] atomic header and low-level intrinsics

Howard Hinnant hhinnant at apple.com
Sun Mar 25 15:47:52 PDT 2012


On Mar 25, 2012, at 6:32 PM, David Chisnall wrote:

> Hi Al,
> 
> 
> On 25 Mar 2012, at 22:42, Al Grant wrote:
> 
>> These are similar to but incompatible with the new GCC atomic intrinsics:
>> 
>> http://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
>> 
>> which include
>> 
>> type __atomic_load_n (type *ptr, int memmodel);
>> void __atomic_load (type *ptr, type *ret, int memmodel);
>> 
>> Is there any reason not to move libcxx <atomic> to use these GCC intrinsics,
>> and have clang implement them?
> 
> Clang already implements the intrinsics.  I have a patch adding the remaining codegen parts that should be going in this week.  With this applied, most of the libc++ atomics tests now pass for me.

That's great news, thanks David.

> 
>> Also, I noticed a couple of minor issues with libcxx <atomic> and its tests:
>> 
>> The pointer operations e.g.
>> 
>>   _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
>>       {return __atomic_fetch_add(&this->__a_, __op, __m);}
>> 
>> don't seem to match the defined intrinsics:
>> 
>> void* __atomic_fetch_add(void** atomic_obj, ptrdiff_t operand, int mem_ord);
>> 
>> Either the low-level intrinsics need to be polymorphic, or <atomic> needs
>> some casts and also needs to scale the ptrdiff_t value.
> 
> The intrinsics are polymorphic.
> 
>> Finally, various libcxx atomic tests attempt to instantiate atomic<> on a
>> struct A which is not trivially-copyable and hence not valid (29.5#1 in N3290).
>> Is libcxx intending its <atomic> to support such types on all platforms?
> 
> This is a bug in the test.  Howard said he'd fix it a couple of months ago when I raised this issue, but as I've only just got around to finishing the remainder of the bits of atomics support that libc++ needs, it probably hasn't been a high priority for him yet.

I accidentally dropped it, and yes, had other priorities.  Thank you both for the reminder.

I'm excited about getting clang/libc++ atomics finished.  Just last week I lamented about not being able to use optimal atomics in libc++abi (http://libcxxabi.llvm.org/) for the get/set handler functions.  And that has certainly rekindled my interest in C++11 atomics! :-)

Howard




More information about the cfe-dev mailing list