This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug inline-asm/37562] [4.2] -funroll-loops destroys inline asm code for powerpc
- From: "pinskia at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Sep 2008 16:52:14 -0000
- Subject: [Bug inline-asm/37562] [4.2] -funroll-loops destroys inline asm code for powerpc
- References: <bug-37562-15404@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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