Re: problems with "reordered code" using GNU, PPC, vxWorks

Michael Meissner <>
30 Mar 2003 00:39:33 -0500

          From comp.compilers

Related articles
problems with "reordered code" using GNU, PPC, vxWorks (2003-03-24)
Re: problems with "reordered code" using GNU, PPC, vxWorks (2003-03-30)
Re: problems with "reordered code" using GNU, PPC, vxWorks (2003-03-30)
Re: problems with "reordered code" using GNU, PPC, vxWorks (Michael Meissner) (2003-03-30)
| List of all articles for this month |

From: Michael Meissner <>
Newsgroups: comp.compilers
Date: 30 Mar 2003 00:39:33 -0500
Organization: Compilers Central
References: 03-03-151
Keywords: optimize
Posted-Date: 30 Mar 2003 00:39:33 EST (Wolfgang Schulze) writes:
> Im 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.
Michael Meissner

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.