Yet another dumb question re optimization

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

Hi ,

 

Could someone enlighten me as to how to set gcc in AS7 to NOT optimize --when using the simulator.

 

Trying to see how some things work and not have them optim'd out.

 

Thanks,

 

hj

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

Change the optimization level to -O0 from the "standard??" -Og or - Os

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

I thought that your next question would be where. cheeky

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Mon. Sep 17, 2018 - 09:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I will just add that you have to stop the debugger first! then change to -O1 (don't use -O0!) and then recompile.

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

ford2go wrote:

Trying to see how some things work and not have them optim'd out.

???  If they are "optimized out", then they won't do anything whether you are optimizing or not.

 

Yes, occasionally it might be irritating or momentarily confusing with reordered code with simulator or ICE or similar.  But I usually just find a place to set a breakpoint where the interesting things are in the state I desire.

 

Have you looked at your toolchain's documentation?  E.g. https://gcc.gnu.org/onlinedocs/g...

-Og

Optimize debugging experience. -Og enables optimizations that do not interfere with debugging. It should be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.

 

 

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

While you can switch the entire build optimization it may be a bit "fierce" if this is just about watching one variable. As I explain here:

 

https://www.avrfreaks.net/forum/...

 

you can use "volatile" to selectively switch off the optimization on single variables. Note that GCC now also supports:

 

https://gcc.gnu.org/onlinedocs/g...

 

so you can do thing like:

#pragma GCC push_options
#pragma GCC optimize ("O0")
int foo(int n) {
    n = n + 1;
    return ;
}
#pragma GCC pop_options

int bar(int n) {
    n = n - 1;
    return n;
}

int main(void) {
    int m = 37;
    m = foo(bar(m));
}

Whatever the optimization setting for the rest of the program the foo() function will be build with -O0 optimization.

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

I sometimes use attributes in function declarations, they can also be used to turn off optimization of individual functions. For example, maybe the compiler is inlining a function that you want to inspect, you can prevent it:

 

int foo(int n) __attribute__(( optimize("no-inline") ));

 

edit: that is, any option from the function optimization list can be enabled/disabled individually https://gcc.gnu.org/onlinedocs/g...

You just need to use instead of "-fsomething", just "something" or "no-something".

Last Edited: Tue. Sep 18, 2018 - 08:59 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
__attribute__(( optimize("no-inline") ));

seems overly complex. Why not simply:

__attribute__(( noinline ));

"noinline" is one of GCC's function attributes:

 

https://gcc.gnu.org/onlinedocs/g...

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

Thanks to all and a special thanks to js for adding the screen shot -- that would certainly have been a question.

 

hj