Source code selective optimization control

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

Is there any way to temporarily disable the GCC compiler optimization for specific C code?

Only as an example, I believe this is how CodeVision would accomplish this type of task in the C source code:

#pragma optsize-
  CLKPR=0x80;
  CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

If I have to, I suppose I could write the never to be optimized GCC code as in-line assembly.

The problem is an internal AVR operation clears a bit in a 16 bit SFIOR and at the same time sets a bit or bits in a different 8 bit SFIOR. I am afraid that source code optimization (current or in the future versions) could screw up how these simultaneous SFIOR event values are read and responded to by an optimized C code IF() test. I do not want to get a false IF(SFIOR_16_bit_clear && SFIOR_8_bits_cleared) response because a SFIOR value is reused, read early or late out of sequence (using the AVR hardware behavior to define the critical sequencing). In theory even if I split up the 16 and 8 bit SFIOR tests, the optimizer could recombine them for me, so I just want to temporarily disable the optimization in the GCC source code.

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

gcc has two ways
http://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html and http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
Neither seems to be implemented in avr-gcc. A pity, as better performance could be obtained by optimizing interrupts and cpu bottlenecks for speed. With your own makefile you can set different optimize for each source file. If you don't need to do it that often, build everything with -Os, change the optimization settings and touch just the files you want to recompile, and rebuild.

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

A recent related thread:
https://www.avrfreaks.net/index.p...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Thanks for the information.

It looks like I will be lost in a maze of twisty little in-line passages that are all alike! xyzzy :lol: