From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12391 invoked by alias); 17 Sep 2008 16:53:39 -0000 Received: (qmail 12002 invoked by alias); 17 Sep 2008 16:52:14 -0000 Date: Wed, 17 Sep 2008 16:53:00 -0000 Message-ID: <20080917165214.12001.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug inline-asm/37562] [4.2] -funroll-loops destroys inline asm code for powerpc In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "pinskia at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-09/txt/msg02057.txt.bz2 ------- 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" 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