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

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

Re: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os


From: Alex Wenger
Subject: Re: [avr-gcc-list] Avr-gcc Produces Incorrect Code with -Os
Date: Fri, 16 May 2008 11:49:57 +0200
User-agent: Thunderbird 2.0.0.14 (Windows/20080421)

Hi,

Loveny Design schrieb:
> I wouldn't have thought the compiler was allowed to re-order statements
> *around* a volatile access. Perhaps someone can help my understanding, given
> :-
> 1: Volatile Statements<sp>
> 2: Statements<sp>
> 3: Volatile Statements<sp>
> where <sp> is a sequence point.
> 
> Line 3 has a volatile access and therefore has side-effects that the
> compiler doesn't know about, so surely it must complete all preceeding
> statements up to and including the sequence point before the volatile access
> occurs?

the problem here is that atan() is declared as const, because
it is matematicaly only a "table look up". If you make two or
more calls to atan() with the same parameter, it could be
reduced to one.
That is essential in loops:

for(uint8_t i = 0; i < 32; i++)
{
        PORTB = atan(foobar) + i * 2;
}

could be reordered to:

tmp = atan(foobar);
for(uint8_t i = 0; i < 32; i++)
{
        PORTB = tmp + i * 2;
}



Alex




reply via email to

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