Stop KDS optimising out NOP / NOPs

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Stop KDS optimising out NOP / NOPs

跳至解决方案
3,064 次查看
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 解答
2,501 次查看
bobpaddock
Senior Contributor IV

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 回复数
2,502 次查看
bobpaddock
Senior Contributor IV

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,501 次查看
beng_
Contributor III

Thanks

0 项奖励
回复