Skip to contentSkip to conversation

target/s390x: vfmin/vfmax fixes

PATCH In review Ilya Leoshkevich 3 participants 6 messages Jul 13, 2022 – Jul 19, 2022

lore
Share & tools
lore
#0 lore raw

v2 cover target/s390x: vfmin/vfmax fixes

Hi,

Uli has found an issue with finding maximum of different kinds of 0s; I wrote a test and found another one with finding maximum of different kinds of NaNs.

Patches 1 and 2 fix those issues, patch 3 adds a vfmin/vfmax test.

Best regards,
Ilya

v1: https://lists.gnu.org/archive/html/qemu-devel/2022-07/msg01915.html
v1 -> v2: Drop mmap() in the test (Richard).

Ilya Leoshkevich (3):
target/s390x: fix handling of zeroes in vfmin/vfmax target/s390x: fix NaN propagation rules tests/tcg/s390x: test signed vfmin/vfmax

 fpu/softfloat-specialize.c.inc    |   3 +-
 target/s390x/tcg/vec_fpu_helper.c |   4 +-
 tests/tcg/s390x/Makefile.target   |   7 +
 tests/tcg/s390x/vfminmax.c        | 411 ++++++++++++++++++++++++++++++
 4 files changed, 422 insertions(+), 3 deletions(-)
 create mode 100644 tests/tcg/s390x/vfminmax.c
Signature · 1 line
2.35.3
#1 lore raw

PATCH v2 1/3 target/s390x: fix handling of zeroes in vfmin/vfmax

vfmin_res() / vfmax_res() are trying to check whether a and b are both zeroes, but in reality they check that they are the same kind of zero. This causes incorrect results when comparing positive and negative zeroes.

Fixes da4807527f3b ("s390x/tcg: Implement VECTOR FP (MAXIMUM|MINIMUM)")
---
 target/s390x/tcg/vec_fpu_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/s390x/tcg/vec_fpu_helper.c +2 -2
index 2a618a1093..75cf605b9f 100644
@@ -824,7 +824,7 @@ static S390MinMaxRes vfmin_res(uint16_t dcmask_a, uint16_t dcmask_b,
         default:
             g_assert_not_reached();
         }
