public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/50281] New: result registers are overwritten giving incorrect result
@ 2011-09-03  0:52 NickParker at Eaton dot com
  2011-09-03  1:07 ` [Bug inline-asm/50281] " pinskia at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: NickParker at Eaton dot com @ 2011-09-03  0:52 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50281
           Summary: result registers are overwritten giving incorrect
                    result
    Classification: Unclassified
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: NickParker@Eaton.com


Application code

bool8_t testMaths(void)
{
  uint32_t result1_u4;
  uint32_t result2_u4;
  int32_t result1_s4;
  int32_t result2_s4;
  //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  // Multiplying U3s
  //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  result1_u4 = MulU3U3S3(16777215L,100L);  // should be around 100

  PutImmediateString(ECU_COMMS,"\r\nmulu3u3s3 : [ ");
  PrintINT4(ECU_COMMS, 16777215L, 'D',0);
  PutImmediateString(ECU_COMMS," ] x [");
  PrintINT4(ECU_COMMS, 100L, 'D',0);
  PutImmediateString(ECU_COMMS," ] = [");
  PrintINT4(ECU_COMMS, result1_u4, 'D',0);
  PutImmediateString(ECU_COMMS," ]");
.
.
.
.
}


/***************************************************************************
* MulU3U3S3()
* ------------
* Function:     Multiplies two unsigned 24bit max values, 
*               then shifts left by 2^24
***************************************************************************/
uint32_t MulU3U3S3(uint32_t a_u4, uint32_t b_u4)
{
    uint32_t answer;

    asm volatile
    (

        "push r0"                   "\n\t"
        "push r1"                   "\n\t"

        "clr r20"                   "\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,r20"               "\n\t"

        "mul %A2,%B1"              "\n\t"
        "add r3,r0"                "\n\t"
        "adc r4,r1"                "\n\t"
        "adc r5,r20"               "\n\t"

        // 2 byte shifts
        "mul %A1,%C2"               "\n\t"
        "add r4,r0"                "\n\t"
        "adc r5,r1"                "\n\t"
        "adc r6,r20"               "\n\t"

        "mul %A2,%C1"               "\n\t"
        "add r4,r0"                "\n\t"
        "adc r5,r1"                "\n\t"
        "adc r6,r20"               "\n\t"

        "mul %B2,%B1"               "\n\t"
        "add r4,r0"                "\n\t"
        "adc r5,r1"                "\n\t"
        "adc r6,r20"               "\n\t"

        // 3 byte shifts
        "mul %B1,%C2"               "\n\t"
        "add r5,r0"                "\n\t"
        "adc r6,r1"                "\n\t"
        "adc r7,r20"               "\n\t"

        "mul %B2,%C1"               "\n\t"
        "add r5,r0"                "\n\t"
        "adc r6,r1"                "\n\t"
        "adc r7,r20"               "\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 r1"                    "\n\t"
        "pop r0"                    "\n\t"

    : "=&r" (answer)
    : "r" (a_u4), "r" (b_u4)
    : "r2","r3","r4","r5","r6","r7","r20"
    );

    return (answer);
}


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

end of thread, other threads:[~2011-09-04 21:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-03  0:52 [Bug c/50281] New: result registers are overwritten giving incorrect result NickParker at Eaton dot com
2011-09-03  1:07 ` [Bug inline-asm/50281] " pinskia at gcc dot gnu.org
2011-09-03  1:09 ` [Bug c/50281] " NickParker at Eaton dot com
2011-09-03  1:11 ` [Bug target/50281] " pinskia at gcc dot gnu.org
2011-09-03  1:13 ` pinskia at gcc dot gnu.org
2011-09-03  1:29 ` NickParker at Eaton dot com
2011-09-03  1:30 ` NickParker at Eaton dot com
2011-09-03  1:32 ` NickParker at Eaton dot com
2011-09-03  1:39 ` pinskia at gcc dot gnu.org
2011-09-03  4:45 ` NickParker at Eaton dot com
2011-09-03  4:47 ` NickParker at Eaton dot com
2011-09-03  8:50 ` rguenth at gcc dot gnu.org
2011-09-04 21:22 ` NickParker at Eaton dot com

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