From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29480 invoked by alias); 3 Sep 2011 01:32:38 -0000 Received: (qmail 29471 invoked by uid 22791); 3 Sep 2011 01:32:38 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 03 Sep 2011 01:32:24 +0000 From: "NickParker at Eaton dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/50281] result registers are overwritten giving incorrect result Date: Sat, 03 Sep 2011 01:32:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: NickParker at Eaton dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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: 2011-09/txt/msg00190.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50281 --- Comment #5 from NickParker at Eaton dot com 2011-09-03 01:32:20 UTC --- Sorry. I pasted a broken version. Before. Code below works. uint32_t MulU3U3S3(uint32_t a_u4, uint32_t b_u4) { //uint32_t answer; asm volatile ( "push r0" "\n\t" "push r1" "\n\t" "push r10" "\n\t" "clr r10" "\n\t" // zero register // 0 byte shifts "mul %A1,%A2" "\n\t" // a1a2 "mov r2,r0" "\n\t" "mov r3,r1" "\n\t" // 1 byte shifts "mul %A1,%B2" "\n\t" "add r3,r0" "\n\t" "adc r4,r1" "\n\t" "adc r5,r10" "\n\t" "mul %A2,%B1" "\n\t" "add r3,r0" "\n\t" "adc r4,r1" "\n\t" "adc r5,r10" "\n\t" // 2 byte shifts "mul %A1,%C2" "\n\t" "add r4,r0" "\n\t" "adc r5,r1" "\n\t" "adc r6,r10" "\n\t" "mul %A2,%C1" "\n\t" "add r4,r0" "\n\t" "adc r5,r1" "\n\t" "adc r6,r10" "\n\t" "mul %B2,%B1" "\n\t" "add r4,r0" "\n\t" "adc r5,r1" "\n\t" "adc r6,r10" "\n\t" // 3 byte shifts "mul %B1,%C2" "\n\t" "add r5,r0" "\n\t" "adc r6,r1" "\n\t" "adc r7,r10" "\n\t" "mul %B2,%C1" "\n\t" "add r5,r0" "\n\t" "adc r6,r1" "\n\t" "adc r7,r10" "\n\t" // 4 byte shifts "mul %C2,%C1" "\n\t" "add r6,r0" "\n\t" "adc r7,r1" "\n\t" "mov %A0,r5" "\n\t" "mov %B0,r6" "\n\t" "mov %C0,r7" "\n\t" "clr %D0" "\n\t" //"adc %G0,r20" "\n\t" "pop r10" "\n\t" "pop r1" "\n\t" "pop r0" "\n\t" : "=&r" (answer) : "r" (a_u4), "r" (b_u4) : "r2","r3","r4","r5","r6","r7","r10" ); return (answer); }