-    } else if (unlikely(dcmask_a & dcmask_b & DCMASK_ZERO)) {
+    } else if (unlikely((dcmask_a & DCMASK_ZERO) && (dcmask_b & DCMASK_ZERO))) {
         switch (type) {
         case S390_MINMAX_TYPE_JAVA:
             return neg_a ? S390_MINMAX_RES_A : S390_MINMAX_RES_B;
@@ -874,7 +874,7 @@ static S390MinMaxRes vfmax_res(uint16_t dcmask_a, uint16_t dcmask_b,
         default:
             g_assert_not_reached();
         }
-    } else if (unlikely(dcmask_a & dcmask_b & DCMASK_ZERO)) {
+    } else if (unlikely((dcmask_a & DCMASK_ZERO) && (dcmask_b & DCMASK_ZERO))) {
         const bool neg_a = dcmask_a & DCMASK_NEGATIVE;
 
         switch (type) {
Signature · 1 line
2.35.3
#2 lore raw

PATCH v2 2/3 target/s390x: fix NaN propagation rules

In reply to Ilya Leoshkevich

s390x has the same NaN propagation rules as ARM, and not as x86.

---
 fpu/softfloat-specialize.c.inc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fpu/softfloat-specialize.c.inc +2 -1
index 943e3301d2..a43ff5e02e 100644
@@ -390,7 +390,8 @@ bool float32_is_signaling_nan(float32 a_, float_status *status)
 static int pickNaN(FloatClass a_cls, FloatClass b_cls,
                    bool aIsLargerSignificand, float_status *status)
 {
-#if defined(TARGET_ARM) || defined(TARGET_MIPS) || defined(TARGET_HPPA)
+#if defined(TARGET_ARM) || defined(TARGET_MIPS) || defined(TARGET_HPPA) || \
+    defined(TARGET_S390X)
     /* ARM mandated NaN propagation rules (see FPProcessNaNs()), take
      * the first of:
      *  1. A if it is signaling
Signature · 1 line
2.35.3
#3 lore raw

PATCH v2 3/3 tests/tcg/s390x: test signed vfmin/vfmax

In reply to Ilya Leoshkevich

Add a test to prevent regressions. Try all floating point value sizes and all combinations of floating point value classes. Verify the results against PoP tables, which are represented as close to the original as possible - this produces a lot of checkpatch complaints, but it seems to be justified in this case.

---
 tests/tcg/s390x/Makefile.target |   7 +
 tests/tcg/s390x/vfminmax.c      | 411 ++++++++++++++++++++++++++++++++
 2 files changed, 418 insertions(+)
 create mode 100644 tests/tcg/s390x/vfminmax.c
tests/tcg/s390x/Makefile.target +7 -0
index 3124172736..1a7a4a2f59 100644
@@ -17,6 +17,13 @@ TESTS+=trap
 TESTS+=signals-s390x
 TESTS+=branch-relative-long
 
+Z14_TESTS=vfminmax
+vfminmax: LDFLAGS+=-lm
+$(Z14_TESTS): CFLAGS+=-march=z14 -O2
+
+TESTS+=$(if $(shell $(CC) -march=z14 -S -o /dev/null -xc /dev/null \
+			 >/dev/null 2>&1 && echo OK),$(Z14_TESTS))
+
 VECTOR_TESTS=vxeh2_vs
 VECTOR_TESTS+=vxeh2_vcvt
 VECTOR_TESTS+=vxeh2_vlstr
tests/tcg/s390x/vfminmax.c new file +411 -0

411 lines not on this page · raw message

Signature · 1 line
2.35.3
Reviewed-by on v2 3/3
#4 lore raw

Re: [PATCH v2 3/3] tests/tcg/s390x: test signed vfmin/vfmax

Quoted 6 lines · Ilya Leoshkevich

Add a test to prevent regressions. Try all floating point value sizes and all combinations of floating point value classes. Verify the results against PoP tables, which are represented as close to the original as possible - this produces a lot of checkpatch complaints, but it seems to be justified in this case.

Quoted 6 lines
---
  tests/tcg/s390x/Makefile.target |   7 +
  tests/tcg/s390x/vfminmax.c      | 411 ++++++++++++++++++++++++++++++++
  2 files changed, 418 insertions(+)

create mode 100644 tests/tcg/s390x/vfminmax.c

r~

#5 lore raw
In reply to Ilya Leoshkevich
Quoted 19 lines · Ilya Leoshkevich

Hi,

Uli has found an issue with finding maximum of different kinds of 0s; I wrote a test and found another one with finding maximum of different kinds of NaNs.

Patches 1 and 2 fix those issues, patch 3 adds a vfmin/vfmax test.

Best regards,
Ilya

v1: https://lists.gnu.org/archive/html/qemu-devel/2022-07/msg01915.html
v1 -> v2: Drop mmap() in the test (Richard).

Ilya Leoshkevich (3):

   target/s390x: fix handling of zeroes in vfmin/vfmax
   target/s390x: fix NaN propagation rules
   tests/tcg/s390x: test signed vfmin/vfmax
Quoted 7 lines
  fpu/softfloat-specialize.c.inc    |   3 +-
  target/s390x/tcg/vec_fpu_helper.c |   4 +-
  tests/tcg/s390x/Makefile.target   |   7 +
  tests/tcg/s390x/vfminmax.c        | 411 ++++++++++++++++++++++++++++++
  4 files changed, 422 insertions(+), 3 deletions(-)

create mode 100644 tests/tcg/s390x/vfminmax.c

Thanks, queued to my s390x-next branch now:

https://gitlab.com/thuth/qemu/-/commits/s390x-next/

Thomas