[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Tip: handling volatile operands
From: |
David Kelly |
Subject: |
Re: [avr-gcc-list] Tip: handling volatile operands |
Date: |
Thu, 10 Jan 2008 13:43:43 -0600 |
User-agent: |
Mutt/1.4.2.3i |
On Thu, Jan 10, 2008 at 02:24:46PM -0500, address@hidden wrote:
> I have come across a few instances where very inefficient c code is
> created by volatile operands - often accidentally and thru no fault of
> the compiler(s)
...
> For example:
>
> while (ioport != 0)
> {
>
> }
...
> If ioport were a "normal" variable, there would be one read and one
> test!
>
> So, if you don't want the absolute latest value of a volatile, use a
> temporary!
>
> unsigned char a = ioport;
>
> if ((a& 1) || (a& 2) || (a& 0x0c))
> {
> }
>
> Will produce much better code!
You changed horses in the middle of the stream. Replace "if" above with
"while" that you started with and your non-volatile may loop forever
based on one read.
The solution is to roll your conditions into one test:
while( ioport & ( 1 | 2 | 0x0c ) )
{
}
--
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.
- Re: [avr-gcc-list] GCC-AVR Register optimisations, (continued)
RE: [avr-gcc-list] GCC-AVR Register optimisations, Weddington, Eric, 2008/01/10
[avr-gcc-list] Tip: handling volatile operands, andrewhutchinson, 2008/01/10
Re: [avr-gcc-list] Tip: handling volatile operands,
David Kelly <=
Re: [avr-gcc-list] Tip: handling volatile operands, Andrew Hutchinson, 2008/01/10
RE: [avr-gcc-list] Tip: handling volatile operands, Dave Hansen, 2008/01/11
Re: [avr-gcc-list] Tip: handling volatile operands, Dave N6NZ, 2008/01/11
Re: [avr-gcc-list] Tip: handling volatile operands, Paulo Marques, 2008/01/11
RE: [avr-gcc-list] GCC-AVR Register optimisations, John Regehr, 2008/01/10
AVR Benchmark Test Suite [was: RE: [avr-gcc-list] GCC-AVR Register optimisations], Weddington, Eric, 2008/01/11
Re: AVR Benchmark Test Suite [was: RE: [avr-gcc-list] GCC-AVR Register optimisations], John Regehr, 2008/01/13
RE: AVR Benchmark Test Suite [was: RE: [avr-gcc-list] GCC-AVR Registeroptimisations], Weddington, Eric, 2008/01/13
RE: AVR Benchmark Test Suite [was: RE: [avr-gcc-list] GCC-AVR Registeroptimisations], John Regehr, 2008/01/14
RE: AVR Benchmark Test Suite [was: RE: [avr-gcc-list] GCC-AVRRegisteroptimisations], Weddington, Eric, 2008/01/14