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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
555 次查看
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?

标记 (2)
0 项奖励
1 解答
518 次查看
hilverlee
Contributor II

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

在原帖中查看解决方案

0 项奖励
2 回复数
536 次查看
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.

 

 

519 次查看
hilverlee
Contributor II

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

0 项奖励