Loop optimisation

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All,

Is there a preprocessor directive to turn off optimisation during certain portions of the code?

For example, the following seems to optimise out my io line delay loop...

(excerpt from the listing)

   ...

00000162 :
 * Output Parameters: None
 * Returns:			  None
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 void icUART_ioDelay(void)
 {
 162:	08 95       	ret

00000164 :
	/* 16-bit value for delay option! */
	unsigned char idel;

	/* Allocate the time that we want to pause */
	idel = icUART_IODELAYTIME;
	
	/* pause for the specified time... */
	while(idel) idel--;
	
 }
/* End Function */

   ...

Then, there is nothing where the ioDelay should be called...

   ...
/* Capture the data on the bus */
	rt = icUART_DATAPIN;
 1de:	19 b3       	in	r17, 0x19	; 25
	
	icUART_ioDelay();
	
	/* Take the port back high again */
	Bit_Set( icUART_PORT, icUART_RDb );
 1e0:	ab 9a       	sbi	0x15, 3	; 21
   ...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use .

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, but I'd rather just inhibit optimisation if I can. us is too long really, I don't need io settling that long.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use the delay_loop2 (I think that's how it's written) in the delay.h file - each iteration is four cycles - not us or ms - so it should be perfect for your needs.

If you want to use your current routine, try adding in a volatile assembler NOP statement to force the compiler to add it. A side effect would be that each iteration of the delay loop would be one cycle longer.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I added asm("nop"); to the loop, and it now compiles as a loop with size optimisation, which is what I needed. Thanks.

It would also work if I did, volatile unsigned char idel; but, wow! That increases the code size a bit!! ;)

Brian