diff mbox series

[03/21] softfloat: add xtensa specialization for pickNaNMulAdd

Message ID 20200706234737.32378-4-jcmvbkbc@gmail.com (mailing list archive)
State New, archived
Headers show
Series target/xtensa: implement double precision FPU | expand

Commit Message

Max Filippov July 6, 2020, 11:47 p.m. UTC
pickNaNMulAdd logic on Xtensa is the same as pickNaN when applied to
the expression (a * b) + c. So with two pickNaN variants there must be
two pickNaNMulAdd variants.

Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: "Alex Bennée" <alex.bennee@linaro.org>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
 fpu/softfloat-specialize.inc.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Alex Bennée July 7, 2020, 10:29 a.m. UTC | #1
Max Filippov <jcmvbkbc@gmail.com> writes:

> pickNaNMulAdd logic on Xtensa is the same as pickNaN when applied to
> the expression (a * b) + c. So with two pickNaN variants there must be
> two pickNaNMulAdd variants.
>
> Cc: Peter Maydell <peter.maydell@linaro.org>
> Cc: "Alex Bennée" <alex.bennee@linaro.org>
> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>

Acked-by: Alex Bennée <alex.bennee@linaro.org>
Richard Henderson July 8, 2020, 4:07 p.m. UTC | #2
On 7/6/20 4:47 PM, Max Filippov wrote:
> pickNaNMulAdd logic on Xtensa is the same as pickNaN when applied to
> the expression (a * b) + c. So with two pickNaN variants there must be
> two pickNaNMulAdd variants.

"Is the same as"?

I question the non-use of the infzero parameter.

When infzero, (a * b) = (Inf * 0), which will produce a default QNaN.  Your
sentence above would suggest that pickNaN is applied twice, so that if
use_first_nan, the default nan is chosen above any nan within c.

In addition, is the invalid flag raised for (Inf * 0) + NaN?  Does that happen
regardless of the use_first_nan setting, or does the whole operation short-circuit?


r~
Max Filippov July 8, 2020, 6:11 p.m. UTC | #3
On Wed, Jul 8, 2020 at 9:07 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 7/6/20 4:47 PM, Max Filippov wrote:
> > pickNaNMulAdd logic on Xtensa is the same as pickNaN when applied to
> > the expression (a * b) + c. So with two pickNaN variants there must be
> > two pickNaNMulAdd variants.
>
> "Is the same as"?
>
> I question the non-use of the infzero parameter.
>
> When infzero, (a * b) = (Inf * 0), which will produce a default QNaN.  Your
> sentence above would suggest that pickNaN is applied twice, so that if
> use_first_nan, the default nan is chosen above any nan within c.

Apparently the description it's wrong: only NaNs in arguments are
considered, default NaN produced as a result of (a * b) is never
chosen when c is NaN.

> In addition, is the invalid flag raised for (Inf * 0) + NaN?  Does that happen
> regardless of the use_first_nan setting, or does the whole operation short-circuit?

Flag setting happens regardless of which NaN is chosen.
I'll post v3 with a fix for this and additional tests.
diff mbox series

Patch

diff --git a/fpu/softfloat-specialize.inc.c b/fpu/softfloat-specialize.inc.c
index e17327b405c5..6b07d50efad3 100644
--- a/fpu/softfloat-specialize.inc.c
+++ b/fpu/softfloat-specialize.inc.c
@@ -574,6 +574,24 @@  static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls,
     } else {
         return 1;
     }
+#elif defined(TARGET_XTENSA)
+    if (status->use_first_nan) {
+        if (is_nan(a_cls)) {
+            return 0;
+        } else if (is_nan(b_cls)) {
+            return 1;
+        } else {
+            return 2;
+        }
+    } else {
+        if (is_nan(c_cls)) {
+            return 2;
+        } else if (is_nan(b_cls)) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
 #else
     /* A default implementation: prefer a to b to c.
      * This is unlikely to actually match any real implementation.