5

Background

It is well known that the exact product of two floating point numbers is not always a floating point number, but the error exact(a*b) - float(a*b) is. Some codes for exact multiplication exploit this by returning the two numbers

res = a * b
err = fma(a, b, -res)

This makes use of the fused-multiply-add instruction which returns the expression (a*b)+c with one single rounding.

Question

Now, I would like to do the same for sums, i.e.

res = a + b
err = add3(a, b, -res)

add3 is supposed to return the expression (a+b)+c with one single rounding.

I wasn't able to find hints that add3 actually exists in the real world except in this article.

Is there a CPU instruction set that contains add3? Are there languages implementing it?

Andrew
  • 1
  • 4
  • 19
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
  • Are you talking about SIMD or scalar operations here ? You have an `sse` tag and a Wikipedia link to SIMD FMA extensions in AMD/Intel CPUs, but your example above is for the scalar `fma()` function in C/C++ ? – Paul R Feb 21 '18 at 12:17
  • The question is about "`add3`", not `fma`. – Nico Schlömer Feb 21 '18 at 12:18
  • Fine - but is the context scalar or SIMD, and are you looking for a specific architecture (e.g. x86) or is it a more general question ? And why the `sse` tag ? – Paul R Feb 21 '18 at 12:19
  • I was just wondering if such an instruction exists anywhere at all or if it's just a numerical analyst's dream right now. The flag `sse` was inappropriate, I removed it. – Nico Schlömer Feb 21 '18 at 12:24
  • 1
    OK - thanks for the clarification - I'm not aware of any such instruction, but it's somewhat clearer now what you're looking for. – Paul R Feb 21 '18 at 12:28
  • Ping @EricPostpischil... – Paul R Feb 21 '18 at 13:53
  • 1
    Not available as an instruction on any major processor architecture (yet), but this publication shows how it can be emulated quite easily: Sylvie Boldo and Guillaume Melquiond, "Emulation of FMA and Correctly Rounded Sums: Proved Algorithms Using Rounding to Odd", *IEEE Transactions on Computers*, Vol. 57, No. 4, April 2008, pp. 462-470 – njuffa Feb 26 '22 at 19:39

0 Answers0