[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Volatile bad compiled while
From: |
max2009tiny |
Subject: |
Re: [avr-gcc-list] Volatile bad compiled while |
Date: |
Thu, 26 Nov 2009 06:50:00 -0800 (PST) |
OK
i can't drop register and i use on this code more register vars and all work
ok exept
while clause. That generate bad jump -4 .
My query is why not for removing register clause.
If memory store all code is +2 bytes for read and +2 any once write var and
this is over memory limit....
David Brown-4 wrote:
>
> max2009tiny wrote:
>> Hi everybody. I make project on Tiny2313 and use
>>
>> volatile register unsigned char lastrec asm("r8")
>>
>> and lastrec is modified on rs232 rx isr.
>>
>> When compile little function
>> __attribute__ ((noinline)) void waitACK(u08 cmack)
>> {
>> while(cmack!=lastrec) ; //wait for reply request
>> }
>>
>
>
> Fixing a variable to a register in this way is almost never a good idea.
> It is /possible/, because there are rare occasions when you want to do
> so, but such cases are very rare. It is also very easy to break other
> parts of your program by using register variables like this, due to
> conflicts with register usage in the library or the compiler. See
>
> <http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_regbind>
>
> (Note that explicitly recommends /not/ using r8 for this use.)
>
>
>
> On some versions of gcc, using a "volatile register" variable will give
> the warning "volatile register variables don't work as you might wish"
> if -Wall or -Wvolatile-register-var is enabled. For some reason, this
> warning does not seem to be triggered by avr-gcc while testing.
> However, the explanation from the manual remains relevant:
>
> """
> -Wvolatile-register-var
> Warn if a register variable is declared volatile. The volatile
> modifier does not inhibit all optimizations that may eliminate reads
> and/or writes to register variables. This warning is enabled by -Wall.
> """
>
>
> Here are some other comments about global volatile register variables:
>
> <http://gcc.gnu.org/ml/gcc-patches/2005-11/msg00657.html>
> <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34351>
>
>
>
> In summary, you use "register" variables for data that is absolutely
> speed-critical and used widely throughout your code, and for which
> dedicating a register makes sense (i.e., almost never). You use
> "volatile" when you specifically want to limit the compiler's
> optimisation of the variable. "volatile register" is a conflict of
> interests, and it does not work as you think it should - the compiler
> cannot treat it as both a restricted volatile and a highly-optimised
> register at the same time.
>
> Drop the "register", and your code will be fine.
>
>
>
>
>
> _______________________________________________
> AVR-GCC-list mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
>
>
--
View this message in context:
http://old.nabble.com/Volatile-bad-compiled-while-tp26513165p26530491.html
Sent from the AVR - gcc mailing list archive at Nabble.com.