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

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

Re: [avr-gcc-list] Compiler optimisation and volatile variables


From: David Brown
Subject: Re: [avr-gcc-list] Compiler optimisation and volatile variables
Date: Fri, 3 Feb 2006 09:31:29 +0100


> gcc -O0
>
> (capital oh) (zero) means optimization level zero.
> Try it...btw: you really should consider using
> "volatile" for this purpose.
>
> PS - as a safety issue I always use -O zero in code
> I'll be embedding and then hand code any optimizations
> I feel are necessary.
>

While -O0 is the best answer to the O/P's question, I don't agree at all
with your second statement.  Hand coding does not increase the "safety" of
anything - rather, it is well known to decrease it (in most cases - there
are exceptions).  You are introducing several layers of extra uncertainty -
your assembly, your assumptions about compiler-assembly interfacing, and the
reliability and maintainability of mixing the two languages.

While it might be an exageration to claim that avr-gcc is bug-free, I don't
think there is any reason for suspecting that the compiler is any less
reliable when using standard optomisation levels (-O, -Os, and -O2).  You
could argue that less used optomisations are less well tested, and there are
certainly "experimental" optomisation options that should not be relied on
for production code.  But outside that, any code that works when
optomisation is off, but fails when optomisation is on, is incorrect code
and cannot be called "safe".

When you want to be secure that the code generated is correct, you should
examine the compiler's assembly output, not hand-code bits of the program.
This examination is vastly easier if at least -O is used, since the
generated code is cleaner and neater.

There are time when assembly functions, or even entire programs in assembly,
make sense and can lead to faster, smaller, and/or safer code.  But using it
instead of compiler optomisations is, IMHO, a bad idea.

mvh.,

David


>
> --- Willem Jacobus Marais <address@hidden>
> wrote:
>
> > Dear All
> >
> > Is there a compiler option that prevents the
> > compiler from removing
> > variables when it optimises the code, rather
> > declaring each variable as
> > volatile?
> >
> > I'm using avr-gcc version 3.4.5 with the
> > optimisation option -Os
> >
> > Thanks in advance
> > Regards
> > Willem Marais
> >
> >
> >
> > _______________________________________________
> > AVR-GCC-list mailing list
> > address@hidden
> >
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
>
> _______________________________________________
> AVR-GCC-list mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
>





reply via email to

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