我需要为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))。'
我在g++ -g0 -march=x86-64 -O2 -mtune=generic -msse3 -mno-fma -DNDEBUG main.cpp
的gcc环境中运行此代码,并始终获得0.48674319998526999 4602440005894221059
。
如何使用gcc复制_set_fma3_enable(0)
结果?
Visual Studio 16.7.4。 gcc版本9.3.0(带有wsl)