https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111404

            Bug ID: 111404
           Summary: [AArch64] 128-bit __sync_val_compare_and_swap is not
                    atomic
           Product: gcc
           Version: 8.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wilco at gcc dot gnu.org
  Target Milestone: ---

This compiles

__int128 f(__int128 *p, __int128 *q, __int128 x)
{
  return __sync_val_compare_and_swap (p, *q, x);
}

into:

f:
        ldp     x6, x7, [x1]
        mov     x4, x0
.L3:
        ldxp    x0, x1, [x4]
        cmp     x0, x6
        ccmp    x1, x7, 0, eq
        bne     .L4
        stlxp   w5, x2, x3, [x4]
        cbnz    w5, .L3
.L4:
        dmb     ish
        ret

This means if the compare fails, we return the value loaded via LDXP. However
unless the STXP succeeds, this returned value is not single-copy atomic.

So on failure we still need to execute STLXP.

Reply via email to