转自: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:极大地提高浮点运算速度【转】的更多相关文章

  1. gcc/g++ -O 优化选项说明

    查查gcc手册就知道了,每个编译选项都控制着不同的优化选项 下面从网络上copy过来的,真要用到这些还是推荐查阅手册 -O设置一共有五种:-O0.-O1.-O2.-O3和-Os. 除了-O0以外,每一 ...

  2. gcc 优化选项 -O1 -O2 -O3 -Os 优先级

    http://hi.baidu.com/xiaole10368/item/7cea9b1369cc240db88a1a5c 少优化->多优化: O0 -->> O1 -->&g ...

  3. 不同优化选项对ARM下C语言编译的影响

    我们知道在C语言编译时,有那么几个常用的优化编译选项,分别是-O0,-O1,-O2,-O3以及-Os.之前一直觉得既然是优化选项,顶多是优化一下逻辑,提高一些效率或者减少一下程序大小而已.很少会觉得它 ...

  4. gcc -O0 -O1 -O2 -O3 四级优化选项及每级分别做什么优化【转】

    转自:http://blog.csdn.net/qinrenzhi/article/details/78334677 相关博客http://blog.chinaunix.net/uid-2495495 ...

  5. 多核服务器的JVM优化选项(转载)

    原文链接 现在多核CPU是主流.利用多核技术,可以有效发挥硬件的能力,提升吞吐量,对于Java程序,可以实现并发垃圾收集.但是Java利用多核技术也带来了一些问题,主要是多线程共享内存引起了.目前内存 ...

  6. Windows 下有什么软件能够极大地提高工作效率

    Windows 下有什么软件能够极大地提高工作效率?修改 可以推荐一些好的应用或者有趣的程序,能提升工作效率或者能让人眼前一亮的.修改 举报1 条评论 分享 • 邀请回答   按票数排序按时间排序 2 ...

  7. PNG与iOS优化选项

    从App Store下载到的每一枚App最初都是一只IPA文件(其实是zip格式,内含特定规则的文件夹组织方式).但当作zip解开之后会发现里面很多的PNG文件看不了,这是因为在这些PNG图像都已被i ...

  8. html样式表极大地提高了工作效率

    样式表极大地提高了工作效率 样式表定义如何显示 HTML 元素,就像 HTML 3.2 的字体标签和颜色属性所起的作用那样.样式通常保存在外部的 .css 文件中.通过仅仅编辑一个简单的 CSS 文档 ...

  9. 警惕arm-linux-gcc编译器优化选项

    arm-linux-gcc的优化选项例如(-O2),可以加速我们的程序,使程序执行效率更高.但是,倘若我们就是需要程序慢一点运行,但是优化却把我们的延时函数优化的没有了的时候,这种优化却不是我们想要的 ...

随机推荐

  1. Git 内部原理之 Git 对象哈希

    在上一篇文章中,将了数据对象.树对象和提交对象三种Git对象,每种对象会计算出一个hash值.那么,Git是如何计算出Git对象的hash值?本文的内容就是来解答这个问题. Git对象的hash方法 ...

  2. 从源码带你看懂functools的partial方法

    1.what? partial是什么, partial也叫偏函数.源码的描述是: 部分应用给定参数和关键字的新函数. New function with partial application of ...

  3. Python3中的列表用法,看这一篇就够了

    类似C语言中的列表用法 ---------------------------------------------------------------------------------------- ...

  4. 数学算法:CF534A-Exam(思维)

    Exam time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...

  5. C语言中可变参数的使用

    在C语言程序编写中我们使用最多的函数一定包括printf以及很多类似的变形体.这个函数包含在C库函数中,定义为 int printf( const char* format, ...); 除了一个格式 ...

  6. 12,scrapy框架之post请求

    今日概要 递归爬取解析多页页面数据 scrapy的post请求发送 1.递归爬取解析多页页面数据 - 需求:将糗事百科所有页码的作者和段子内容数据进行爬取切持久化存储 - 需求分析:每一个页面对应一个 ...

  7. IDEA配置好maven后新建maven项目一直build失败的解决方法

    maven配置了aliyun中央仓库后,IDEA新建maven项目一直出现以下问题: 相信有遇到这个问题的小伙伴很蛋疼,明明maven配置没错,新建项目却一直build失败,为了这个问题我重装过几次I ...

  8. 通过js date对象获取各种开始结束日期的示例

    有时候做一些任务计划的功能时候,需要提供一个开始时间或者结束时间,比如本周结束,本月结束,今天结束等等,因此,我参考网上的资料把相关的实现为一个项目: gitee: https://gitee.com ...

  9. loj2049 「HNOI2016」网络

    好像复杂度来说不是正解--不加谜之优化(下叙)能被loj上的加强数据卡 #include <algorithm> #include <iostream> #include &l ...

  10. 使用原app接口进行微信公众号开发

    1.跨域问题 原来的app项目已经上线,然而接下来就有意思了,突然上头说要把app的发件功能复制到微信公众号里.那么问题来了,微信公众号的页面是前端和交互式h5大哥写的. 那么就将页面丢微信里,请求我 ...