在 GCC 中启用严格的浮点模式 [英] Enabling strict floating point mode in GCC

查看:34
本文介绍了在 GCC 中启用严格的浮点模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还没有创建一个程序来查看 GCC 是否需要它通过,当我这样做时,我想知道我将如何启用严格的浮点模式,这将允许在运行和计算机之间重现结果,谢谢.

I haven't yet created a program to see whether GCC will need it passed, When I do I'd like to know how I'd go about enabling strict floating point mode which will allow reproducible results between runs and computers, Thanks.

推荐答案

在支持 -msse2 的 Intel/AMD 处理器上进行编译将使您几乎达到目标.不要让任何库将 FPU 置于 FTZ/DNZ 模式,您将主要设置(尽管有处理器错误).

Compiling with -msse2 on an Intel/AMD processor that supports it will get you almost there. Do not let any library put the FPU in FTZ/DNZ mode, and you will be mostly set (processor bugs notwithstanding).

对于其他架构,答案会有所不同.那些不提供任何方便的方法来获得精确的 IEEE 754 语义的架构(例如,pre-SSE2 IA32 CPU)将需要使用浮点仿真库来获得您想要的结果,但性能损失非常大.

For other architectures, the answer would be different. Those achitectures that do not offer any convenient way to get exact IEEE 754 semantics (for instance, pre-SSE2 IA32 CPUs) would require the use of a floating-point emulation library to get the result you want, at a very high performance penalty.

如果您的目标架构支持 fmadd(没有中间舍入的乘法和加法)指令,请确保您的编译器在源代码中有显式乘法和加法时不使用它.除非您使用 -ffast-math 选项,否则 GCC 不应该这样做.

If your target architecture supports the fmadd (multiplication and addition without intermediate rounding) instruction, make sure your compiler does not use it when you have explicit multiplications and additions in the source code. GCC is not supposed to do this unless you use the -ffast-math option.

这篇关于在 GCC 中启用严格的浮点模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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