Code optimization problem
2005-01-24 by delta delta
Yahoo Groups archive
Index last updated: 2026-04-28 23:31 UTC
Thread
2005-01-24 by delta delta
Hello, We are using GNU C compiler and Philips LPC2294 ARM processor. We need to know how code optimization is used in GNU compiler? Can we exclude some files from optimization ? Thanks, Delta Corporation. India. Yahoo! India Matrimony: Find your life partneronline. [Non-text portions of this message have been removed]
2005-01-24 by Gus
In my case, my code doesn't work when optomization is enabled! Gus --- In lpc2000@yahoogroups.com, delta delta <deltacorporation2005@y...> wrote:
> Hello, > We are using GNU C compiler and Philips LPC2294 ARM processor. > We need to know how code optimization is used in GNU compiler? > Can we exclude some files from optimization ? > > Thanks, > Delta Corporation. > India. > > > Yahoo! India Matrimony: Find your life partneronline. > > [Non-text portions of this message have been removed]
2005-01-24 by Richard
I ran into a problem with the Keil compiler and code optimization. The default optimization level was such that lines of code that did dummy reads of registers, this is how some bits are cleared, were optimized out. Needless to say the code would not work until I lowered the optimization level and thus retained these lines of code. At least in Keil it is easy to see, when debugging, which lines are executed and which are not. Richard --- In lpc2000@yahoogroups.com, "Gus" <gus_is_working@y...> wrote:
> > In my case, my code doesn't work when optomization is enabled! > > Gus > --- In lpc2000@yahoogroups.com, delta delta > <deltacorporation2005@y...> wrote: > > Hello, > > We are using GNU C compiler and Philips LPC2294 ARM processor. > > We need to know how code optimization is used in GNU compiler? > > Can we exclude some files from optimization ? > > > > Thanks, > > Delta Corporation. > > India. > > > > > > Yahoo! India Matrimony: Find your life partneronline. > > > > [Non-text portions of this message have been removed]
2005-01-24 by Robert Adsett
At 05:09 PM 1/24/05 +0000, you wrote:
>I ran into a problem with the Keil compiler and code optimization.
>The default optimization level was such that lines of code that did
>dummy reads of registers, this is how some bits are cleared, were
>optimized out. Needless to say the code would not work until I
>lowered the optimization level and thus retained these lines of code.
> At least in Keil it is easy to see, when debugging, which lines are
>executed and which are not.
Were those registers declared with a void qualifier? If so than that is
definitely a bug.
Robert
" 'Freedom' has no meaning of itself. There are always restrictions,
be they legal, genetic, or physical. If you don't believe me, try to
chew a radio signal. "
Kelvin Throop, III2005-01-24 by Richard
Robert,
I don't follow, the registers are declared thusly:
#define SPI_SPDR (*((volatile unsigned char *) 0xE0020008))
Richard
--- In lpc2000@yahoogroups.com, Robert Adsett <subscriptions@a...> wrote:
> At 05:09 PM 1/24/05 +0000, you wrote:
>
>
> >I ran into a problem with the Keil compiler and code optimization.
> >The default optimization level was such that lines of code that did
> >dummy reads of registers, this is how some bits are cleared, were
> >optimized out. Needless to say the code would not work until I
> >lowered the optimization level and thus retained these lines of code.
> > At least in Keil it is easy to see, when debugging, which lines are
> >executed and which are not.
>
>
> Were those registers declared with a void qualifier? If so than
that is > definitely a bug. > > Robert > > " 'Freedom' has no meaning of itself. There are always restrictions, > be they legal, genetic, or physical. If you don't believe me, try to > chew a radio signal. " > > Kelvin Throop, III
2005-01-25 by Robert Adsett
At 11:55 PM 1/24/05 +0000, you wrote:
> I don't follow, the registers are declared thusly:
>
>#define SPI_SPDR (*((volatile unsigned char *) 0xE0020008))
Sigh, It would probably help if I wrote what I was thinking. I meant
volatile when I wrote void.
Given the above, then the following line
(void)SPI_SPDR;
should generate a read of the register (and discard the result) regardless
of the level of optimization. volatile tells the compiler that it must
generate an access and not optimize it out. If it does not then compiler
has a bug. You should probably write a short 2 or 3 line program to
demonstrate it and report it.
Of course optimizers are notoriously buggy so turning down the optimization
level to get correct code is not terribly unusual. I seem to recall an
instance or two where a minimum optimization was required in order to
generate correct code but that's rather less common.
Robert
" 'Freedom' has no meaning of itself. There are always restrictions,
be they legal, genetic, or physical. If you don't believe me, try to
chew a radio signal. "
Kelvin Throop, III2005-01-25 by Richard
Robert,
Can you elaborate on how this is used? Right now the statement:
dummy = U0IIR; // clear the flag
Is optimized out in my UART ISR.
Richard
-- In lpc2000@yahoogroups.com, Robert Adsett <subscriptions@a...> wrote:
> At 11:55 PM 1/24/05 +0000, you wrote:
> > I don't follow, the registers are declared thusly:
> >
> >#define SPI_SPDR (*((volatile unsigned char *) 0xE0020008))
>
>
> Sigh, It would probably help if I wrote what I was thinking. I meant
> volatile when I wrote void.
>
> Given the above, then the following line
>
> (void)SPI_SPDR;
>
> should generate a read of the register (and discard the result)
regardless
> of the level of optimization. volatile tells the compiler that it must
> generate an access and not optimize it out. If it does not then
compiler
> has a bug. You should probably write a short 2 or 3 line program to
> demonstrate it and report it.
>
> Of course optimizers are notoriously buggy so turning down the
optimization > level to get correct code is not terribly unusual. I seem to recall an > instance or two where a minimum optimization was required in order to > generate correct code but that's rather less common. > > Robert > > " 'Freedom' has no meaning of itself. There are always restrictions, > be they legal, genetic, or physical. If you don't believe me, try to > chew a radio signal. " > > Kelvin Throop, III
2005-01-25 by Uwe Arends
Richard, > dummy = U0IIR; // clear the flag > > Is optimized out in my UART ISR. even if you declare dummy as volatile? -uwe
2005-01-25 by Robert Adsett
At 05:40 PM 1/25/05 +0000, you wrote:
>Robert,
> Can you elaborate on how this is used? Right now the statement:
>
>dummy = U0IIR; // clear the flag
>
>Is optimized out in my UART ISR.
Given:
extern volatile char U0IIR;
char dummy;
where dummy is never referred to, then the lines
dummy = U0IIR;
U0IIR;
(void)U0IIR;
Should all produce similar code. The last two should produce identical
code. With low optimization the first line might produce code that
actually stores a value in dummy.
The last two lines are legal C and basically say read this value and ignore
it. The void cast on the last line tells compilers and static analysis
tools that that is what you intended to do and that it's not a typo.
At no level of optimization should the read be optimized out for any of the
above lines. The volatile qualifier should prevent that kind of optimization.
Robert
" 'Freedom' has no meaning of itself. There are always restrictions,
be they legal, genetic, or physical. If you don't believe me, try to
chew a radio signal. "
Kelvin Throop, III