2

I've gotten great performance benefit from using the mad function in the c++AMP library. I was wondering if there is a similar function for regular c++ 11? All I found googling was stuff on AVX intrinsics but I'd rather avoid them due to them not being universally supported.

Also, they seem to be all made for processing 4+ mad operations at the same time and I'm not sure that constructing an environment for that to happen while actually just using 1 of them is even efficient.

manlio
  • 18,345
  • 14
  • 76
  • 126
user81993
  • 6,167
  • 6
  • 32
  • 64
  • 1
    Do you mean something like [inner_product](http://en.cppreference.com/w/cpp/algorithm/inner_product)? – SirGuy Mar 04 '15 at 13:13
  • 2
    It depends on your CPU and your compiler, but if your CPU supports FMA (e.g. Haswell) and your compiler is half-way decent then you may already be getting fused multiply-accumulate. – Paul R Mar 04 '15 at 13:13
  • 2
    What do you expect? A _portable_ way? Don't you see it's heavily architecture-dependent? – Matt Mar 04 '15 at 13:13
  • 1
    @user4419802 according to the answer, yes :p – user81993 Mar 04 '15 at 13:24
  • @user81993 Well, it's not guaranteed to perform better than just `(x*y+z)`, but usually it should. OK then. – Matt Mar 04 '15 at 13:43

1 Answers1

3

In C and C++ there is the fma family of math functions:

As they are part of the standard library they should be portable enough.

Felix Bytow
  • 345
  • 1
  • 6