c语言编译优化原则,KEIL编译器【C语言编译选项优化等级说明】

参考:https://blog..net/chengdong1314/article/details/53463183

KEIL编译器C语言编译选项优化等级说明摘录于:http://blog..net/conquerwave/article/details/10450721

9fec18852cf3b164216bff199ceb52b8.png

原文0Minimum optimization. Turns off most optimizations.It gives the best possible debug view and the lowest level of optimization.近乎不优化,用于调试代码。出现代码行不能设置断点可如此设置试试。1Restrictedoptimization. Removes unused inline functions and unused static functions.Turns off optimizations that seriously degrade the debug view. Ifused with --debug, this option gives a satisfactorydebug view with good code density.部分优化。移除未调用的内联函数和静态函数,关闭debug窗口优化,此状态也能用于调试2Highoptimization. If used with--debug, the debug viewmight be less satisfactory because the mapping of object code tosource code is not always clear.

This is the default optimization level.默认优化等级。如果处于debug状态,部分代码行将不能被调试,具体做了什么优化好像没说3Maximumoptimization.-O3 performs the same optimizationsas-O2 however the balance between space and timeoptimizations in the generated code is more heavily weighted towardsspace or time compared with-O2. That is:

-O3 -Otime aims to produce fastercode than-O2 -Otime, at the risk of increasingyour image size

-O3 -Ospace aims to produce smallercode than-O2 -Ospace, but performance might bedegraded.

In addition, -O3 performs extra optimizationsthat are more aggressive, such as:

High-levelscalar optimizations, including loop unrolling, for-O3-Otime. Thiscan give significant performance benefits at a small code size cost,but at the risk of a longer build time.

More aggressive inlining and automatic inliningfor-O3 -Otime.

KEIL编译器C语言编译选项优化等级设置不一样造成代码运行的效果完全不一样,下面是SYD8801上运行的实例!

主函数如下:

int main()

{

uint8_tkey_num=0;

gpio_config();

led_close();

timer_0_enable(0x20,timer0_callback); // 32 * 31.25 us = 1ms

__enable_irq();

while(1)

{

*(uint32_t*)GPO_CTRL &=0xffffff00;

*(uint32_t*)GPO_CTRL |=0x000000ff;

}

}

现在的编译器C环境设置如下:

89474d1e689d6e7d17d81d4131829e39.png

编译、下载、复位后现象如下:

a97a09d8dd01802b8da4ea2da31d952d.png

如果编译设置这样改:

0da0017c3361023fa37f5f9ecc3f5cd7.png

编译、下载、复位现象是这样的:

24e9149ad750a3fd5c97ce5723333b28.png

所以一定要注意C编译器的优化选项,还有一点就是C编译器的设置选项也要关注的,虽然这里并没有出错,也就是如下图:

3ff8e5baf88c71375d7547e96dc04e79.png

支持C99(变量声明在执行语句之后)

C语言目前已经支持变量声明在执行语句之后的操作了,不过这是C99的内容,KELL默认是不支持C99的,也就是说下面的写法KELL将会报错:

155d73c43611220701402c16b22fe27a.png

KELL要支持C99可以按照如下操作:

55f687203e3dc931a7ee7bd94600b2c6.png

在低版本的KELL中也可以按照如下操作:

742787f9db8f51bc5eb0c90b37e96c66.png

KEIL反汇编设置

摘录于:http://www.stmcu.org/module/forum/thread-602450-1-1.html

这里只是学习之用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值