|problems with "reordered code" using GNU, PPC, vxWorks email@example.com (2003-03-24)|
|Re: problems with "reordered code" using GNU, PPC, vxWorks firstname.lastname@example.org (2003-03-30)|
|Re: problems with "reordered code" using GNU, PPC, vxWorks email@example.com (2003-03-30)|
|Re: problems with "reordered code" using GNU, PPC, vxWorks firstname.lastname@example.org (Michael Meissner) (2003-03-30)|
|From:||Michael Meissner <email@example.com>|
|Date:||30 Mar 2003 00:39:33 -0500|
|Posted-Date:||30 Mar 2003 00:39:33 EST|
firstname.lastname@example.org (Wolfgang Schulze) writes:
> I´m using a PPC under vxworks, Ansi C, GNU. After compilation my code
> is reordered for optimisation. I want to have my code optimized by the
> compiler, but in some source code I need to have the exact instruction
> order as I write in my source code. ...
> [Isn't that what volatile declarations are supposed to do? -John]
In general, John is right you really should be using volatile on all
variables that need to be ordered. Otherwise, the compiler is fully
entitled to rearrange things.
On asm statements, you should use asm volatile instead of asm where
the asm statement cannot be moved out of a loop, and you should
indicate "memory" in the list of clobbered registers as per the
documentation. A usual problem that many people have is in using
multiple asm statements, one per instruction, when you should put all
of the interelated asm's together in one block, so that the compiler
won't move things between the asm statements. You obviously need to
have the right inputs and outputs so the compiler can do the
dependency checking (and not use the form of asm that has no
There are options for not rescheduling instructions, but those are a
crutch, and in general you should try to not use them.
The final method of course is to write the critical parts in
assembler, and call it from the code.
Return to the
Search the comp.compilers archives again.