All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] target/s390x: Fix R[NOX]SBG with T=1
@ 2023-03-16 17:22 Ilya Leoshkevich
  2023-03-16 17:22 ` [PATCH v3 1/2] " Ilya Leoshkevich
  2023-03-16 17:22 ` [PATCH v3 2/2] tests/tcg/s390x: Add rxsbg.c Ilya Leoshkevich
  0 siblings, 2 replies; 4+ messages in thread
From: Ilya Leoshkevich @ 2023-03-16 17:22 UTC (permalink / raw)
  To: Richard Henderson, David Hildenbrand, Thomas Huth,
	Philippe Mathieu-Daudé
  Cc: qemu-s390x, qemu-devel, Ilya Leoshkevich

v2: https://lists.gnu.org/archive/html/qemu-devel/2023-03/msg04699.html
v2 -> v3: Assert that o->out != NULL, mention the commit that exposed
          the problem (Philippe).

v1: https://lists.gnu.org/archive/html/qemu-devel/2023-03/msg04493.html
v1 -> v2: Work around a clang issue (Thomas).
          Add cc=0 test, use more human-friendly constants.

Hi,

This series fixes ROTATE THEN <do something with> SELECTED BITS when
test-results control is on. The problem is the incorrect translation,
which confuses the register allocator.

Patch 1 is the fix, patch 2 adds a test.

Best regards,
Ilya

Ilya Leoshkevich (2):
  target/s390x: Fix R[NOX]SBG with T=1
  tests/tcg/s390x: Add rxsbg.c

 target/s390x/tcg/translate.c    |  4 +++
 tests/tcg/s390x/Makefile.target |  3 +++
 tests/tcg/s390x/rxsbg.c         | 46 +++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 tests/tcg/s390x/rxsbg.c

-- 
2.39.2



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v3 1/2] target/s390x: Fix R[NOX]SBG with T=1
  2023-03-16 17:22 [PATCH v3 0/2] target/s390x: Fix R[NOX]SBG with T=1 Ilya Leoshkevich
@ 2023-03-16 17:22 ` Ilya Leoshkevich
  2023-03-16 17:22 ` [PATCH v3 2/2] tests/tcg/s390x: Add rxsbg.c Ilya Leoshkevich
  1 sibling, 0 replies; 4+ messages in thread
From: Ilya Leoshkevich @ 2023-03-16 17:22 UTC (permalink / raw)
  To: Richard Henderson, David Hildenbrand, Thomas Huth,
	Philippe Mathieu-Daudé
  Cc: qemu-s390x, qemu-devel, Ilya Leoshkevich

RXSBG usage in the "filetests" test from the wasmtime testsuite makes
tcg_reg_alloc_op() attempt to temp_load() a TEMP_VAL_DEAD temporary,
causing an assertion failure:

    0x01000a70:  ec14 b040 3057  rxsbg    %r1, %r4, 0xb0, 0x40, 0x30

    OP after optimization and liveness analysis:
     ---- 0000000001000a70 0000000000000004 0000000000000006
     rotl_i64 tmp2,r4,$0x30                   dead: 1 2  pref=0xffff
     and_i64 tmp2,tmp2,$0x800000000000ffff    dead: 1  pref=0xffff
    [xor_i64 tmp3,tmp3,tmp2                   dead: 1 2  pref=0xffff]
     and_i64 cc_dst,tmp3,$0x800000000000ffff  sync: 0  dead: 0 1 2  pref=0xffff
     mov_i64 psw_addr,$0x1000a76              sync: 0  dead: 0 1  pref=0xffff
     mov_i32 cc_op,$0x6                       sync: 0  dead: 0 1  pref=0xffff
     call lookup_tb_ptr,$0x6,$1,tmp8,env      dead: 1  pref=none
     goto_ptr tmp8                            dead: 0
     set_label $L0
     exit_tb $0x7fffe809d183

    ../tcg/tcg.c:3865: tcg fatal error

The reason is that tmp3 does not have an initial value, which confuses
the register allocator. This also affects the correctness of the
results.

Fix by assigning R1 to it.

