target/s390x: vfmin/vfmax fixes
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
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 | 426 ++++++++++++++++++++++++++++++ 4 files changed, 437 insertions(+), 3 deletions(-) create mode 100644 tests/tcg/s390x/vfminmax.c
Signature · 1 line
2.35.3
PATCH 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.
--- target/s390x/tcg/vec_fpu_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/s390x/tcg/vec_fpu_helper.c +2 -2
@@ -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
PATCH 2/3 target/s390x: fix NaN propagation rules
In reply to Ilya Leoshkevichs390x 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
@@ -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
PATCH 3/3 tests/tcg/s390x: test signed vfmin/vfmax
In reply to Ilya LeoshkevichAdd 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 | 426 ++++++++++++++++++++++++++++++++ 2 files changed, 433 insertions(+) create mode 100644 tests/tcg/s390x/vfminmax.c
tests/tcg/s390x/Makefile.target +7 -0
@@ -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 +426 -0
426 lines not on this page · raw message
Signature · 1 line
2.35.3
Re: [PATCH 1/3] target/s390x: fix handling of zeroes in vfmin/vfmax
In reply to Ilya LeoshkevichQuoted 11 lines · Ilya Leoshkevich
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)")Co-developed-by Ulrich Weigand<[email protected]>Signed-off-by Ilya Leoshkevich<[email protected]>--- target/s390x/tcg/vec_fpu_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
r~
Re: [PATCH 2/3] target/s390x: fix NaN propagation rules
In reply to Ilya LeoshkevichQuoted 6 lines · Ilya Leoshkevich
s390x has the same NaN propagation rules as ARM, and not as x86.
Signed-off-by Ilya Leoshkevich<[email protected]>--- fpu/softfloat-specialize.c.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Yes, I think no one has those x86 rules, including x86. :-)
r~
Re: [PATCH 3/3] tests/tcg/s390x: test signed vfmin/vfmax
In reply to Ilya LeoshkevichQuoted 18 lines · Ilya Leoshkevich
tests/tcg/s390x/vfminmax.c new file +18
-0+/* +* vfmin/vfmax code generation. +*/ +extern const char vfminmax_template[]; +extern const int vfminmax_template_size; +extern const int vfminmax_offset; +asm(".globl vfminmax_template\n" +"vfminmax_template:\n" +"vl %v25,0(%r3)\n" +"vl %v26,0(%r4)\n" +"0: vfmax %v24,%v25,%v26,2,0,0\n" +"vst %v24,0(%r2)\n" +"br %r14\n" +"1: .align 4\n" +".globl vfminmax_template_size\n" +"vfminmax_template_size: .long 1b - vfminmax_template\n" +".globl vfminmax_offset\n" +"vfminmax_offset: .long 0b - vfminmax_template\n" );
...
Quoted 5 lines
tests/tcg/s390x/vfminmax.c new file +5
-0+ +#define VFMIN 0xEE +#define VFMAX 0xEF + +static void vfminmax(unsigned char *buf, unsigned int op,
tests/tcg/s390x/vfminmax.c line 40
Quoted 10 lines
tests/tcg/s390x/vfminmax.c new file +10
-0+ unsigned int m4, unsigned int m5, unsigned int m6, + void *v1, const void *v2, const void *v3) +{ +memcpy (buf ,vfminmax_template ,vfminmax_template_size ); + buf[vfminmax_offset +3 ] = (m6 <<4 ) | m5; + buf[vfminmax_offset +4 ] &=0x0F ; + buf[vfminmax_offset +4 ] |= (m4 <<4 ); + buf[vfminmax_offset +5 ] = op; + ((void (*)(void *,const void *,const void *))buf)(v1, v2, v3); +}
This works, of course. It could be simpler using EXECUTE, to store just the one instruction and not worry about an executable mapped page, but I guess it doesn't matter.
r~
Re: [PATCH 1/3] target/s390x: fix handling of zeroes in vfmin/vfmax
In reply to Ilya LeoshkevichQuoted 26 lines · Ilya Leoshkevich
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)")Co-developed-by Ulrich Weigand <[email protected]>Signed-off-by Ilya Leoshkevich <[email protected]>--- target/s390x/tcg/vec_fpu_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/s390x/tcg/vec_fpu_helper.c +1
-1@@ -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 ;
target/s390x/tcg/vec_fpu_helper.c static S390MinMaxRes vfmax_res(uint16_t dcmask_a, uint16_t dcmask_b, · line 880
Quoted 8 lines
target/s390x/tcg/vec_fpu_helper.c +1
-1@@ -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) {
Thanks!
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH 2/3] target/s390x: fix NaN propagation rules
In reply to Ilya LeoshkevichQuoted 12 lines · Ilya Leoshkevich
s390x has the same NaN propagation rules as ARM, and not as x86.
Signed-off-by Ilya Leoshkevich <[email protected]>--- fpu/softfloat-specialize.c.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fpu/softfloat-specialize.c.inc +0
-0
fpu/softfloat-specialize.c.inc bool float32_is_signaling_nan(float32 a_, float_status *status) · line 397
Quoted 9 lines
fpu/softfloat-specialize.c.inc +2
-1@@ -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 · 3 lines
Thanks, David / dhildenb
Re: [PATCH 3/3] tests/tcg/s390x: test signed vfmin/vfmax
In reply to Richard HendersonQuoted 43 lines · Richard Henderson
Quoted 18 lines · Ilya Leoshkevich
tests/tcg/s390x/vfminmax.c new file +18
-0+/* +* vfmin/vfmax code generation. +*/ +extern const char vfminmax_template[]; +extern const int vfminmax_template_size; +extern const int vfminmax_offset; +asm(".globl vfminmax_template\n" + "vfminmax_template:\n" + "vl %v25,0(%r3)\n" + "vl %v26,0(%r4)\n" + "0: vfmax %v24,%v25,%v26,2,0,0\n" + "vst %v24,0(%r2)\n" + "br %r14\n" + "1: .align 4\n" + ".globl vfminmax_template_size\n" + "vfminmax_template_size: .long 1b - vfminmax_template\n" + ".globl vfminmax_offset\n" + "vfminmax_offset: .long 0b - vfminmax_template\n");...
Quoted 9 lines
tests/tcg/s390x/vfminmax.c new file +6
-0+ +#define VFMIN 0xEE +#define VFMAX 0xEF + +static void vfminmax (unsigned char *buf,unsigned int op, + unsigned int m4, unsigned int m5, unsignedint m6,
+ void *v1, const void *v2, const void *v3) +{Quoted 8 lines
+
memcpy(buf, vfminmax_template, vfminmax_template_size); + buf[vfminmax_offset + 3] = (m6 << 4) | m5;
+ buf[vfminmax_offset + 4] &=0x0F;
+ buf[vfminmax_offset + 4] |= (m4 << 4);
+ buf[vfminmax_offset + 5] = op;
+ ((void (*)(void *, const void *, const void *))buf)(v1, v2, v3);
+}This works, of course. It could be simpler using EXECUTE, to store just the one
instruction and not worry about an executable mapped page, but I guess it doesn't matter.
Quoted 4 lines
Reviewed-by Richard Henderson <[email protected]>r~
Thanks!
I thought about this too, but EX/EXRL operate only on the second byte, and I need to modify bytes 3-5 here.
Re: [PATCH 3/3] tests/tcg/s390x: test signed vfmin/vfmax
Quoted 7 lines · Ilya Leoshkevich
Quoted 4 lines
This works, of course. It could be simpler using EXECUTE, to store just the one
instruction and not worry about an executable mapped page, but I guess it doesn't matter.I thought about this too, but EX/EXRL operate only on the second byte, and I need to modify bytes 3-5 here.
I didn't mean modify the instruction via EX, but something like
static char minmax[6] __attribute__((aligned(2)))
= { xx, yy, zz, 0, 0, 0 }; minmax[3] = m6 ...
minmax[4] = ...
minmax[5] = op;
asm("vl %%v25,0(%1)\n"
"vl %%v26,0(%2)\n"
"ex 0,0(%3)\n"
"vst %%v24,0(%0)"
: : "a"(v1), "a"(v2), "a"(v3), "a"(minmax)
: "memory", "v24", "v25", "v26);r~
Re: [PATCH 3/3] tests/tcg/s390x: test signed vfmin/vfmax
Quoted 28 lines · Richard Henderson
Quoted 9 lines · Ilya Leoshkevich
Quoted 5 lines
This works, of course. It could be simpler using EXECUTE, to store
just the one
instruction and not worry about an executable mapped page, but I guess it doesn't matter.I thought about this too, but EX/EXRL operate only on the second byte,
and I need to modify bytes 3-5 here.I didn't mean modify the instruction via EX, but something like
static char minmax[6] __attribute__((aligned(2))) = { xx, yy, zz, 0, 0, 0 };
minmax[3] = m6 ...
minmax[4] = ...
minmax[5] = op;asm("vl %%v25,0(%1)\n"
"vl %%v26,0(%2)\n"
"ex 0,0(%3)\n"
"vst %%v24,0(%0)"
: : "a"(v1), "a"(v2), "a"(v3), "a"(minmax)
: "memory", "v24", "v25", "v26);
Quoted 1 line
r~
Nice trick!
This works in qemu, but not natively: EX target must be executable. I'd still like to try to find a way to establish an rwx section, and send a v2 with this improvement.
I guess we'll need to fix the access check discrepancy some day.