Stop KDS optimising out NOP / NOPs

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

Stop KDS optimising out NOP / NOPs

ソリューションへジャンプ
1,358件の閲覧回数
beng_
Contributor III

This is another newbie question (I've previously used IAR).

 

For debuggin purposes in a bit of test code I want some nops to single step through

 

If In insert multiple nops e.g.

  __NOP();
  __NOP();
  __NOP();

they seem to be optimised out. How can I stop this.

 

I've selected the following settings but they don't appear to have any effect on keeping the NOPs

Project/Properties/C/C++ Build/Tool Settings/Optimization/Optimization Level = None (-O0)

Project/Properties/C/C++ Build/Tool Settings/Debugging/Debug Level = Maximum (-g3)

ラベル(1)
1 解決策
795件の閲覧回数
bobpaddock
Senior Contributor III

Such instructions must be marked asVolatile to prevent the compiler from removing it.

Compiler sees that it has no side effects so removes it as unnecessary.

For GCC:

#define ATTR_NO_INSTRUMENT_FUNCTION __attribute__( ( no_instrument_function ) )
/*
* NOP is not necessarily a time-consuming NOP. The processor might
* remove it from the pipeline before it reaches the execution stage.
* Use in combination with the Sync Barrier Instruction to consume time.
*/
static inline ATTR_NO_INSTRUMENT_FUNCTION void nop( void )
{
__asm__ __volatile__ ("nop");
}

Then use 'nop();' in your code.

The pipeline comment depends on what part you are using.

A Sync Barrier Instruction may consume thousands of cycles.

元の投稿で解決策を見る

2 返答(返信)
796件の閲覧回数
bobpaddock
Senior Contributor III

Such instructions must be marked asVolatile to prevent the compiler from removing it.

Compiler sees that it has no side effects so removes it as unnecessary.

For GCC:

#define ATTR_NO_INSTRUMENT_FUNCTION __attribute__( ( no_instrument_function ) )
/*
* NOP is not necessarily a time-consuming NOP. The processor might
* remove it from the pipeline before it reaches the execution stage.
* Use in combination with the Sync Barrier Instruction to consume time.
*/
static inline ATTR_NO_INSTRUMENT_FUNCTION void nop( void )
{
__asm__ __volatile__ ("nop");
}

Then use 'nop();' in your code.

The pipeline comment depends on what part you are using.

A Sync Barrier Instruction may consume thousands of cycles.

795件の閲覧回数
beng_
Contributor III

Thanks

0 件の賞賛