[lttng-dev] [PATCH 2/7] Use gcc __atomic builtis for <urcu/uatomic.h> implementation

Duncan Sands baldrick at free.fr
Wed Mar 22 04:24:35 EDT 2023


Hi Mathieu,

> Tested on godbolt.org with:
> 
> int a;
> 
> void fct(void)
> {
>      (void) __atomic_add_fetch(&a, 1, __ATOMIC_RELAXED);
>      __atomic_thread_fence(__ATOMIC_SEQ_CST);
> }
> 
> x86-64 gcc 12.2 -O2 -std=c11:
> 
> fct:
>          lock add        DWORD PTR a[rip], 1
>          lock or QWORD PTR [rsp], 0
>          ret
> a:
>          .zero   4

that's disappointing.  It's the same if both use __ATOMIC_SEQ_CST:

int a;

void fct(void)
{
     (void) __atomic_add_fetch(&a, 1, __ATOMIC_SEQ_CST);
     __atomic_thread_fence(__ATOMIC_SEQ_CST);
}

->

fct():
         lock add        DWORD PTR a[rip], 1
         lock or QWORD PTR [rsp], 0
         ret
a:
         .zero   4

on x86-64 gcc 12.2 -O2 -std=c11.  Clang also doesn't optimize the fence away.

Best wishes, Duncan.


More information about the lttng-dev mailing list