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.
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Reply via email to