This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: code optimizations
- To: tadams at extremeeng dot com
- Subject: Re: [ECOS] code optimizations
- From: Bart Veer <bartv at redhat dot com>
- Date: Thu, 23 Aug 2001 16:43:02 +0100
- Cc: ecos-discuss at sourceware dot cygnus dot com
- References: <001801c12be8$ccabe930$090110ac@TRENT>
- Reply-To: bartv at redhat dot com
>>>>> "Trenton" == Trenton D Adams <tadams@extremeeng.com> writes:
Trenton> Here's some output from my stepping through my
Trenton> pc-controller driver I'm making. Notice how the code
Trenton> jumps back and forth? This shouldn't happen should it? My
Trenton> hardware is supposed to be initialized in a specific
Trenton> order, not jump around. If this occurs during debug, it
Trenton> would occur during a normal run too, wouldn't it? I know
Trenton> we talked about this before, but this just seems really
Trenton> weird to me! I never did show anyone this before so I
Trenton> thought I would give it a try.
Trenton> How do I make the config tool allow me to specify
Trenton> different compiler options for my driver? Is it a CDL
Trenton> thing?
This is expected behaviour if you are compiling with optimisation:
the compiler is supposed to reorganise your code in any way that
improves performance, while still meeting the exact conformance
criteria described in the ISO specification. For example, given
two lines:
*(unsigned *)PMPCON |= 0x0002;
*(unsigned *)SYSCON2 |= SYSCON2_PCMCIA1;
The compiler is entirely at liberty to rearrange these instructions
if it thinks that is a good idea.
The solution here is to make proper use of the "volatile" qualifier.
The compiler is not allowed to reorder accesses to volatile memory
locations, so if you rewrite the above as:
*(volatile unsigned *)PMPCON |= 0x0002;
*(volatile unsigned *)SYSCON2 |= SYSCON2_PCMCIA1;
then the compiler cannot reorder these accesses. Typically PMPCON will
be #define'd such that it includes the type and volatile qualifier,
and then you can just go:
*PMPCON |= 0x0002;
without having to worry about casts all over the place.
Bart