【发布时间】:2020-10-05 11:12:52
【问题描述】:
我需要为 64 位系统禁用 FMA3 指令(出于向后兼容性问题)。
我在 Windows 环境中使用了_set_FMA3_enable(0)。我需要使用什么选项(或宏)来禁用 gcc 中的 FMA3?
例如。
#include <iostream>
#include <iomanip>
#include <math.h>
#include <limits>
union value
{
double real;
long long unsigned integer;
};
int main()
{
#if defined (_WIN64)
_set_FMA3_enable(0);
#endif
value x;
x.integer = 4602754097807755994;
value y;
y.real = sin(x.real);
std::cout << std::setprecision(17) << y.real << std::endl;
std::cout << y.integer << std::endl;
}
在 Visual C++ 上,它运行到 0.48674319998526994 4602440005894221058 和 _set_FMA3_enable(0)。
0.48674319998526999 4602440005894221059 没有它(或使用 `_set_FMA3_enable(1))。'
我在 gcc 环境中使用g++ -g0 -march=x86-64 -O2 -mtune=generic -msse3 -mno-fma -DNDEBUG main.cpp 运行此代码,并且总是得到0.48674319998526999 4602440005894221059。
如何使用 gcc 重现 _set_FMA3_enable(0) 结果?
Visual Studio 16.7.4。 gcc 9.3.0 版(带 wsl)
【问题讨论】:
-
different versions of visual studio之间的浮点精度已经很难保证了,你有什么希望比较不同的编译器?
标签: c++ gcc cross-platform fma