MSVC supports AVX/AVX2 instructions for years now and according to this msdn blog post, it can automatically generate fused-multiply-add (FMA) instructions.
Yet neither of the following functions compile to FMA instruction:
float func1(float x, float y, float z)
{
return x * y + z;
}
float func2(float x, float y, float z)
{
return std::fma(x,y,z);
}
Even worse, std::fma is not implemented as a single FMA instruction, it performs terribly, much slower than a plain x * y + z
(the poor performance of std::fma is expected if the implementation doesn't rely on FMA instruction).
I compile with /arch:AVX2 /O2 /Qvec
flags.
Also tried it with /fp:fast
, no success.
So the question is how can MSVC forced to automatically emit FMA instructions?
UPDATE
There is a #pragma fp_contract (on|off)
, which (looks like) does nothing.