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

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    |  3 +++
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/rxsbg.c         | 25 +++++++++++++++++++++++++
 3 files changed, 29 insertions(+)
 create mode 100644 tests/tcg/s390x/rxsbg.c

-- 
2.39.2



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

* [PATCH 1/2] target/s390x: Fix R[NOX]SBG with T=1
  2023-03-14 23:34 [PATCH 0/2] target/s390x: Fix R[NOX]SBG with T=1 Ilya Leoshkevich
@ 2023-03-14 23:34 ` Ilya Leoshkevich
  2023-03-15  8:59   ` David Hildenbrand
  2023-03-14 23:34 ` [PATCH 2/2] tests/tcg/s390x: Add rxsbg.c Ilya Leoshkevich
  1 sibling, 1 reply; 6+ messages in thread
From: Ilya Leoshkevich @ 2023-03-14 23:34 UTC (permalink / raw)
  To: Richard Henderson, David Hildenbrand, Thomas Huth
  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.

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

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



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

* [PATCH 2/2] tests/tcg/s390x: Add rxsbg.c
  2023-03-14 23:34 [PATCH 0/2] target/s390x: Fix R[NOX]SBG with T=1 Ilya Leoshkevich
  2023-03-14 23:34 ` [PATCH 1/2] " Ilya Leoshkevich
@ 2023-03-14 23:34 ` Ilya Leoshkevich
  2023-03-15 18:12   ` Thomas Huth
  1 sibling, 1 reply; 6+ messages in thread
From: Ilya Leoshkevich @ 2023-03-14 23:34 UTC (permalink / raw)
  To: Richard Henderson, David Hildenbrand, Thomas Huth
  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 |  1 +
 tests/tcg/s390x/rxsbg.c         | 25 +++++++++++++++++++++++++
 2 files changed, 26 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..b4d0d704534 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -29,6 +29,7 @@ TESTS+=clst
 TESTS+=long-double
 TESTS+=cdsg
 TESTS+=chrl
+TESTS+=rxsbg
 
 cdsg: CFLAGS+=-pthread
 cdsg: LDFLAGS+=-pthread
