转自: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. 模块之 logging模块 time 模块 random模块 sys模块 pickle模块

    1.如果执行文件不在项目根目录下,需要添加项目根目录到sys.path中2.调用业务逻辑 2.logging模块 程序日志是 什么时间发生了什么事情,以及当时的情况 不是logging的话 记录日志的 ...

  2. 精通SpringBoot---整合RabbitMQ消息队列

    今天来和朋友们一起学习下,SpringBoot怎么整合RabbitMQ.目前消息组件大致有三种:.activemq, rabbitmq, kafka.这三者各有优缺点,RabbitMQ相比之下是处于其 ...

  3. Python9-MySQL-Homework-day43

    表结构 SET NAMES utf8; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure f ...

  4. HDU 5971 二分图判定

    Wrestling Match Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. MySQL查询数据库中表名或字段名

    查询数据库中所有表名 select table_name from information_schema.tables where table_schema='csdb' and table_type ...

  6. 2、python中的数字

    第二篇开始谈谈python中的数据. 一.前言 python中的数字包含了整数.浮点数.复数三种.在python的早期版本,或许可以看到正数被分为长整数与短整数,后来被取消了,因此这里不作讨论.通常我 ...

  7. 【精彩回顾】第二届微医前端技术沙龙(附PPT下载)

    5 月 25 日,以「无界」为主题的第二届微医前端技术沙龙成功举办.本届沙龙的演讲题目涵盖了前端技术几个主要的应用场景,包括服务端.桌面端以及跨平台的开发.最近几年前端技术发展非常快,各种可以提高开发 ...

  8. Careercup - Microsoft面试题 - 5485521224597504

    2014-05-12 06:19 题目链接 原题: Given an input list of lists.. flatten the list. For e.g. {{,}, {}, {,}} . ...

  9. leetcode 【 Container With Most Water 】python 实现

    题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...

  10. Python操作MySQL+Redis+MongoDB

    1-1 python操作三大主流数据库导学篇 1-2 数据库简介 1-3 MySQL简介 2-1 MySQL安装及配置 2-2 MySQL图形化管理工具 2-3 SQL语法基础-创建并使用数据库 2- ...