This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: code optimizations


>>>>> "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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]