Re: Powerpc optimization change the order of operation



Arlet Ottens wrote:
dreamerg wrote:
Hi Does sombody know a way to disable optimization for part of a code?
I have a code that writes data to some HW machine. It has to do it in
acertain order. Although I use volatile to write to those adresses the
order in which the writes and read are done changes when I enable
optimization in the compiler. Is there a way to solve this without the need
to disable the optimization? I don't want to put this code in seperate
function in another file and disable the optimization only for this file.

Do you also use volatile variables to read ?

The compiler is not allowed to change the order of volatile accesses, even with optimizations enabled. If it does, it's a bug in the compiler. Did you talk to your compiler vendor ?

It is, of course, possible that the variables aren't declared properly, or that there's another error in the code. Perhaps you could post a small example of what you're trying to do ?


As well as all the above good advice, it's important to remember that "volatile" is an instruction to the compiler, not the processor. In particular, it won't affect things like caches, write buffers, and instruction re-ordering. Depending on the powerpc in question, you can get all sorts of re-ordering in the processor.

You have to make sure that your accesses are not cached, and that you use an "eieio" instruction (or equivalent, depending on the exact ppc model) to ensure that write buffers are flushed and any speculative loads are dropped between accesses.
.



Relevant Pages

  • Re: i386 nmi_watchdog: Merge check_nmi_watchdog fixes from x86_64
    ... > after the store without volatile it seems a reasonable ... > as we have taken the address earlier so at some point the compiler ... pointer away and will be referring to it later. ... or if the compiler does whole-program optimization and can see ...
    (Linux-Kernel)
  • Re: Is there a way to flush registers and tell the C compiler to refill?
    ... Because using volatile would prevent some C compilation optimization, ... is nothing to worry about (other than a broken compiler). ... Such a caching ...
    (comp.lang.c)
  • Re: Share .cpp and .h along projects
    ... optimization is a necessity for implementing mutex lock/unlock operations, ... correct compiler behavior for MT programming WRT these operations ... you use the volatile keyword for variables that are volatile. ... The mutex lock/unlock situation I've been talking about is illustrated by ...
    (microsoft.public.vc.language)
  • Re: Java outperforms C++?
    ... > overlapped it is stopping some other instruction from overlapping. ... > Which C++ compiler uses GC? ... optimization is difficult and expensive. ... Decoupling the optimization from execution allows the optimization to ...
    (microsoft.public.vc.language)
  • Re: Share .cpp and .h along projects
    ... correct compiler behavior for MT programming WRT these operations ... you use the volatile keyword for variables that are volatile. ... an opaque DLL suppresses this optimization, ... the compiler could look into the DLL, there would have to be some way to ...
    (microsoft.public.vc.language)

Loading