Does the MCU function and performance exactly same for (-O3) and (-Os)?

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

Does the MCU function and performance exactly same for (-O3) and (-Os)?

Jump to solution
556 Views
hilverlee
Contributor II

For S32DS C Compiler/ Standard S32DS C++ Compiler - Optimization, when we change the setting from Optimize most (-O3) to Optimize size (-Os), with the same source code, does the MCU function and performance keeps exactly same? If not, what will be the difference?

Tags (2)
0 Kudos
1 Solution
519 Views
hilverlee
Contributor II

I think it is an excellent reply and perfectly answered my questions, thank you very much.

View solution in original post

0 Kudos
2 Replies
537 Views
Daniel-Aguirre
NXP TechSupport
NXP TechSupport

Hi,

The difference in optimizations are related directly to the compiler being used. We can find the following regarding your inquiry (link: Optimize Options (Using the GNU Compiler Collection (GCC))

-O3

Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the following optimization flags:

-Os

Optimize for size. -Os enables all -O2 optimizations except those that often increase code size:

Related to function, if you create a blink application, both optimizations should result in your application blinking a LED. The problem with function comes when your application becomes complex and the optimizations start harming the overall functionality of your application. This is related to the optimizations that are being done, meaning the code was written to work as one thing, but the optimization changes the overall logic (due to the changes creating a better performance, changing memory accesses and implementing optimized loops) and this new logic can happen to be not compliant with what the original idea was, hence harming functionality.

As for performance, each level will create a different kind of optimization related to loop-unrolling, memory access pipelining and so. Given that -Os is related to size and -O3 is related more optimizations, we can assume that -O3 should have a better performance than the -Os one.

Still, the optimization level is to be taken with care, given that a -Os optimized application can be running as expected, but once you up the optimization to -O3, the application can fail, due to non-compliant behavior.

Again, this is more related to the compiler itself, rather than the NXP products. We might recommend talking a look into the different optimization flags and see if any of them can be non-compliant with your application.

Please, let us know.

 

 

520 Views
hilverlee
Contributor II

I think it is an excellent reply and perfectly answered my questions, thank you very much.

0 Kudos