KEIL/MDK编译优化optimization选项注意事项

article/2025/10/30 23:51:03

KEIL编译器C语言编译选项优化等级说明
在这里插入图片描述
-Onum
Specifies the level of optimization to be used when compiling source files.
Syntax
-Onum
Where num is one of the following:
0
Minimum optimization. Turns off most optimizations. When debugging is enabled, this option gives the best possible debug view because the structure of the generated code directly corresponds to the source code. All optimization that interferes with the debug view is disabled.
最小的优化。关闭大多数优化。当启用调试时,该选项将提供最佳的调试视图,因为生成的代码的结构直接对应于源代码。所有干扰调试视图的优化都被禁用。
In particular:
• Breakpoints can be set on any reachable point, including dead code.
断点可以设置在任何可达点上,包括死代码。
• The value of a variable is available everywhere within its scope, except where it is uninitialized.
变量的值在其作用域内的任何地方都是可用的,除非它是未初始化的。
• Backtrace gives the stack of open function activations that is expected from reading the source.
Note
Backtrace给出了从读取源代码中预期的打开函数激活的堆栈。
Although the debug view produced by -O0 corresponds most closely to the source code, users might prefer the debug view produced by -O1 because this improves the quality of the code without changing the fundamental structure.
尽管由-O0生成的调试视图最接近源代码,但用户可能更喜欢由-O1生成的调试视图,因为这在不改变基本结构的情况下提高了代码的质量。
Note
Dead code includes reachable code that has no effect on the result of the program, for example an assignment to a local variable that is never used. Unreachable code is specifically code that cannot be reached via any control flow path, for example code that immediately follows a return statement.
死代码包括对程序结果没有影响的可访问代码,例如对从未使用过的局部变量的赋值。无法到达的代码是指不能通过任何控制流路径到达的代码,例如紧跟在返回语句后面的代码。

1
Restricted optimization. The compiler only performs optimizations that can be described by debug information. Removes unused inline functions and unused static functions. Turns off optimizations that seriously degrade the debug view. If used with --debug, this option gives a generally satisfactory debug view with good code density.
受限制的优化。编译器只执行可以通过调试信息描述的优化。删除未使用的内联函数和未使用的静态函数。关闭会严重降低调试视图的优化。如果与 --debug 一起使用,该选项将提供一个令人满意的调试视图,具有良好的代码密度。
The differences in the debug view from –O0 are:
调试视图与-O0的区别是:
• Breakpoints cannot be set on dead code.
•不能在死代码上设置断点。
• Values of variables might not be available within their scope after they have been initialized.
•变量的值在初始化后可能在其作用域内不可用。
For example if their assigned location has been reused.
例如,如果它们指定的位置已被重用。
• Functions with no side-effects might be called out of sequence, or might be omitted if the result is not needed.
•没有副作用的函数可能会被打乱顺序调用,或者如果结果不需要,可能会被省略。
• Backtrace might not give the stack of open function activations that is expected from reading the source because of the presence of tailcalls.
•由于尾部调用的存在,Backtrace可能不会给出读源代码所期望的打开函数激活堆栈。
The optimization level –O1 produces good correspondence between source code and object code, especially when the source code contains no dead code. The generated code can be significantly smaller than the code at –O0, which can simplify analysis of the object code.
优化级别-O1在源代码和目标代码之间产生良好的对应关系,特别是当源代码不包含死代码时。生成的代码可以明显小于-O0处的代码,这可以简化目标代码的分析。

2
High optimization. If used with --debug, the debug view might be less satisfactory because the mapping of object code to source code is not always clear. The compiler might perform optimizations that cannot be described by debug information.
高优化。如果与 --debug 一起使用,调试视图可能不太令人满意,因为目标代码到源代码的映射并不总是清楚的。编译器可能执行调试信息无法描述的优化。
This is the default optimization level.
这是默认的优化级别
The differences in the debug view from –O1 are:
调试视图与-O1的区别是:
• The source code to object code mapping might be many to one, because of the possibility of multiple source code locations mapping to one point of the file, and more aggressive instruction scheduling.
•源代码到目标代码的映射可能是多对一,因为多个源代码位置映射到文件的一个点的可能性,以及更激进的指令调度。
• Instruction scheduling is allowed to cross sequence points. This can lead to mismatches between the reported value of a variable at a particular point, and the value you might expect from reading the source code.
•允许指令调度跨序列点。这可能导致在特定点报告的变量值与您从阅读源代码中可能期望的值之间的不匹配。
• The compiler automatically inlines functions.
编译器自动内联函数。

