当前位置:网站首页>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
边栏推荐
- UCORE lab1 system software startup process experimental report
- Fundamentals of digital circuits (III) encoder and decoder
- Install and run tensorflow object detection API video object recognition system of Google open source
- Statistics 8th Edition Jia Junping Chapter 2 after class exercises and answer summary
- [pointer] use the insertion sorting method to arrange n numbers from small to large
- ucore lab6 调度器 实验报告
- 150 common interview questions for software testing in large factories. Serious thinking is very valuable for your interview
- Capitalize the title of leetcode simple question
- 自动化测试你必须要弄懂的问题,精品总结
- 数字电路基础(二)逻辑代数
猜你喜欢

Keil5-MDK的格式化代码工具及添加快捷方式

C language do while loop classic Level 2 questions

HackTheBox-Emdee five for life

China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '

Opencv recognition of face in image

The minimum number of operations to convert strings in leetcode simple problem

全网最详细的postman接口测试教程,一篇文章满足你

基于485总线的评分系统双机实验报告

安全测试入门介绍
软件测试需求分析之什么是“试纸测试”
随机推荐
“Hello IC World”
[pointer] find the value of the largest element in the two-dimensional array
Statistics 8th Edition Jia Junping Chapter 2 after class exercises and answer summary
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
{1,2,3,2,5} duplicate checking problem
Leetcode simple question: check whether two strings are almost equal
ucore lab7 同步互斥 实验报告
Keil5 MDK's formatting code tool and adding shortcuts
[oiclass] maximum formula
Detailed introduction to dynamic programming (with examples)
Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)
Fundamentals of digital circuits (III) encoder and decoder
Daily code 300 lines learning notes day 9
[oiclass] share prizes
王爽汇编语言详细学习笔记二:寄存器
Global and Chinese market of maleic acid modified rosin esters 2022-2028: Research Report on technology, participants, trends, market size and share
ByteDance ten years of experience, old bird, took more than half a year to sort out the software test interview questions
Wang Shuang's detailed notes on assembly language learning I: basic knowledge
ucore lab2 物理内存管理 实验报告
In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.