diff --git a/tests/tcg/s390x/rxsbg.c b/tests/tcg/s390x/rxsbg.c
new file mode 100644
index 00000000000..b7f35411899
--- /dev/null
+++ b/tests/tcg/s390x/rxsbg.c
@@ -0,0 +1,25 @@
+/*
+ * Smoke test RXSBG instruction with T=1.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdlib.h>
+
+int main(void)
+{
+    unsigned long r1, r2, cc;
+
+    r1 = 0xc8dc86a225a77bb4;
+    r2 = 0xd6aff24fa3e7320;
+    cc = 0;
+    asm("rxsbg %[r1],%[r2],177,43,228\n"
+        "ipm %[cc]"
+        : [cc] "+r" (cc)
+        : [r1] "r" (r1)
+        , [r2] "r" (r2)
+        : "cc");
+    cc = (cc >> 28) & 1;
+    assert(cc == 1);
+
+    return EXIT_SUCCESS;
+}
-- 
2.39.2



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

* Re: [PATCH 1/2] target/s390x: Fix R[NOX]SBG with T=1
  2023-03-14 23:34 ` [PATCH 1/2] " Ilya Leoshkevich
@ 2023-03-15  8:59   ` David Hildenbrand
  0 siblings, 0 replies; 6+ messages in thread
From: David Hildenbrand @ 2023-03-15  8:59 UTC (permalink / raw)
  To: Ilya Leoshkevich, Richard Henderson, Thomas Huth; +Cc: qemu-s390x, qemu-devel

On 15.03.23 00:34, Ilya Leoshkevich wrote:
> 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.
> 
> Fixes: d6c6372e186e ("target-s390: Implement R[NOX]SBG")
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb



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

* Re: [PATCH 2/2] tests/tcg/s390x: Add rxsbg.c
  2023-03-14 23:34 ` [PATCH 2/2] tests/tcg/s390x: Add rxsbg.c Ilya Leoshkevich
@ 2023-03-15 18:12   ` Thomas Huth
  2023-03-15 18:30     ` Ilya Leoshkevich
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Huth @ 2023-03-15 18:12 UTC (permalink / raw)
  To: Ilya Leoshkevich, Richard Henderson, David Hildenbrand
  Cc: qemu-s390x, qemu-devel

On 15/03/2023 00.34, 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 |  1 +
>   tests/tcg/s390x/rxsbg.c         | 25 +++++++++++++++++++++++++
>   2 files changed, 26 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..b4d0d704534 100644
> --- a/tests/tcg/s390x/Makefile.target
> +++ b/tests/tcg/s390x/Makefile.target
> @@ -29,6 +29,7 @@ TESTS+=clst
>   TESTS+=long-double
>   TESTS+=cdsg
>   TESTS+=chrl
> +TESTS+=rxsbg
>   
>   cdsg: CFLAGS+=-pthread
>   cdsg: LDFLAGS+=-pthread
> diff --git a/tests/tcg/s390x/rxsbg.c b/tests/tcg/s390x/rxsbg.c
> new file mode 100644
> index 00000000000..b7f35411899
> --- /dev/null
> +++ b/tests/tcg/s390x/rxsbg.c
> @@ -0,0 +1,25 @@
> +/*
> + * Smoke test RXSBG instruction with T=1.
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +#include <assert.h>
> +#include <stdlib.h>
> +
> +int main(void)
> +{
> +    unsigned long r1, r2, cc;
> +
> +    r1 = 0xc8dc86a225a77bb4;
> +    r2 = 0xd6aff24fa3e7320;
> +    cc = 0;
> +    asm("rxsbg %[r1],%[r2],177,43,228\n"
> +        "ipm %[cc]"
> +        : [cc] "+r" (cc)
> +        : [r1] "r" (r1)
> +        , [r2] "r" (r2)
> +        : "cc");
> +    cc = (cc >> 28) & 1;
> +    assert(cc == 1);
> +
> +    return EXIT_SUCCESS;
> +}

This also fails with Clang 15:
tests/tcg/s390x/rxsbg.c:15:9: error: invalid operand for instruction
     asm("rxsbg %[r1],%[r2],177,43,228\n"
         ^
<inline asm>:1:23: note: instantiated into assembly here
         rxsbg %r1,%r2,177,43,228
                              ^

  Thomas



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

* Re: [PATCH 2/2] tests/tcg/s390x: Add rxsbg.c
  2023-03-15 18:12   ` Thomas Huth
@ 2023-03-15 18:30     ` Ilya Leoshkevich
  0 siblings, 0 replies; 6+ messages in thread
From: Ilya Leoshkevich @ 2023-03-15 18:30 UTC (permalink / raw)
  To: Thomas Huth, Richard Henderson, David Hildenbrand; +Cc: qemu-s390x, qemu-devel

On Wed, 2023-03-15 at 19:12 +0100, Thomas Huth wrote:
> On 15/03/2023 00.34, 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 |  1 +
> >   tests/tcg/s390x/rxsbg.c         | 25 +++++++++++++++++++++++++
> >   2 files changed, 26 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..b4d0d704534 100644
> > --- a/tests/tcg/s390x/Makefile.target
> > +++ b/tests/tcg/s390x/Makefile.target
> > @@ -29,6 +29,7 @@ TESTS+=clst
> >   TESTS+=long-double
> >   TESTS+=cdsg
> >   TESTS+=chrl
> > +TESTS+=rxsbg
> >   
> >   cdsg: CFLAGS+=-pthread
> >   cdsg: LDFLAGS+=-pthread
> > diff --git a/tests/tcg/s390x/rxsbg.c b/tests/tcg/s390x/rxsbg.c
> > new file mode 100644
> > index 00000000000..b7f35411899
> > --- /dev/null
> > +++ b/tests/tcg/s390x/rxsbg.c
> > @@ -0,0 +1,25 @@
> > +/*
> > + * Smoke test RXSBG instruction with T=1.
> > + * SPDX-License-Identifier: GPL-2.0-or-later
> > + */
> > +#include <assert.h>
> > +#include <stdlib.h>
> > +
> > +int main(void)
> > +{
> > +    unsigned long r1, r2, cc;
> > +
> > +    r1 = 0xc8dc86a225a77bb4;
> > +    r2 = 0xd6aff24fa3e7320;
> > +    cc = 0;
> > +    asm("rxsbg %[r1],%[r2],177,43,228\n"
> > +        "ipm %[cc]"
> > +        : [cc] "+r" (cc)
> > +        : [r1] "r" (r1)
> > +        , [r2] "r" (r2)
> > +        : "cc");
> > +    cc = (cc >> 28) & 1;
> > +    assert(cc == 1);
> > +
> > +    return EXIT_SUCCESS;
> > +}
> 
> This also fails with Clang 15:
> tests/tcg/s390x/rxsbg.c:15:9: error: invalid operand for instruction
>      asm("rxsbg %[r1],%[r2],177,43,228\n"
>          ^
> <inline asm>:1:23: note: instantiated into assembly here
>          rxsbg %r1,%r2,177,43,228
>                               ^
> 
>   Thomas
> 

This seems to be a clang bug. PoP says:

    Bit 1 of the I3 field and bits 0-1 of the I4 field (bits 17
    and 24-25 of the instruction) are reserved and should
    contain zeros; otherwise, the program may not oper-
    ate compatibly in the future. Bits 0-1 of the I5 field
    (bits 32-33 of the instruction) are ignored.

But LLVM has:

    imm32zx8:$I4, imm32zx6:$I5

which looks like a mixup (should be imm32zx6 + imm32zx8 IMHO).

I guess there is not much we can do about this at the moment, so I will
choose another constant for the test and send a v2.


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

end of thread, other threads:[~2023-03-15 18:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14 23:34 [PATCH 0/2] target/s390x: Fix R[NOX]SBG with T=1 Ilya Leoshkevich
2023-03-14 23:34 ` [PATCH 1/2] " Ilya Leoshkevich
2023-03-15  8:59   ` David Hildenbrand
2023-03-14 23:34 ` [PATCH 2/2] tests/tcg/s390x: Add rxsbg.c Ilya Leoshkevich
2023-03-15 18:12   ` Thomas Huth
2023-03-15 18:30     ` Ilya Leoshkevich

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.