Exposed by commit e2e641fa3d5 ("tcg: Change default temp lifetime to
TEMP_TB").

Fixes: d6c6372e186e ("target-s390: Implement R[NOX]SBG")
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 target/s390x/tcg/translate.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c
index 14c3896d529..0fb36e04be8 100644
--- a/target/s390x/tcg/translate.c
+++ b/target/s390x/tcg/translate.c
@@ -3695,11 +3695,15 @@ static DisasJumpType op_rosbg(DisasContext *s, DisasOps *o)
     int i3 = get_field(s, i3);
     int i4 = get_field(s, i4);
     int i5 = get_field(s, i5);
+    TCGv_i64 orig_out;
     uint64_t mask;
 
     /* If this is a test-only form, arrange to discard the result.  */
     if (i3 & 0x80) {
+        tcg_debug_assert(o->out != NULL);
+        orig_out = o->out;
         o->out = tcg_temp_new_i64();
+        tcg_gen_mov_i64(o->out, orig_out);
     }
 
     i3 &= 63;
-- 
2.39.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3 2/2] tests/tcg/s390x: Add rxsbg.c
  2023-03-16 17:22 [PATCH v3 0/2] target/s390x: Fix R[NOX]SBG with T=1 Ilya Leoshkevich
  2023-03-16 17:22 ` [PATCH v3 1/2] " Ilya Leoshkevich
@ 2023-03-16 17:22 ` Ilya Leoshkevich
  2023-03-17  7:52   ` Thomas Huth
  1 sibling, 1 reply; 4+ messages in thread
From: Ilya Leoshkevich @ 2023-03-16 17:22 UTC (permalink / raw)
  To: Richard Henderson, David Hildenbrand, Thomas Huth,
	Philippe Mathieu-Daudé
  Cc: qemu-s390x, qemu-devel, Ilya Leoshkevich

Add a small test for RXSBG with T=1 to prevent regressions.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tests/tcg/s390x/Makefile.target |  3 +++
 tests/tcg/s390x/rxsbg.c         | 46 +++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100644 tests/tcg/s390x/rxsbg.c

diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index cf93b966862..3c940ac952e 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -29,10 +29,13 @@ TESTS+=clst
 TESTS+=long-double
 TESTS+=cdsg
 TESTS+=chrl
+TESTS+=rxsbg
 
 cdsg: CFLAGS+=-pthread
 cdsg: LDFLAGS+=-pthread
 
+rxsbg: CFLAGS+=-O2
+
 Z13_TESTS=vistr
 $(Z13_TESTS): CFLAGS+=-march=z13 -O2
 TESTS+=$(Z13_TESTS)
diff --git a/tests/tcg/s390x/rxsbg.c b/tests/tcg/s390x/rxsbg.c
new file mode 100644
index 00000000000..4b155db304e
--- /dev/null
+++ b/tests/tcg/s390x/rxsbg.c
@@ -0,0 +1,46 @@
+/*
+ * Test the RXSBG instruction.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdlib.h>
+
+static inline __attribute__((__always_inline__)) void
+rxsbg(unsigned long *r1, unsigned long r2, int i3, int i4, int i5, int *cc)
+{
+    asm("rxsbg %[r1],%[r2],%[i3],%[i4],%[i5]\n"
+        "ipm %[cc]"
+        : [r1] "+r" (*r1), [cc] "=r" (*cc)
+        : [r2] "r" (r2) , [i3] "i" (i3) , [i4] "i" (i4) , [i5] "i" (i5)
+        : "cc");
+    *cc = (*cc >> 28) & 3;
+}
+
+void test_cc0(void)
+{
+    unsigned long r1 = 6;
+    int cc;
+
+    rxsbg(&r1, 3, 61 | 0x80, 62, 1, &cc);
+    assert(r1 == 6);
+    assert(cc == 0);
+}
+
+void test_cc1(void)
+{
+    unsigned long r1 = 2;
+    int cc;
+
+    rxsbg(&r1, 3, 61 | 0x80, 62, 1, &cc);
+    assert(r1 == 2);
+    assert(cc == 1);
+}
+
+int main(void)
+{
+    test_cc0();
+    test_cc1();
+
+    return EXIT_SUCCESS;
+}
-- 
2.39.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 2/2] tests/tcg/s390x: Add rxsbg.c
  2023-03-16 17:22 ` [PATCH v3 2/2] tests/tcg/s390x: Add rxsbg.c Ilya Leoshkevich
@ 2023-03-17  7:52   ` Thomas Huth
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2023-03-17  7:52 UTC (permalink / raw)
  To: Ilya Leoshkevich, Richard Henderson, David Hildenbrand,
	Philippe Mathieu-Daudé
  Cc: qemu-s390x, qemu-devel

On 16/03/2023 18.22, Ilya Leoshkevich wrote:
> Add a small test for RXSBG with T=1 to prevent regressions.
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>   tests/tcg/s390x/Makefile.target |  3 +++
>   tests/tcg/s390x/rxsbg.c         | 46 +++++++++++++++++++++++++++++++++
>   2 files changed, 49 insertions(+)
>   create mode 100644 tests/tcg/s390x/rxsbg.c

Reviewed-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-17  7:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-16 17:22 [PATCH v3 0/2] target/s390x: Fix R[NOX]SBG with T=1 Ilya Leoshkevich
2023-03-16 17:22 ` [PATCH v3 1/2] " Ilya Leoshkevich
2023-03-16 17:22 ` [PATCH v3 2/2] tests/tcg/s390x: Add rxsbg.c Ilya Leoshkevich
2023-03-17  7:52   ` Thomas Huth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.