Stop KDS optimising out NOP / NOPs

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Stop KDS optimising out NOP / NOPs

Jump to solution
1,632 Views
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)

Labels (1)
1 Solution
1,069 Views
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.

View solution in original post

2 Replies
1,070 Views
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.

1,069 Views
beng_
Contributor III

Thanks

0 Kudos
Reply