3
Maximum optimization. When debugging is enabled, this option typically gives a poor debug view. ARM recommends debugging at lower optimization levels.
最大的优化。当启用调试时,该选项通常给出一个糟糕的调试视图。ARM建议在较低的优化级别进行调试。
If you use -O3 and -Otime together, the compiler performs extra optimizations that are more aggressive, such as:
如果你同时使用-O3和-Otime,编译器会执行更激进的额外优化,例如:
• High-level scalar optimizations, including loop unrolling. This can give significant performance benefits at a small code size cost, but at the risk of a longer build time.
•高级标量优化,包括循环展开。这可以以较小的代码规模成本获得显著的性能优势,但有可能需要更长的构建时间。
• More aggressive inlining and automatic inlining.
•更积极的内联和自动内联。
These optimizations effectively rewrite the input source code, resulting in object code with the lowest correspondence to source code and the worst debug view. The --loop_optimization_level=option controls the amount of loop optimization performed at –O3 –Otime. The higher the amount of loop optimization the worse the correspondence between source and object code.
这些优化有效地重写了输入源代码,导致目标代码与源代码的对应程度最低,调试视图最差。选项 --loop_optimization_level=控制在-O3 -Otime执行的循环优化量。循环优化的数量越高,源代码和目标代码之间的对应关系就越差。
Use of the --vectorize option also lowers the correspondence between source and object code.
使用–vectorize选项还降低了源代码和目标代码之间的通信。
For extra information about the high level transformations performed on the source code at –O3 –Otime use the --remarks command-line option.
有关在-O3 -Otime对源代码执行的高级转换的额外信息,请使用–remarks命令行选项。
Note
The performance of floating-point code can be influenced by selecting an appropriate numerical model using the --fpmode option.
通过使用–fpmode选项选择合适的数值模型,可以影响浮点代码的性能。
Note
Do not rely on the implementation details of these optimizations, because they might change in future releases.
不要依赖于这些优化的实现细节,因为它们可能在未来的版本中发生更改。
Note
By default, the compiler optimizes to reduce image size at the expense of a possible increase in execution time. That is, -Ospace is the default, rather than -Otime. Note that -Ospace is not affected by the optimization level -Onum. That is, -O3 -Ospace enables more optimizations than -O2 -Ospace, but does not perform more aggressive size reduction.
默认情况下,编译器优化以减少映像大小,代价是可能增加执行时间。也就是说,-Ospace是默认值,而不是-Otime。注意-Ospace不受优化级别-Onum的影响。也就是说,-O3 -Ospace比-O2 -Ospace支持更多的优化,但不会执行更积极的大小缩减。
Default
If you do not specify -Onum, the compiler assumes -O2.
如果不指定-Onum,编译器假定为-O2。

例:在main.c文件中定义一个全局变量fortest,optimization选择-O0,编译后分析map文件时查找不到变量fortest的信息
在这里插入图片描述
将optimization选择-O3后,重新编译后,在map文件中可查找到fortest的详细信息,而不是像-O0一样无法体现出各个变量的具体信息
在这里插入图片描述


http://chatgpt.dhexx.cn/article/nRRd0BFr.shtml

相关文章

0,'\0','0'

#include <iostream> using namespace std; int main(void) { cout<<__FILE__<<\t<<__LINE__<<endl;cout<<"内 容:\t"<<"0"<<\t<<"\\\0\"<<\t<<"\0\"<<…

Odoo

狭路相逢 勇者胜 Odoo 是用于经营公司的最好的管理软件。 数百万用户使用我们的集成应用可以更好地开展工作 现在开始。免费的。 重新定义可扩展性 一个需求&#xff0c;一个应用程式。整合从来没有那么顺畅 促进销售量 客户关系管理POS销售 整合您的服务 项目工时表帮助…

0 、 '0' 、 0 、 ’\0’ 区别

转载自&#xff1a;https://blog.csdn.net/qnavy123/article/details/93901631 ① ‘0’ 代表 字符0 &#xff0c;对应ASCII码值为 0x30 (也就是十进制 48) ② ‘\0’ 代表 空字符(转义字符)【输出为空】 &#xff0c;对应ASCII码值为 0x00(也就是十进制 0)&#xff0c; …

Linux的内核编译用O0是编译不过的

最近在ATF的升级过程中遇到了一个编译问题&#xff0c;最后是通过编译优化解决的&#xff0c;然后一百度这个优化全是在Linux中的。于是就借着Linux编译优化来学学。 内容来自 宋宝华老师&#xff1a; 关于Linux编译优化几个必须掌握的姿势 1、编译选项和内核编译 首先我们都…

alert uuid does not exits. Dropping to a shell!

ALERT&#xff01;UUID does not exit. Dropping to a shell&#xff01; 服务器系统ubuntu16.04server&#xff0c;非自然断电后开机进入initramfs模式&#xff0c;服务器磁盘阵列是raid1和raid5。初步分析是硬盘坏道或掉盘&#xff0c;进入raid卡里看到硬盘一切正常&#xf…

跟着团子学SAP PS:如何查询PS模块中的user exits以及相关BAdIs SE80/SMOD/CNEX006/CNEX007/CNEX008

在PS很多标准字段或功能无法满足客户需求的时候往往需要通过SAP标准的user exits或者BAdI进行开发以满足业务需要&#xff0c;所以今天介绍下如何查询PS模块中的用户出口以及BAdIs&#xff1a; &#xff08;1&#xff09;查询PS模块中的user exits: 执行SE80&#xff0c;在菜…

EXT

