6

Does the C# compiler / jitter make use of fused multiply-add operations if they are available on the hardware being used? If it does, are there any particular compiler settings I need to set in order to take advantage of it?

redcalx
  • 8,177
  • 4
  • 56
  • 105
Paul Chernoch
  • 5,275
  • 3
  • 52
  • 73
  • 2
    No. Such code generation is limited to System.Numeric.Vectors, its current version does not use FMA. Might be different tomorrow, there wasn't much point in moving the matrix classes into that namespace otherwise. Only way to get it is to use the C++/CLI language, beware the interop overhead. Measure three times, cut once. – Hans Passant May 25 '16 at 17:17
  • I was curious if anything had changed on this, but am now confused. The disassembly for multiplication of two Matrix3x2 seems to use vector instructions to load the registers, but there are no add or multiplication instructions, so it appears the work is done by a subroutine (CALL). There is indeed handling of PInvoke in the code gen at https://github.com/dotnet/coreclr/blob/4f8be95166a30ea7c0b1d6aed4ef424ee47c425a/src/jit/codegenxarch.cpp (line 5014) – redcalx May 21 '17 at 22:24
  • Somewhat relevant: I'm seeing generation of a vdpps instruction (dot product) from Vector.Dot(vec1, vec2) using System.Numerics.Vectors v.4.4.0-preview2-25405-01. – redcalx Jul 31 '17 at 23:06

1 Answers1

6

At last, .NET Core 3.0 provides System.Math.FusedMultiplyAdd. The rationale for not using this operation automatically is explained in a github issue.

Tom Minka
  • 794
  • 6
  • 10