This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/71162] New: powerpc64 __atomics should probably emit bne- after stdcx.


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

            Bug ID: 71162
           Summary: powerpc64 __atomics should probably emit bne- after
                    stdcx.
           Product: gcc
           Version: 6.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dhowells at redhat dot com
  Target Milestone: ---

On powerpc64, __atomic_fetch_or(), for example, emits a BNE instruction after
the STDCX. instruction to work out whether it needs to retry.  For example,
compiling this:

static __always_inline
bool iso_test_and_set_bit(long bit, volatile unsigned long *addr, int memorder)
{
        unsigned long mask = 1UL << (bit & (64 - 1));
        unsigned long old;

        addr += bit >> 6;
        old = __atomic_fetch_or(addr, mask, memorder);
        return old & mask;
}

long iso_t_a_s(long bit, volatile unsigned long *addr)
{
        return iso_test_and_set_bit(bit, addr, __ATOMIC_SEQ_CST);
}

produces this:

00000000000000e4 <.iso_t_a_s>:
  e4:   7c 00 04 ac     hwsync
  e8:   54 6a 06 be     clrlwi  r10,r3,26
  ec:   7c 63 36 74     sradi   r3,r3,6
  f0:   39 20 00 01     li      r9,1
  f4:   78 63 1f 24     rldicr  r3,r3,3,60
  f8:   7d 29 50 36     sld     r9,r9,r10
  fc:   7c 84 1a 14     add     r4,r4,r3
 100:   7c 60 20 a8     ldarx   r3,0,r4
 104:   7c 6a 4b 78     or      r10,r3,r9
 108:   7d 40 21 ad     stdcx.  r10,0,r4
 10c:   40 82 ff f4     bne     100 <.iso_t_a_s+0x1c>
 110:   4c 00 01 2c     isync
 114:   7d 29 18 38     and     r9,r9,r3
 118:   30 69 ff ff     addic   r3,r9,-1
 11c:   7c 63 49 10     subfe   r3,r3,r9
 120:   4e 80 00 20     blr

with gcc-6.1.1 targetted at powerpc64-linux-gnu and -Os.

Hopefully the need to retry is unlikely, so BNE- should probably be emitted
rather than BNE.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]