public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "em at la dot mine dot nu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/16563] The compiler doesnt the necessary push/restore of  r18/r19
Date: Wed, 08 Sep 2004 13:57:00 -0000	[thread overview]
Message-ID: <20040908135730.16795.qmail@sourceware.org> (raw)
In-Reply-To: <20040715103001.16563.baphomed@lycos.de>


------- Additional Comments From em at la dot mine dot nu  2004-09-08 13:57 -------
I have found another bug which I think is related to this one:

typedef unsigned char u08;
typedef unsigned short u16;

#define PROGMEM __attribute__((__progmem__))

#define pgm_read_word(addr)                  \
({                                           \
     u16 __addr16 = (u16)(addr);             \
     u16 __result;                           \
     __asm__                                 \
     (                                       \
         "lpm %A0, Z+"   "\n\t"              \
         "lpm %B0, Z"    "\n\t"              \
         : "=r" (__result), "=z" (__addr16)  \
         : "1" (__addr16)                    \
     );                                      \
     __result;                               \
})

PROGMEM u16 crctbl[1] = { 0x0000 };

u08           crc[2];

void
crc16( u08 * bufptr, u16 len )
{
  *(u16*)crc = 0;
  for ( ; len--; bufptr++ )
//  *(u16*)crc = pgm_read_word( &crctbl[crc[1] ^ *bufptr] ) ^ ( crc[0] << 8 );
    *(u16*)crc = ( crc[0] << 8 ) ^ pgm_read_word( &crctbl[crc[1] ^ *bufptr] );
}

int
main( void )
{
  return 0;
}

Compiling the above .c generates wrong code for the following line
                                                                     
    *(u16*)crc = ( crc[0] << 8 ) ^ pgm_read_word( &crctbl[crc[1] ^ *bufptr] );

  9c:   80 91 60 00     lds     r24, 0x0060
  a0:   99 27           eor     r25, r25
  a2:   38 2f           mov     r19, r24
  a4:   22 27           eor     r18, r18
  a6:   20 91 61 00     lds     r18, 0x0061   <- r18 is lost here
  aa:   9d 91           ld      r25, X+
  ac:   29 27           eor     r18, r25
  ae:   e2 2f           mov     r30, r18
  b0:   ff 27           eor     r31, r31
  b2:   ee 0f           add     r30, r30
  b4:   ff 1f           adc     r31, r31
  b6:   ec 5a           subi    r30, 0xAC
  b8:   ff 4f           sbci    r31, 0xFF
  ba:   85 91           lpm     r24, Z+
  bc:   94 91           lpm     r25, Z
  be:   28 27           eor     r18, r24     <- uses the wrong value
  c0:   39 27           eor     r19, r25
  c2:   30 93 61 00     sts     0x0061, r19
  c6:   20 93 60 00     sts     0x0060, r18

If you change the line and reverse the XOR then the generated code is fine:
   *(u16*)crc = pgm_read_word( &crctbl[crc[1] ^ *bufptr] ) ^ ( crc[0] << 8 );

I'm using avr-gcc (GCC) 3.4.1 and the following flags to compile:

CPFLAGS = -g -O3 -funsigned-char -funsigned-bitfields -fpack-struct 
-fshort-enums -Wall -W
+strict-prototypes -Wa,-ahlms=$(<:.c=.lst) -mmcu=atmega16





-- 


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


  parent reply	other threads:[~2004-09-08 13:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-15 10:30 [Bug c/16563] New: " baphomed at lycos dot de
2004-07-15 11:57 ` [Bug target/16563] " bangerth at dealii dot org
2004-07-15 20:23 ` ericw at evcohs dot com
2004-07-15 20:41 ` j dot gnu at uriah dot heep dot sax dot de
2004-08-31 18:35 ` denisc at overta dot ru
2004-09-08 13:57 ` em at la dot mine dot nu [this message]
2004-10-06 16:48 ` berndtrog at yahoo dot com
     [not found] <bug-16563-8949@http.gcc.gnu.org/bugzilla/>
2007-02-14 16:48 ` eweddington at cso dot atmel dot com
2008-06-04 13:07 ` eric dot weddington at atmel dot com
     [not found] <bug-16563-4@http.gcc.gnu.org/bugzilla/>
2014-02-16 13:16 ` jackie.rosen at hushmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040908135730.16795.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).