检测x86上Linux的非正常浮动操作(Detecting denormal float operations on Linux for x86)

我正在将一个windows程序移植到linux的过程中,并且陷入了一段特定于msvc的代码中,这些代码似乎检查了浮点运算,从而导致了非正常或不精确的结果。 我非常不确定如何以可靠的方式实现它。 我应该补充一点,在涉及特定于linux的编程和像这些非常低级的操作时,我相当缺乏经验。

具体来说,给我麻烦的部分如下:

if ( _statusfp() & ( _SW_INEXACT | _SW_DENORMAL) )

{

... portable stuff ...

}

_clearfp();

虽然fenv.h似乎能够清除状态标志并检查不准确的标志,但它似乎没有提供任何帮助来检查反常标志。 此外,我已经向我建议,gcc可能会处理浮点运算的方式不同,以至于无法实现这段代码的简单直接端口。 我会很感激这方面的任何帮助。

如果它是相关的,那么在性能很重要的程序中,这被用于非常繁重的部分。

编辑:当根据http://en.cppreference.com/w/cpp/numeric/fenv/FE_exceptions生成非正规结果时,fenv.h中称为FE_UNDERFLOW的标志似乎会被引发,但看到其他几个消息来源指出:只有当结果太小,即使是低于正常水平时也会升高。 将运行测试,看看它是否也能满足我的需求,如果有的话也回答自己。

I'm in the process of porting a windows program to linux, and have gotten stumped on piece of msvc-specific code that seems to check for floating point operations that has given a denormal or inexact result. I'm very much unsure on how to implement it in a robust manner. I should add that I'm fairly inexperienced when it comes to both linux-specific programming and very low-level operations like these.

Specifically, the part that gives me trouble is the following:

if ( _statusfp() & ( _SW_INEXACT | _SW_DENORMAL) )

{

... portable stuff ...

}

_clearfp();

While fenv.h seems to give the ability to both clear the status flag and check for the inexact flag, it does not seem to provide any assistance in checking the denormal flag. Furthermore, I have had it suggested to me that gcc might handle floating point operations differently enough that a simple straight port of this piece of code may not be possible. I'd be grateful for any assistance in this.

If it is relevant, this is used in a very heavy number crunching part of the program where performance matter.

Edit: The flag in fenv.h called FE_UNDERFLOW seems to be raised when a denormal result is generated according to http://en.cppreference.com/w/cpp/numeric/fenv/FE_exceptions , but have seen several other sources state that it is raised only when the result is too small even for a subnormal. Will run tests to see if it does what I need it too and and answer myself if so.

原文:https://stackoverflow.com/questions/17217621

更新时间:2020-01-24 16:02

最满意答案

As said in the question, it seems that fenv.h has a flag FE_UNDERFLOW that on some architectures at least indicate a subnormal/denormal result. My own testing indicates that this seems to be the case on my test x86 architecture, so I will go ahead and use this for now unless a better solution is provided.

2013-06-27

相关问答

大约两个半月前(2016年9月)的以下补丁从thread_info结构中删除了“任务”成员: 提交15f4eae70d365bba26854c90b6002aaabb18c8aa 作者:Andy Lutomirski 日期:9月13日星期二14:29:25 2016-0700 x86:将thread_info移入task_struct 参见: http : //git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=15

...

除非你想引导你的整个工具链,你可以从uclibc工具链 (i386版本,我想象)开始 - 软浮动(AFAIK)不直接支持debian和派生类的“本地”编译,但它可以通过uclibc工具链的“嵌入式”方法使用。 Unless you want to bootstrap your entire toolchain by hand, you could start with uclibc toolchain (the i386 version, I imagine) -- soft float is (

...

是的,这就是你得到的( Linux系统调用号码 , 64位Linux系统调用号码 ): 11: sys_exevce ,或exec的系统调用 45: sys_brk ,malloc下的东西 33: sys_access 192: lgetxattr 等等。 Yes, it's what you got (Linux System Call Numbers, 64-bit Linux System Call Numbers): 11 : sys_exevce, or exec's system ca

...

我只能建议在隔离的位置(而不是/usr/目录)重建ImageMagick和委托。 curl -O http://www.imagemagick.org/download/ImageMagick.tar.gz

tar zvxf ImageMagick.tar.gz && cd ImageMagick-6.9.2-4

CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32 \

./configure --build=i686-pc-linux-gnu --prefix=/opt/

...

项目正在使用: http://packages.debian.org/source/sid/libatomic-ops 如果你想要简单的操作,如CAS,你不能只是使用arch的特定的实现从内核,并用自动工具/ cmake的用户空间的arch检查? 就许可而言,尽管内核是GPL,但我认为这些操作的内联程序集是由Intel / AMD提供的,而不是内核具有许可证。 它们恰好在内核源代码中容易访问。 Projects are using this: http://packages.debian.org/

...

-mregparm=3对此负责。 -mregparm=3 is responsible for this.

你的测量真的不多; 也许只是编译器优化的程度。 为了使测量有效,您必须对结果做一些事情,或者编译器可以优化所有测试或测试的主要部分。 我要做的是1)初始化向量,2)获取开始时间(可能使用clock ,因为这只需要考虑CPU时间),3)执行第二个循环100(或更多......足以持续几秒钟,至少几次,4)得到结束时间,最后,5)输出向量中元素的总和。 关于您可能会发现的差异:独立于浮点处理器,64位机器具有更多通用寄存器供编译器使用。 这可能会产生巨大的影响。 除非你看一下生成的汇编程序,否则你无法

...

