当前位置:网站首页>Brief description of compiler optimization level
Brief description of compiler optimization level
2022-07-06 15:09:00 【eric_ [email protected]】
Compile optimization , It will make the compiler try at the expense of compilation time and the ability to debug the program , To improve performance or code size ;
Reasonable optimization level , Can be in code volume 、 Executive performance 、RAM Get a balance in share !
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
1、 Optimization level description
GCC The optimization level is -O0、-O1、-O2、-O3、-Og、-Os、-Ofast
Summarized below :
| Optimization level | explain | remarks |
|---|---|---|
| -O0 | Turn off all optimizations | Code space is big , Inefficient execution -O1 The basic optimization level compiler does not spend too much compilation time , Try to generate faster 、 Smaller code |
| -O2 | O1 Upgraded version , Recommended optimization level | The compiler tries to improve code performance , Without increasing the volume and taking up too much compilation time |
| -O3 | The most dangerous optimization level | It will prolong the code compilation time , Generate larger volume 、 More memory consuming binary files , Greatly increase the probability of compilation failure and unpredictable program behavior , Do more harm than good |
| -Og | O1 On the basis of , Eliminate optimizations that affect debugging | If the final purpose is to debug the program , You can use this parameter . But this parameter alone is not enough , This parameter just tells the compiler , The compiled code should not affect debugging , But the generation of debugging information still depends on -g Parametric |
| -Os | O2 On the basis of , Further optimize code size | Eliminate optimizations that will increase the size of the final executable , If you want a smaller executable , This parameter can be selected . |
| -Ofast | Optimize to the point that destroys standard compliance ( Equivalent to -O3 -ffast-math ) | Is in -O3 On the basis of , Added some unconventional optimizations , These optimizations are made by breaking some international standards ( For example, the implementation standards of some mathematical functions ) To achieve , Therefore, this parameter is generally not recommended . |
give an example :

2、MDK Optimization level modification
Set the optimization level globally

Set the optimization level locally
Usually , As the code structure is complex , The addition of third-party components , The overall optimization level can no longer meet the actual use scenarios ;
MDK It can be applied to a single file , Or set the optimization level separately for a single group of files .

- Set the optimization level in the code
In the code , Set the optimization level separately for a function
https://www.keil.com/support/man/docs/armcc/armcc_chr1359124988971.htm
AC5 Setting method in :
#pragma push
#pragma O1
void function(void){
... // Optimized at O0
}
#pragma pop
AC6 Setting method in :
void function(void) _attribute__((optnone))
{
... // Optimized none
}
Reference resources :
https://www.cnblogs.com/armfly/p/15605027.html
版权声明
本文为[eric_ [email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131323057796.html
边栏推荐
- "If life is just like the first sight" -- risc-v
- Query method of database multi table link
- Global and Chinese markets of cobalt 2022-2028: Research Report on technology, participants, trends, market size and share
- Servlet
- CSAPP家庭作业答案7 8 9章
- Global and Chinese markets of PIM analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
- Statistics 8th Edition Jia Junping Chapter 2 after class exercises and answer summary
- Common Oracle commands
- How to learn automated testing in 2022? This article tells you
- Functions: Finding Roots of equations
猜你喜欢

Pedestrian re identification (Reid) - Overview

ucore lab5用户进程管理 实验报告

How to learn automated testing in 2022? This article tells you
软件测试面试回答技巧

Opencv recognition of face in image

Maximum nesting depth of parentheses in leetcode simple questions

王爽汇编语言详细学习笔记二:寄存器

C language do while loop classic Level 2 questions

UCORE lab7 synchronous mutual exclusion experiment report

1. Payment system
随机推荐
[200 opencv routines] 98 Statistical sorting filter
"If life is just like the first sight" -- risc-v
Stc-b learning board buzzer plays music
Don't you even look at such a detailed and comprehensive written software test question?
[pointer] counts the number of times one string appears in another string
Soft exam information system project manager_ Project set project portfolio management --- Senior Information System Project Manager of soft exam 025
Thinking about three cups of tea
软件测试需求分析之什么是“试纸测试”
Common Oracle commands
In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
Fundamentals of digital circuits (I) number system and code system
Quaternion -- basic concepts (Reprint)
Summary of thread implementation
Statistics 8th Edition Jia Junping Chapter 1 after class exercises and answers summary
Investment operation steps
[oiclass] share prizes
How to transform functional testing into automated testing?
Description of Vos storage space, bandwidth occupation and PPS requirements
Wang Shuang's detailed learning notes of assembly language II: registers
软件测试工作太忙没时间学习怎么办?