On Thu, Jan 10, 2008 at 02:24:46PM -0500, [EMAIL PROTECTED] 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, [EMAIL PROTECTED]
========================================================================
Whom computers would destroy, they must first drive mad.
_______________________________________________
AVR-GCC-list mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list