是否有一个(Linux)g ++等同于Visual Studio中使用的/ fp:precision和/ fp:fast标志? [英] Is there a (Linux) g++ equivalent to the /fp:precise and /fp:fast flags used in Visual Studio?

查看:265
本文介绍了是否有一个(Linux)g ++等同于Visual Studio中使用的/ fp:precision和/ fp:fast标志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

很多年前,我继承了一个使用Visual Studio(VC ++)标志的代码库'/ fp:fast在一个特定的计算重型库中生成更快的代码。不幸的是,'/ fp:fast'产生的结果与不同编译器(Borland C ++)下的同一个库略有不同。因为我们需要产生完全相同的结果,我切换到'/ fp:precise',这工作正常,一切都已经peachy从那以后。但是,现在我在uBuntu Linux 10.04上用g ++编译同一个库,我看到类似的行为,我想知道它是否有类似的根本原因。我的g ++构建的数值结果与我的VC ++构建的数值结果略有不同。这带来了我的问题:

Many years ago, I inherited a codebase that was using the Visual Studio (VC++) flag '/fp:fast' to produce faster code in a particular calculation-heavy library. Unfortunately, '/fp:fast' produced results that were slightly different to the same library under a different compiler (Borland C++). As we needed to produce exactly the same results, I switched to '/fp:precise', which worked fine, and everything has been peachy ever since. However, now I'm compiling the same library with g++ on uBuntu Linux 10.04 and I'm seeing similar behavior, and I wonder if it might have a similar root cause. The numerical results from my g++ build are slightly different from the numerical results from my VC++ build. This brings me to my question:

问题:

或类似的参数到VC ++中的'fp:fast'和'fp:precise'选项?

Does g++ have equivalent or similar parameters to the 'fp:fast' and 'fp:precise' options in VC++? (and what are they? I want to activate the 'fp:precise' equivalent.)

更详细的信息:

我使用'make'编译,调用g ++。只要我能告诉(make文件是有点神秘,而不是我写的)唯一的参数添加到g ++调用是正常(包括文件夹和要编译的文件)和-fPIC我不知道这个开关是什么,我没有看到它在'人'页)。

I compile using 'make', which calls g++. So far as I can tell (the make files are a little cryptic, and weren't written by me) the only parameters added to the g++ call are the "normal" ones (include folders and the files to compile) and -fPIC (I'm not sure what this switch does, I don't see it on the 'man' page).

'man g ++'中唯一相关的参数似乎是启用优化选项。 (例如 - 安全数学优化)。

The only relevant parameters in 'man g++' seem to be for turning optimization options ON. (e.g. -funsafe-math-optimizations). However, I don't think I'm turning anything ON, I just want to turn the relevant optimization OFF.

我试过发布和调试版本,VC ++给出了发布和调试的结果相同,而g ++对发布和调试给出了相同的结果,但是我不能得到g ++版本给出与VC ++版本相同的结果。

I've tried Release and Debug builds, VC++ gives the same results for release and debug, and g++ gives the same results for release and debug, but I can't get the g++ version to give the same results as the VC++ version.

推荐答案

过多的寄存器精度只是FPU寄存器的问题,编译器(使用正确的使能开关)往往会避免。当在SSE寄存器中执行浮点计算时,寄存器精度等于存储器精度。

Excess register precision is an issue only on FPU registers, which compilers (with the right enabling switches) tend to avoid anyway. When floating point computations are carried out in SSE registers, the register precision equals the memory one.

在我的经验中,大多数/ fp:快速影响(和潜在的差异)来自编译器自由执行代数变换。这可以像改变被命令顺序一样简单:

In my experience most of the /fp:fast impact (and potential discrepancy) comes from the compiler taking the liberty to perform algebraic transforms. This can be as simple as changing summands order:

( a + b ) + c --> a + ( b + c)



<将会,并可以得到一些相当复杂的变换 - 所有打算重复使用以前的计算。
在无限精度中,这样的变换是良性的,当然 - 但在有限精度他们实际上改变结果。作为一个玩具的例子,尝试summand-order-example与a = b = 2 ^( - 23),c = 1. MS的埃里克Fleegal 更详细地描述它

最接近/ fp:precise的gcc开关是-fno-unsafe-math-optimizations。我认为它是默认开 - 也许你可以尝试明确设置它,看看它是否有所作为。类似地,您可以尝试显式关闭所有-ffast-math优化:-fno-finite-math-only,-fmath-errno,-ftrapping-math,-frounding-math和-fsignaling-nans(最后2个选项是默认值!)

In this respect, the gcc switch nearest to /fp:precise is -fno-unsafe-math-optimizations. I think it's on by default - perhaps you can try setting it explicitly and see if it makes a difference. Similarly, you can try explicitly turning off all -ffast-math optimizations: -fno-finite-math-only, -fmath-errno, -ftrapping-math, -frounding-math and -fsignaling-nans (the last 2 options are non default!)

这篇关于是否有一个(Linux)g ++等同于Visual Studio中使用的/ fp:precision和/ fp:fast标志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