public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/37562]  New: [4.2] -funroll-loops destroys inline asm code von powerpc
@ 2008-09-17 15:43 rbuergel at web dot de
  2008-09-17 15:45 ` [Bug inline-asm/37562] " rbuergel at web dot de
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: rbuergel at web dot de @ 2008-09-17 15:43 UTC (permalink / raw)
  To: gcc-bugs

typedef unsigned int UInt32;
typedef unsigned char UInt8;

struct Data
{
  UInt8 data[16];

  const UInt8* getData() const
  {
    return data + 4;
  }
};

struct Value {
  UInt32 value;
  static void update (Value& signal, const Data& source, UInt32 startBit);
};

void Value::update(Value& signal, const Data& source, UInt32 startByte)
{
  UInt32& value = signal.value;
  const UInt8* data = source.getData();
  asm( "lwbrx %0,%1,%2;\n":"=r"(value): "r"(data), "r"(startByte), "m" (*(data
+ startByte)) );
}

generated for gcc-4.2.4 on powerpc:
00000000 <_ZN5Value6updateERS_RK4Dataj>:
   0:   38 04 00 04     addi    r0,r4,4
   4:   7c 80 2c 2c     lwbrx   r4,0,r5
   8:   90 83 00 00     stw     r4,0(r3)
   c:   4e 80 00 20     blr

the correct version without -funroll-loops reads:
00000000 <_ZN5Value6updateERS_RK4Dataj>:
   0:   38 84 00 04     addi    r4,r4,4
   4:   7c 84 2c 2c     lwbrx   r4,r4,r5
   8:   90 83 00 00     stw     r4,0(r3)
   c:   4e 80 00 20     blr


lwbrx sums the contents of r4 and r5 and accesses this address, swaps it's
value and stores it again in r4. The incorrect version accesses an invalid
address, which leads to a segmentation fault.

this is corrected at least with gcc-4.3.1, there i couldn't reproduce the
behaviour.


-- 
           Summary: [4.2] -funroll-loops destroys inline asm code von
                    powerpc
           Product: gcc
           Version: 4.2.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rbuergel at web dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37562


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-09-17 19:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-17 15:43 [Bug inline-asm/37562] New: [4.2] -funroll-loops destroys inline asm code von powerpc rbuergel at web dot de
2008-09-17 15:45 ` [Bug inline-asm/37562] " rbuergel at web dot de
2008-09-17 16:52 ` [Bug inline-asm/37562] New: " Andrew Thomas Pinski
2008-09-17 16:53 ` [Bug inline-asm/37562] [4.2] -funroll-loops destroys inline asm code for powerpc pinskia at gmail dot com
2008-09-17 18:47 ` rbuergel at web dot de
2008-09-17 18:51 ` pinskia at gcc dot gnu dot org
2008-09-17 18:58 ` rbuergel at web dot de
2008-09-17 19:08 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).