Code reordering due to optimizations

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Code reordering due to optimizations

1,836件の閲覧回数
achimd
Contributor I

Does the CodeWarrior C/C++ Compiler for ColdFire (Version 6.4) reorder a sequence of a volatile access and a call to the c standard library?

If we have the following c code:

     {

          volatile int i = 0;

          ...

          i = 3;

          memcpy( ... );

          ...

     }

Is it possible that the compiler is reordering the statements due to optimization?

     {

          volatile int i = 0;

          ...

          memcpy( ... );

          i = 3;

          ...

     }

 

Is there a recommended way to generate a compiler or memory barrier with the CodeWarrior C/C++ Compiler for ColdFire?

ラベル(1)
0 件の賞賛
返信
3 返答(返信)

1,610件の閲覧回数
Carlos_Mendoza
NXP Employee
NXP Employee

Hi Achim,

Could you tell us which ColdFire MCU are you using?

CodeWarrior for ColdFire 6.4 is an old version, have you tested if the same happens in CodeWarrior 7.2 which is the newest classic version or in CodeWarrior 10.6 which is the newest Eclipse version? here are the links to download these IDEs:

CodeWarrior Development Tools for ColdFire|NXP

CodeWarrior for Microcontrollers-Eclipse IDE|NXP

Hope it helps!

Best Regards,

Carlos Mendoza

Technical Support Engineer

0 件の賞賛
返信

1,610件の閲覧回数
achimd
Contributor I

Hi Carlos,

we use the ColdFire MCF5484.

The reordering is not taking place at the moment. I'm asking the question because the c standard does not forbid the reordering, it is up to the compiler. I need to know wether it is possible that the CodeWarrior C/C++ Compiler for ColdFire (Version 6.4) reorders in such a way.

It's not possible for us to switch to a newer version. If this reordering can actually appear we need to prevent it at critical section in our code. This is why i asked for a recommended way to generate a compiler or memory barrier.

Best Regards,

Achim Daub

0 件の賞賛
返信

1,610件の閲覧回数
Carlos_Mendoza
NXP Employee
NXP Employee

Hi Achim,

Yes, it might be possible that the compiler will re-order the code if using optimizations. This is because the compiler analyzes a function’s flow of execution and how the function uses variables and then uses this information to find shortcuts in execution and reduce the number of registers and memory that the function uses.

You could use the following optimization pragma to disable the optimizations on a section of code:

#pragma optimization_level 0

You can find more information about this on the document "CodeWarrior Development Studio ColdFire® Architectures Edition Build Tools Reference" located on the path C:\Program Files\Freescale\CodeWarrior for ColdFire V6.4\Help\PDF

Hope it helps!

Best Regards,

Carlos Mendoza

Technical Support Engineer

0 件の賞賛
返信