gcc都做了什么优化
直接上程序:
setjmp和longjmp是处理函数嵌套调用的,goto语句不能跨越函数,所以不选择goto。
#include <setjmp.h>
int setjmp(jmp_buf env); //返回值:若第一次直接调用则直接返回0,若从longjmp调用则返回下面的val
void longjmp(jmp_buf env, int val);
对程序进行不带优化编译:
[henry@localhost c]$ gcc -g youhua.c -o youhua
对程序进行带优化的编译:
[henry@localhost c]$ gcc -g -O youhua.c -o youhua_after
对比上面结果可以看到,全局、静态、volatile变量不受优化的影响。
- 不进行优化时,上面定义的5个变量包括register变量都直接从内存中取值。
- 进行优化后,register变量和局部变量gcc都是从寄存器中取的值。
gcc都做了什么优化呢?首先可以看到变量从内存取值优化到从寄存器取值。一下是manual的部分翻译。
gcc有几个优化等级:
O0,O1,O2,O3
-O0表示没有优化,-O1为缺省值,-O3优化级别最高
'-O '
'-O1 '
Optimize. Optimizing compilation takes somewhat more time, and a
lot more memory for a large function. With `-O ', the compiler tries to reduce code size and execution
time, without performing any optimizations that take a great deal ##编译器试着减少代码段的大小和代码执行时间,如果没有执行一些
of compilation time. 优化结果将花费大量编译时间。 `-O ' turns on the following optimization flags:
-fdefer-pop 延迟到必要时在函数栈种pop参数
-fdelayed-branch
-fguess-branch-probability
-fcprop-registers
-floop-optimize
-fif-conversion
-fif-conversion2
-ftree-ccp
-ftree-dce
-ftree-dominator-opts
-ftree-dse
-ftree-ter
-ftree-lrs
-ftree-sra
-ftree-copyrename
-ftree-fre
-ftree-ch
-funit-at-a-time
-fmerge-constants `-O ' also turns on `-fomit-frame-pointer ' on machines where doing ## ’-O‘也打开-fomit-frame-pointer标志当机器 so does not interfere with debugging. 这样做不会影响干涉调试。 `-O ' doesn 't turn on `-ftree-sra ' for the Ada compiler. This
option must be explicitly specified on the command line to be enabled for the Ada compiler.`-O2 '
完!
参考:·[1]
apue
gcc都做了什么优化的更多相关文章
- 【webapp的优化整理】要做移动前端优化的朋友进来看看吧
单页or多页 本文仅代表个人观点,不足请见谅,欢迎赐教. webapp 小钗从事单页相关的开发一年有余,期间无比的推崇webapp的网站模式,也整理了很多移动开发的知识点,但是现在回过头来看,weba ...
- 面试:做过sql优化吗?
近来面试找工作经常会遇见这种问题: 做过数据库优化吗?大数据量基础过吗?系统反应慢怎么查询? 这咱也没背过啊,面试还老问,现在的网站主要的压力都来自于数据库,频繁的数据库访问经常会使系统瘫痪,这样就需 ...
- [转帖]支撑双11每秒17.5万单事务 阿里巴巴对JVM都做了些什么?
支撑双11每秒17.5万单事务 阿里巴巴对JVM都做了些什么? https://mp.weixin.qq.com/s?__biz=MzA3OTg5NjcyMg==&mid=2661671930 ...
- OGG-Oracle 集成模式抽取进程,REGISTER DATABASE都做了什么?
一.学习目标 有同事问OGG技术问题,OGG软件,在oracle数据库中,集成模式抽取进程REGISTER DATABASE,都做了什么操作? 有什么风险? 并且提到了一个抽取进程注册,在瞬时间并发占 ...
- 深入探索Glide图片加载框架:做了哪些优化?如何管理生命周期?怎么做大图加载?
前言 Glide可以说是最常用的图片加载框架了,Glide链式调用使用方便,性能上也可以满足大多数场景的使用,Glide源码与原理也是面试中的常客. 但是Glide的源码内容比较多,想要学习它的源码往 ...
- configure, make, make install都做了什么
1. 我的理解./configure: 确保接下来的make以及make install所依赖的文件没有问题make: build编译连接生成可执行程序make install: 将编译好的可执行 ...
- 从架构演进的角度聊聊Spring Cloud都做了些什么?
Spring Cloud作为一套微服务治理的框架,几乎考虑到了微服务治理的方方面面,之前也写过一些关于Spring Cloud文章,主要偏重各组件的使用,本次分享主要解答这两个问题:Spring Cl ...
- Java对象的创建 —— new之后JVM都做了什么?
Java对象创建过程 1. 类加载检查 虚拟机遇到一条new指令时,首先将去检查这个指令的参数是否能在常量池中定位到一个类的符号引用,并且检查这个符号引用代表的类是否已经被加载.解析和初始化过.如果没 ...
- 从架构演进的角度聊聊Spring Cloud都做了些什么
1.从架构演进的角度聊聊Spring Cloud都做了些什么?2.中小型互联网公司微服务实践-经验和教训3.Spring Cloud在国内中小型公司能用起来吗?
随机推荐
- [原]素数筛法【Sieve Of Eratosthenes + Sieve Of Euler】
拖了有段时间,今天来总结下两个常用的素数筛法: 1.sieve of Eratosthenes[埃氏筛法] 这是最简单朴素的素数筛法了,根据wikipedia,时间复杂度为 ,空间复杂度为O(n). ...
- YTU 2610: A改错题--体检情况分析
2610: A改错题--体检情况分析 时间限制: 1 Sec 内存限制: 128 MB 提交: 233 解决: 161 题目描述 注:本题只需要提交标记为修改部分之间的代码,请按照C++方式提交. ...
- Mybatis 插入与批量插入以及多参数批量删除
实体类: import java.io.Serializable; public class AttachmentTable implements Serializable { private sta ...
- WCF常见异常-The maximum string content length quota (8192) has been exceeded while reading XML data
异常信息:The maximum string content length quota (8192) has been exceeded while reading XML data 问题:调用第三 ...
- LA 4670 (AC自动机 模板题) Dominating Patterns
AC自动机大名叫Aho-Corasick Automata,不知道的还以为是能自动AC的呢,虽然它确实能帮你AC一些题目.=_=|| AC自动机看了好几天了,作用就是多个模式串在文本串上的匹配. 因为 ...
- iPad中控制器view的width和height
一.iPad中控制器view的width和height 1> 规律 * width 是宽高中最小的那个值 * height 是宽高中最大的那个值 2> 举例(比如窗口根控制器的view,有 ...
- unity3d 破解安装
1.下载破解程序,执行生成unity_v4.x.ulf文件 2.断网 3.执行unity客户端,load该lisence文件即可 注意:安装unity客户端完成后,未破解,切记别打开unity客户端
- jquery 获取和设置 select下拉框的值(转手册)
##实例应用中遇到的问题 //在某事件响应的应用中设置select选中项,前两种情况的设置不生效,使用了最后一种用法才生效的 //$("#select_time").find(&q ...
- php 获取301 302的真实地址
function getRealURL($url){ $header = get_headers($url,1); if (strpos($header[0],'301') || strpos($he ...
- python练习程序(c100经典例10)
题目: 打印楼梯,同时在楼梯上方打印两个笑脸. print '..' for i in range(1,9): print '**' for j in range(1,i+1): print ' ',