ext的核心是store&#xff0c;存储数据用的。调试时可以先把store这块先屏蔽掉&#xff0c;先看页面的&#xff0c;页面出来了再调试store。这样会调试起来很快。 init: function () { var view this.getView(), // var store Global.getStore(app.store.L…

IDEA|class path resource XXX cannot be opened because it does not exits

IDEA|class path resource XXX cannot be opened because it does not exits 问题截图&#xff1a; 原因&#xff1a;没有设置好各个文件夹。我的理解是&#xff0c;当把文件夹设置好具体的功能才能被IDEA自动识别。 解决方法&#xff1a; 转发链接&#xff1a;https://bl…

User Exits和Customer Exits

一、Extension of SAP functionality SAP makes different possibilities available to extend SAP functionality in the R/3 without modifying the delivered R/3-Standard. Thus these extensions are further present also after a R/3-Release-Wechsel. User exit Fi…

sql查询中使用in和exits比较和区别

首先&#xff0c;查询中涉及到的两个表&#xff0c;一个user和一个order表&#xff0c;具体表的内容如下&#xff1a; user表&#xff1a; order表&#xff1a; in 确定给定的值是否与子查询或列表中的值相匹配。in在查询的时候&#xff0c;首先查询子查询的表&#xff0c;然后…

SQL语句中exits和in的区别

一 表展示 查询中涉及到的两个表&#xff0c;一个user和一个order表&#xff0c;具体表的内容如下&#xff1a; user表&#xff1a; order表&#xff1a; 二 in 演示 确定给定的值是否与子查询或列表中的值相匹配。in在查询的时候&#xff0c;首先查询子查询的表&#xff0c…

E. Exits in Excess

题意&#xff1a; 移除最多一半的边使得图没有环。 将所有边分成两部分&#xff0c; 第一部分为 u < v u < v u<v&#xff0c; 第二部分为 v > u v > u v>u&#xff0c; 将小的边集合删去即可。 AC代码&#xff1a; int n, m; vector<int> v1, v2…

20220621 Dual Quaternion

文章目录 对偶数一、对偶数是什么&#xff1f;二、对偶矢量三、对偶四元数 对偶数 一、对偶数是什么&#xff1f; https://zhuanlan.zhihu.com/p/358146509 对偶数是一种特殊的自洽的运算&#xff0c;类似于常用的复数基本单位 i i i &#xff08; i 2 − 1 i^2-1 i2−1&a…

Quaternion

01:欧拉角 1.欧拉角Vector3(x,y,z)代表的是旋转物体&#xff08;若是标准旋转那么是旋转坐标轴x,y,z&#xff0c;转换为旋转物体则旋转角度取反顺序不变&#xff09;&#xff0c;且是将物体从物体坐标系旋转到惯性坐标系&#xff08;世界坐标系中为了渲染&#xff09;&#x…

Quaternion.Euler调整记录

Quaternion.Euler调整 1.运行unity 调整摄像头视角&#xff0c;找到需要的位置&#xff0c;记录下 摄像头的位置和旋转角度。 2.调整空物体的位置 使之位置与需要的位置一致 3.调整Quaternion.Euler 使Quaternion.Euler与旋转数值一致。

Quaternion(四元数)和旋转以及Yaw, pitch, roll 的含义

原文&#xff1a; http://www.linuxgraphics.cn/graphics/opengl_quaternion.html Quaternion(四元数)和旋转 本文介绍了四元数以及如何在OpenGL中使用四元数表示旋转。 Quaternion 的定义 四元数一般定义如下&#xff1a; qwxiyjzk其中 w,x,y,z是实数。同时&#xff0c;有…

Unity3d开发之对Quaternion的使用

上周找到了新公司。这周二来上班。可怕的是我刚去的第二天下午四点领导通知我做一个VRdemo&#xff0c;要求第二天交。我勒个擦。我现在对设备还没熟悉呢。连sdk都没下载而且距离上一次开发vr是在快两年之前了。属实让我措手不及。没错&#xff0c;按剧本走&#xff0c;加班到凌…

【Unity编程】四元数(Quaternion)与欧拉角

欧拉旋转、四元数、矩阵旋转之间的差异 除了欧拉旋转以外&#xff0c;还有两种表示旋转的方式&#xff1a;矩阵旋转和四元数旋转。接下来我们比较它们的优缺点。 欧拉角 优点&#xff1a;三个角度组成&#xff0c;直观&#xff0c;容易理解。优点&#xff1a;可以进行从一个方…

Quaternion类

Euler public static Quaternion Euler(float x, float y, float z); public static Quaternion Euler(Vector3 euler); 功能: 返回Quaternion对应的欧拉角 例子&#xff1a; public class ExampleClass : MonoBehaviour {public Quaternion rotation Quaternion.Euler(0, 30,…

Unity Quaternion

Quaternion 类的属性 eulerAngles 欧拉角 Quaternion 类的实例方法 1、SetFromToRotion 函数 2、SetLookRotation 函数 3、ToAngleAxis 函数 Quaternion 类的静态方法 1、Angle方法 2、Dot方法 3、Euler方法 4、FromToRotation方法 5、Inverse方法 6、Lerp方法 7…