C ++ 11是您的选择吗? 如果是这样,也许你可以在结果上调用std::isnormal ,参见例如http://en.cppreference.com/w/cpp/numeric/math/isnormal 。 As said in the question, it seems that fenv.h has a flag FE_UNDERFLOW that on some architectures at least indicate a subnormal/denormal result.

...

您至少需要删除空格 make CROSS_COMPILE=i686-linux ARCH=i386

但我不确定这是否足够。 阅读GNU make文档 。 You need at least to remove the spaces make CROSS_COMPILE=i686-linux ARCH=i386

but I am not sure that is enough. Read GNU make documentation.

read系统调用返回eax寄存器中读取的字节数。 如果此数字<0,则存在某种读取错误。 The read system call returns the number of bytes read in the eax register. If this number is < 0, there was a read error of some sort.

linux下float的寄存器,检测x86上Linux的非正常浮动操作(Detecting denormal float operations on Linux for x86)...相关推荐

  1. LINUX检测服务并自动运行,一种Linux下的开机自动检测硬件信息的方法与流程

    技术领域本发明涉及服务器开机检测技术,具体的说是一种Linux下的开机自动检测硬件信息的方法. 背景技术: 服务器产品研发初期,产品多为工程样本,问题很多,这些问题中硬件问题占较大部分.在工程验证测试 ...

  2. linux系统读sim卡信息,在Linux下使用串口读取SIM卡上的SMS消息使用C

    试图通过linux中的串口读取sms消息,从一张安装在华为3g USB调制解调器内的SIM卡读取.我必须在屏幕上显示一些短信之前执行脚本.有时它显示不寻常的字符.我想要做的就是使用AT命令,c和串行端 ...

  3. linux上连接ftp服务器,linux下lftp连接ftp服务器进行上传与下载的方法详解

    摘要 腾兴网为您分享:linux下lftp连接ftp服务器进行上传与下载的方法详解,中英翻译,中建在线,掌上看家,银行帮等软件知识,以及微信一键转发工具,小学英语冀教版,正是在下表情包,易问电信,万能 ...

  4. linux定时备份数据库到远程ftp,Linux下自动备份MySQL数据库并上传到远程FTP服务器...

    Linux下自动备份MySQL数据库并上传到远程FTP服务器且删除指定日期前的备份Shell脚本 说明: 1.备份MySQL数据库存放目录/var/lib/mysql下面的xshelldata数据库到 ...

  5. 实时linux下的PCI驱动开发(上)

    第一篇博客,忆苦思甜下先,当然,我尽量长话短说,但说来话长倒也无妨......这是我研究生阶段写的第一个Linux驱动,一入Linux深似海,从此Windows是路人.那是2009年冬天的第一场雪,王 ...

  6. Linux下使用tee既在屏幕上显示输出,又把输出写进文件

    Linux下的tee是一个很好用的工具,可以把重定向屏幕输出到文件的同时在屏幕上显示输出 使用示例如下: command | tee stdout.log 这里有一个需要注意的坑点,上面的命令只是把标 ...

  7. linux下rz和sz命令实现上传下载文件

    linux下上传文件命令 安装 yum install -y lrzsz 1.mobax使用上传会异常 ⚌CCCCCCCCCCC23be50ive.**B0100000023be50 解决方法:使用x ...

  8. linux下 单调时间(另附墙上时间、CPU时间)

    1.单调时间     linux下编写应用程序时,涉及到时间获取有多个函数可以选择,这些常用获取时间函数之间的差异: <1>. time 该函数返回自1970来的秒数,精度过低: < ...

  9. linux 下的gettimeofday 函数在windows上的替换方案

    方案一: #include <time.h> #ifdef WIN32 #   include <windows.h> #else #   include <sys/ti ...

最新文章

  1. android RecycleView padding 和高度一样会出现什么情况?
  2. HTML-参考手册: HTTP 方法:GET 对比 POST
  3. 每日一个css效果之css sprites
  4. jsp标签 判断 余数_程序员的数学基础课(三)余数与迭代法
  5. 抖音客新版UI短视频点赞任务系统完美运营级别[等级功能+信誉积分+保证金]
  6. 鼠标方式自动弹出内容html,html 在一个超链接上面,鼠标移动上去时,也显示一串文字,如何实现...
  7. SSH框架总结(框架分析+环境搭建+实例源码下载) 《转》
  8. 自动化运维工具puppet的使用
  9. shell脚本(四)
  10. 离散事件系统仿真(第五版)
  11. 搞一个yyds的京东登录页面
  12. Matlab表格和时间表中的分组计算
  13. JAVA面试题大全,收藏这一篇就够了
  14. QGridLayout(表格布局)详细使用说明
  15. 数据库系统概论 第七章 数据库设计(1)特点,概述,设计方法,规范设计方法,新奥尔良方法,用户和数据库管理员,模式,外模式,概念模式,逻辑模式,内模式,需求分析,数据项,数据流,数据存储,处理过程
  16. EOJ 3674.唐纳德先生与 .DOC
  17. Qt 编译错误 cannot find -lGL 解决方法
  18. Elsevier 期刊模板
  19. Angular、React、Vue.js 等 6 大主流 Web 框架都有什么优缺点
  20. Word2003常用快捷键

热门文章

  1. JQuery 中load、ready 和 onload 的区别
  2. 电脑市场GHOST XP SP3_V9.9
  3. JS的面向对象二(通过构造函数的方式)
  4. 恐龙世界游戏-恐龙百科世界乐园游戏
  5. python怎样设置列表翻译_翻译:《实用的Python编程》01_05_Lists
  6. 第三方推送服务:个推服务推送流程
  7. git的了解和开发安装 以及分支合集
  8. isee 处理图片的好工具
  9. Android手机添加BusyBox超级终端打造linux工具箱
  10. 将 dev 分支强推到 master