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

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

Re: [avr-gcc-list] How to (efficeiently !!!) test a bitwithinamulti-byte


From: David Brown
Subject: Re: [avr-gcc-list] How to (efficeiently !!!) test a bitwithinamulti-byte intege
Date: Fri, 4 Nov 2005 16:31:54 +0100

> From: Vincent Trouilliez <address@hidden>
>
> [...]
>
> >About the -Os flag, I noticed this morning that it managed MASSIVE code
> >size reduction ! SO far I had been using just -O (I guess that means no
> >particular optimisation ?), and the program is about 13KB in size. With
> >-Os, it's only 10KB !!!  Sadly, for some reason, when compiled with this
> >flag, my program misbehaves badly (I get massive corruption of the LCD
> >display) !! Too bad... :o(
>
> I believe it was Gerry Weinburg who once wrote that "optimization is
easy --
> if you don't have to get the right answer."
>
> I suspect, though, that some of your code might be relying on behavior
> that's not guaranteed (e.g., the value of an uninitialized variable)
rather
> than a bug in the optimizer.
>
> Regards,
>
>    -=Dave
>

The bug is almost certainly a delay loop variable that is not declared
volatile.  The delay function is probably something like:

void shortDelay(void) {
    uint8_t n = 50;
    while (n--);
}

That (might) work fine with little or no optomisation, but when optomisation
is on, it fails.  The solution is simply to make n "volatile".  Note that it
will not give you precise control of your delay - different optomisations or
different compiler versions might give slightly different code, and may or
may not inline the function.  But in a case like this it doesn't matter -
all you are looking for is a slight delay, and it doesn't matter if it is
too long.  I've done exactly this sort of thing (with "volatile", naturally)
myself for LCD routines.

mvh.,

David








reply via email to

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