avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] [Bug] Initialization for _delay_loop_2 OptimizedOut


From: Dave Hansen
Subject: Re: [avr-gcc-list] [Bug] Initialization for _delay_loop_2 OptimizedOut
Date: Thu, 24 Jul 2003 16:15:21 -0400

Sorry Joerg, for the multiple copies: I sent the first directly to you accidently.

As "Dave Hansen" <address@hidden> wrote:

>Notice the brne and the rjmp target the same location.  So it doesn't
>work for me.  What version are you using?

I've tested it with both of the following, using various -mmcu=avrN and
-Ox options:

% avr-gcc -v
Reading specs from /usr/local/lib/gcc-lib/avr/3.3/specs
Configured with: ./configure --target=avr --prefix=/usr/local i386-portbld-freebsd4.8
Thread model: single
gcc version 3.3 20030511 (prerelease)

% avr-gcc -v
Reading specs from /usr/local/lib/gcc-lib/avr/3.3.1/specs
Configured with: ./configure --target=avr --prefix=/usr/local i386-portbld-freebsd5.0
Thread model: single
gcc version 3.3.1 20030707 (prerelease)

Both newer than mine, I guess:

C:\Dave>avr-gcc -v
Reading specs from C:\WINAVR\BIN\..\lib\gcc-lib\avr\3.3\specs
Configured with: ../configure --prefix=/e/avrdev/install --target=avr --enable-l
anguages=c,c++ --disable-nls
Thread model: single
gcc version 3.3 20030421 (prerelease)

Perhaps it's been fixed already? Just for completeness, my command line follows:

avr-gcc -c -mmcu=atmega32 -D OSC_FREQ=12000000 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=delaytst.lst delaytst.c -o delaytst.o 2> delaytst.err

No, I don't type all that in, it's done in a makefile. ;-) I hope I transcribed it correctly...

FWIW, my "workaround" didn't fix my problem either. The problem actually showed up in a much more complex routine, and the result of my workaround was the same as the library code: the value of an uninitialized register (r16) was copied (movw) into r30, and r30 was decremented (sbiw) loop. I did finally get it to work by changing my_delay_loop as shown below:

  static inline void
  my_delay_loop(unsigned int count)
  {
      if (count)
      {
          asm volatile (
              "1: sbiw %0,1" "\n\t"
              "brne 1b"
              : //"=w" (count)
              : "w" (count)
          );
      }
  }

Note that the output list is commented out (so it is now empty), and the constraint string on the input list has been changed from "0" to "w". I also changed the name of the parameter, because as you pointed out, it's the right thing to do, and this is production code. Plus I find the leading underscores ugly.

The generated code is identical to that you posted earlier (ldi r24,3; ldi r25,0; 1: sbiw r24,1; brne 1b).

Regards,
  -=Dave

_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail



reply via email to

[Prev in Thread] Current Thread [Next in Thread]