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

* [Bug inline-asm/37562] [4.2] -funroll-loops destroys inline asm code von powerpc
  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 ` rbuergel at web dot de
  2008-09-17 16:52 ` [Bug inline-asm/37562] New: " Andrew Thomas Pinski
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rbuergel at web dot de @ 2008-09-17 15:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rbuergel at web dot de  2008-09-17 15:44 -------
oops, i forgot to mention my command line to compile it:
powerpc-linux-g++ -O3 -funroll-loops -c -o GetBytes2.o GetBytes2.cpp

using -O3 is important for reproducing this error


-- 


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


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

* Re: [Bug inline-asm/37562]  New: [4.2] -funroll-loops destroys inline asm code von powerpc
  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 ` 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
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Andrew Thomas Pinski @ 2008-09-17 16:52 UTC (permalink / raw)
  To: gcc-bugzilla; +Cc: gcc-bugs



Sent from my iPhone

On Sep 17, 2008, at 8:42 AM, "rbuergel at web dot de" <gcc-bugzilla@gcc.gnu.org 
 > wrote:

> 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)) );
> }

The second constraint should be using "b" instead of "r" as b says  
don't use r0.


>
>
> 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

* [Bug inline-asm/37562] [4.2] -funroll-loops destroys inline asm code for powerpc
  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 ` pinskia at gmail dot com
  2008-09-17 18:47 ` rbuergel at web dot de
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gmail dot com @ 2008-09-17 16:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gmail dot com  2008-09-17 16:52 -------
Subject: Re:   New: [4.2] -funroll-loops destroys inline asm code von powerpc



Sent from my iPhone

On Sep 17, 2008, at 8:42 AM, "rbuergel at web dot de" <gcc-bugzilla@gcc.gnu.org 
 > wrote:

> 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)) );
> }

The second constraint should be using "b" instead of "r" as b says  
don't use r0.


>
>
> 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
>


-- 


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


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

* [Bug inline-asm/37562] [4.2] -funroll-loops destroys inline asm code for powerpc
  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
                   ` (2 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rbuergel at web dot de @ 2008-09-17 18:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rbuergel at web dot de  2008-09-17 18:46 -------
> The second constraint should be using "b" instead of "r" as b says
> don't use r0.
Is this documented anywhere? The gcc manual says "r" means "any general purpose
register" and "b" means "Address base register". Any Documentation (for example
http://developer.apple.com/documentation/DeveloperTools/Reference/Assembler/PPCInstructions/chapter_6_section_2.html
) i've found, lists r0-r31 as general purpose registers.

Anyway, ignoring this point, you seem to be right. I remember 4.3.1 using r6
instead of r0, probably that's why it works. Unfortunately, i can't check your
suggestion until monday, when i'm back at work.


-- 


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


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

* [Bug inline-asm/37562] [4.2] -funroll-loops destroys inline asm code for powerpc
  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
                   ` (3 preceding siblings ...)
  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
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-09-17 18:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2008-09-17 18:50 -------
From:
http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Machine-Constraints.html#Machine-Constraints

b
Address base register

Address base register is the standard saying rN or 0 (if r0 is used).  This is
just the way PPC asm works.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug inline-asm/37562] [4.2] -funroll-loops destroys inline asm code for powerpc
  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
                   ` (4 preceding siblings ...)
  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
  6 siblings, 0 replies; 8+ messages in thread
From: rbuergel at web dot de @ 2008-09-17 18:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rbuergel at web dot de  2008-09-17 18:57 -------
Too bad for newbies to ppc asm. :)
But thank you for your explanations


-- 


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


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

* [Bug inline-asm/37562] [4.2] -funroll-loops destroys inline asm code for powerpc
  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
                   ` (5 preceding siblings ...)
  2008-09-17 18:58 ` rbuergel at web dot de
@ 2008-09-17 19:08 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-09-17 19:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pinskia at gcc dot gnu dot org  2008-09-17 19:06 -------
You can also use __builtin_bswap32 in GCC 4.3 and above which gives you the
best code generation as it understands loading from memory and if the value is
in a register already.


-- 


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).