浮点优化选项 -ffast-math:极大地提高浮点运算速度【转】
转自:http://blog.csdn.net/zjujoe/article/details/2604157
版权声明:本文为博主原创文章,未经博主允许不得转载。
关于浮点优化选项:(摘自C in a nutshell)
C99 浮点环境支持科学和数学级别的应用,这些应用必须有相当高的精度,但是某些应用却不是如此,注重速度高于精度。对于这些以速度为重的应用, -ffast-math 选项定义了预处理器宏 __FAST_MATH__, 指示编译不必遵循 IEEE 和 ISO 的浮点运算标准。-ffast-math标记是一个群组选项,可以分别启用下面六个优化选项:
-fno-math-errno
Disables the use of the global variable errno for math functions that represent a single floating-point instruction.
-funsafe-math-optimizations
The "unsafe math optimizations" are those that might violate floating-point math standards, or that do away with verification of arguments and results. Using such optimizations may involve linking code that modifies the floating-point processor's control flags.
-fno-trapping-math
Generates "nonstop" code, on the assumption that no math exceptions will be raised that can be handled by the user program.
-ffinite-math-only
Generates executable code that disregards infinities and NaN ("not a number") values in arguments and results.
-fno-rounding-math
This option indicates that your program does not depend on a certain rounding behavior, and does not attempt to change the floating-point environment's default rounding mode. This setting is currently the default, and its opposite, -frounding-math, is still experimental.
-fno-signaling-nans
This option permits optimizations that limit the number of floating-point exceptions that may be raised by signaling NaNs. This setting is currently the default, and its opposite, -fsignaling-nans, is still experimental.
测试
测试方法
分别使用marvell(gcc4.1.1) 以及 maemo 编译器(codesourcery 2005q3-2,gcc3.4.4)并使用不同的编译选项进行测试对比。 程序运行在 PXA310 624M CPU 下。
marvell 编译器 + -ffast-math
arm-iwmmxt-Linux-gnueabi-gcc float.c -o float1
arm-iwmmxt-linux-gnueabi-strip float1
arm-iwmmxt-linux-gnueabi-gcc -ffast-math float.c -o float2
arm-iwmmxt-linux-gnueabi-strip float2
测试结果
/mnt/share # ./float1
Start time is: 0.0
DIV End time is: 4.4294564932
MUL End time is: 5.4294622841
ADD End time is: 6.4294699686
SUB End time is: 7.4294810851
/mnt/share # ./float2
Start time is: 0.0
DIV End time is: 1.66616
MUL End time is: 2.122699
ADD End time is: 3.253242
SUB End time is: 4.363897
Meamo 编译器 + -ffast-math
gcc -mfloat-abi=soft -march=iwmmxt float.c -o cs_float1
strip cs_float1
gcc -mfloat-abi=soft -march=iwmmxt -ffast-math float.c -o cs_float2
strip cs_float2
测试结果
/mnt/share # ./cs_float1
Start time is: 0.0
DIV End time is: 4.4294865258
MUL End time is: 5.258137
ADD End time is: 7.4294683333
SUB End time is: 8.169521
/mnt/share # ./cs_float2
Start time is: 0.0
DIV End time is: 1.330878
MUL End time is: 3.4294658034
ADD End time is: 4.110022
SUB End time is: 6.4294530884
以下运行在 meamo文件系统下:
Nokia-N810-42-19:/mnt/share# ./cs_float1
Start time is: 0.0
DIV End time is: 4.4294844089
MUL End time is: 5.229302
ADD End time is: 7.4294646888
SUB End time is: 8.127102
Nokia-N810-42-19:/mnt/share# ./cs_float2
Start time is: 0.0
DIV End time is: 1.320814
MUL End time is: 2.673556
ADD End time is: 4.84794
SUB End time is: 5.530572
浮点优化选项 -ffast-math:极大地提高浮点运算速度【转】的更多相关文章
- gcc/g++ -O 优化选项说明
查查gcc手册就知道了,每个编译选项都控制着不同的优化选项 下面从网络上copy过来的,真要用到这些还是推荐查阅手册 -O设置一共有五种:-O0.-O1.-O2.-O3和-Os. 除了-O0以外,每一 ...
- gcc 优化选项 -O1 -O2 -O3 -Os 优先级
http://hi.baidu.com/xiaole10368/item/7cea9b1369cc240db88a1a5c 少优化->多优化: O0 -->> O1 -->&g ...
- 不同优化选项对ARM下C语言编译的影响
我们知道在C语言编译时,有那么几个常用的优化编译选项,分别是-O0,-O1,-O2,-O3以及-Os.之前一直觉得既然是优化选项,顶多是优化一下逻辑,提高一些效率或者减少一下程序大小而已.很少会觉得它 ...
- gcc -O0 -O1 -O2 -O3 四级优化选项及每级分别做什么优化【转】
转自:http://blog.csdn.net/qinrenzhi/article/details/78334677 相关博客http://blog.chinaunix.net/uid-2495495 ...
- 多核服务器的JVM优化选项(转载)
原文链接 现在多核CPU是主流.利用多核技术,可以有效发挥硬件的能力,提升吞吐量,对于Java程序,可以实现并发垃圾收集.但是Java利用多核技术也带来了一些问题,主要是多线程共享内存引起了.目前内存 ...
- Windows 下有什么软件能够极大地提高工作效率
Windows 下有什么软件能够极大地提高工作效率?修改 可以推荐一些好的应用或者有趣的程序,能提升工作效率或者能让人眼前一亮的.修改 举报1 条评论 分享 • 邀请回答 按票数排序按时间排序 2 ...
- PNG与iOS优化选项
从App Store下载到的每一枚App最初都是一只IPA文件(其实是zip格式,内含特定规则的文件夹组织方式).但当作zip解开之后会发现里面很多的PNG文件看不了,这是因为在这些PNG图像都已被i ...
- html样式表极大地提高了工作效率
样式表极大地提高了工作效率 样式表定义如何显示 HTML 元素,就像 HTML 3.2 的字体标签和颜色属性所起的作用那样.样式通常保存在外部的 .css 文件中.通过仅仅编辑一个简单的 CSS 文档 ...
- 警惕arm-linux-gcc编译器优化选项
arm-linux-gcc的优化选项例如(-O2),可以加速我们的程序,使程序执行效率更高.但是,倘若我们就是需要程序慢一点运行,但是优化却把我们的延时函数优化的没有了的时候,这种优化却不是我们想要的 ...
随机推荐
- Git 内部原理之 Git 对象哈希
在上一篇文章中,将了数据对象.树对象和提交对象三种Git对象,每种对象会计算出一个hash值.那么,Git是如何计算出Git对象的hash值?本文的内容就是来解答这个问题. Git对象的hash方法 ...
- wampserver怎么设置外网可访问
wampserver配置httpd.conf允许外网访问? 在电脑上开启wamp服务后,默认是禁止外部网络访问的,如果您想要同一局域网中的设备能够访问PC上的web项目,则需要对httpd.conf文 ...
- python3爬虫之Urllib库(一)
上一篇我简单说了说爬虫的原理,这一篇我们来讲讲python自带的请求库:urllib 在python2里边,用urllib库和urllib2库来实现请求的发送,但是在python3种在也不用那么麻烦了 ...
- request_resource
1.全局变量 resource结构体定义如下,指针parent.sibling.child用于构建树状结构. struct resource { resource_size_t start; reso ...
- A1083 List Grades (25)(25 分)
A1083 List Grades (25)(25 分) Given a list of N student records with name, ID and grade. You are supp ...
- NMF分解(二)
应用: 一.图像分析 NMF最成功的一类应用是在图像的分析和处理领域.图像本身包含大量的数据,计算机一般将图像的信息按照矩阵的形式进行存放,针对图像的识别.分析和处理也是在矩阵的基础上进行的.这些特点 ...
- FreeMarker的基础语法使用 && 心得和技巧
FreeMarker语言 FreeMarker语言概述 FreeMarker是一个模板引擎,一个基于模板生成文本输出的通用工具,使用纯Java编写. FreeMarker被设计用来生成HTML Web ...
- loj2308 「APIO2017」商旅
ref #include <iostream> #include <cstring> #include <cstdio> #include <queue> ...
- WordCount by Java
WordCount by Java 软测第二周作业 该项目github地址如下: https://github.com/YuQiao0303/WordCount 一.概述 项目WordCount的需求 ...
- python - 接口自动化测试 - TestLogin - 登录接口测试用例
# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: test_login.py @ide: PyCharm C ...