[PATCH 2/5] x86: Remove catomic_* locking primitives

Uros Bizjak ubizjak@gmail.com
Mon Sep 8 13:18:58 GMT 2025


On Mon, Sep 8, 2025 at 2:57 PM Adhemerval Zanella Netto
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 08/09/25 09:38, Uros Bizjak wrote:
> > Remove obsolete catomic_* locking primitives which don't map
> > to standard compiler builtins.
> >
> > There are still a couple of places in the tree that uses them
> > (malloc/arena.c and malloc/malloc.c).
> >
> > x86 didn't define __arch_c_compare_and_exchange_bool_* primitives
> > so fallback code used __arch_c_compare_and_exchange_val_* primitives
> > instead.  This resulted in unoptimal code for
> > catomic_compare_and_exchange_bool_acq where superfluous
> > CMP was emitted after CMPXCHG, e.g. in arena_get2:
>
> The CMP is a single-thread optimization used not only on arena_get2, but on
> internal locks as well (lll_lock). It checks the TCB multiple_threads field
> to avoid using 'lock' variants if the process is not multithreaded.

Please note that I was referring to the CMP *after* CMPXCHG:

   775ca:       f0 48 0f b1 0d 75 3d    lock cmpxchg
%rcx,0x163d75(%rip)        # 1db348 <narenas>
   775d1:       16 00
   775d3:       48 39 c2                cmp    %rax,%rdx   <--- *THIS ONE*

not the CMPL that checks for multiple threads *before* CMPXCHG.

The referred CMP is simply due to x86 not declaring
catomic_compare_and_exchange_bool_acq primitive.

Uros.


More information about the Libc-alpha mailing list