Skip to contentSkip to conversation

target/s390x: Fix emulation of C(G)HRL

PATCH In review Nina Schoetterl-Glausch 2 participants 5 messages Mar 10, 2023

lore
Share & tools
lore
#0 lore raw

v3 cover target/s390x: Fix emulation of C(G)HRL

The second operand of COMPARE HALFWORD RELATIVE LONG is a signed halfword, it does not have the same size as the first operand. Fix this and add a tcg test for c(g)hrl.

v2 -> v3
* pick up R-b's (thanks Richard)
* get rid of tabs in inline asm (cosmetic only)

v1 -> v2
* rebase on newer version

Nina Schoetterl-Glausch (2):
target/s390x: Fix emulation of C(G)HRL
tests/tcg/s390x: Add C(G)HRL test

 target/s390x/tcg/insn-data.h.inc |  4 +-
 target/s390x/tcg/translate.c     |  7 +++
 tests/tcg/s390x/chrl.c           | 80 ++++++++++++++++++++++++++++++++
 tests/tcg/s390x/Makefile.target  |  1 +
 4 files changed, 90 insertions(+), 2 deletions(-)
 create mode 100644 tests/tcg/s390x/chrl.c

Range-diff against v2:
1: 228a1d9cfb ! 1: 899db74823 target/s390x: Fix emulation of C(G)HRL
@@ Commit message
halfword, it does not have the same size as the first operand.

Fixes a7e836d5eb ("target-s390: Convert COMPARE, COMPARE LOGICAL")

+ Reviewed-by: Richard Henderson <[email protected]>

## target/s390x/tcg/insn-data.h.inc ##
2: 3b1ca6b682 ! 2: 30868c4692 tests/tcg/s390x: Add C(G)HRL test

    @@ Commit message
         instruction.
         Test the sign extension performed on the second operand.
     
    +    Reviewed-by: Richard Henderson <[email protected]>
         Signed-off-by: Nina Schoetterl-Glausch <[email protected]>
     
      ## tests/tcg/s390x/chrl.c (new) ##
    @@ tests/tcg/s390x/chrl.c (new)
     +    uint32_t program_mask, cc;
     +
     +    asm volatile (
    -+               ".pushsection .rodata\n"
    -+        "0:	.short	1,0x8000\n"
    -+        "	.popsection\n"
    ++        ".pushsection .rodata\n"
    ++        "0:\n\t"
    ++        ".short 1, 0x8000\n\t"
    ++        ".popsection\n\t"
     +
    -+        "	chrl	%[r],0b\n"
    -+        "	ipm	%[program_mask]\n"
    ++        "chrl %[r], 0b\n\t"
    ++        "ipm %[program_mask]\n"
     +        : [program_mask] "=r" (program_mask)
     +        : [r] "r" (1)
     +    );
    @@ tests/tcg/s390x/chrl.c (new)
     +    assert(!cc);
     +
     +    asm volatile (
    -+               ".pushsection .rodata\n"
    -+        "0:	.short	-1,0x8000\n"
    -+        "	.popsection\n"
    ++        ".pushsection .rodata\n"
    ++        "0:\n\t"
    ++        ".short -1, 0x8000\n\t"
    ++        ".popsection\n\t"
     +
    -+        "	chrl	%[r],0b\n"
    -+        "	ipm	%[program_mask]\n"
    ++        "chrl %[r], 0b\n\t"
    ++        "ipm %[program_mask]\n"
     +        : [program_mask] "=r" (program_mask)
     +        : [r] "r" (-1)
     +    );
    @@ tests/tcg/s390x/chrl.c (new)
     +    uint32_t program_mask, cc;
     +
     +    asm volatile (
    -+               ".pushsection .rodata\n"
    -+        "0:	.short	1,0x8000,0,0\n"
    -+        "	.popsection\n"
    ++        ".pushsection .rodata\n"
    ++        "0:\n\t"
    ++        ".short 1, 0x8000, 0, 0\n\t"
    ++        ".popsection\n\t"
     +
    -+        "	cghrl	%[r],0b\n"
    -+        "	ipm	%[program_mask]\n"
    ++        "cghrl %[r], 0b\n\t"
    ++        "ipm %[program_mask]\n"
     +        : [program_mask] "=r" (program_mask)
     +        : [r] "r" (1L)
     +    );
    @@ tests/tcg/s390x/chrl.c (new)
     +    assert(!cc);
     +
     +    asm volatile (
    -+               ".pushsection .rodata\n"
    -+        "0:	.short	-1,0x8000,0,0\n"
    -+        "	.popsection\n"
    ++        ".pushsection .rodata\n"
    ++        "0:\n\t"
    ++        ".short -1, 0x8000, 0, 0\n\t"
    ++        ".popsection\n\t"
     +
    -+        "	cghrl	%[r],0b\n"
    -+        "	ipm	%[program_mask]\n"
    ++        "cghrl %[r], 0b\n\t"
    ++        "ipm %[program_mask]\n"
     +        : [program_mask] "=r" (program_mask)
     +        : [r] "r" (-1L)
     +    );

base-commit: 15002921e878e6cf485f655d580733b5319ea015

Signature · 1 line
2.39.1
#1 lore raw

PATCH v3 1/2 target/s390x: Fix emulation of C(G)HRL

The second operand of COMPARE HALFWORD RELATIVE LONG is a signed halfword, it does not have the same size as the first operand.

Fixes a7e836d5eb ("target-s390: Convert COMPARE, COMPARE LOGICAL")
---
 target/s390x/tcg/insn-data.h.inc | 4 ++--
 target/s390x/tcg/translate.c     | 7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)
target/s390x/tcg/insn-data.h.inc +2 -2
index 9d2d35f084..6fe8ca5143 100644
@@ -199,8 +199,8 @@
     C(0xe55c, CHSI,    SIL,   GIE, m1_32s, i2, 0, 0, 0, cmps64)
     C(0xe558, CGHSI,   SIL,   GIE, m1_64, i2, 0, 0, 0, cmps64)
 /* COMPARE HALFWORD RELATIVE LONG */
-    C(0xc605, CHRL,    RIL_b, GIE, r1_o, mri2_32s, 0, 0, 0, cmps32)
-    C(0xc604, CGHRL,   RIL_b, GIE, r1_o, mri2_64, 0, 0, 0, cmps64)
+    C(0xc605, CHRL,    RIL_b, GIE, r1_o, mri2_16s, 0, 0, 0, cmps32)
+    C(0xc604, CGHRL,   RIL_b, GIE, r1_o, mri2_16s, 0, 0, 0, cmps64)
 /* COMPARE HIGH */
     C(0xb9cd, CHHR,    RRE,   HW,  r1_sr32, r2_sr32, 0, 0, 0, cmps32)
     C(0xb9dd, CHLR,    RRE,   HW,  r1_sr32, r2_o, 0, 0, 0, cmps32)
target/s390x/tcg/translate.c +7 -0
index 21a57d5eb2..d324c0b6f2 100644
@@ -5979,6 +5979,13 @@ static void in2_m2_64a(DisasContext *s, DisasOps *o)
 #define SPEC_in2_m2_64a 0
 #endif
 
+static void in2_mri2_16s(DisasContext *s, DisasOps *o)
+{
+    o->in2 = tcg_temp_new_i64();
+    tcg_gen_qemu_ld16s(o->in2, gen_ri2(s), get_mem_index(s));
+}
+#define SPEC_in2_mri2_16s 0
+
 static void in2_mri2_16u(DisasContext *s, DisasOps *o)
 {
     o->in2 = tcg_temp_new_i64();
Signature · 1 line
2.39.1
Reviewed-by on v3 1/2
#2 lore raw
Quoted 7 lines · Nina Schoetterl-Glausch

The second operand of COMPARE HALFWORD RELATIVE LONG is a signed halfword, it does not have the same size as the first operand.

Fixes a7e836d5eb ("target-s390: Convert COMPARE, COMPARE LOGICAL")

---

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw

PATCH v3 2/2 tests/tcg/s390x: Add C(G)HRL test

In reply to Nina Schoetterl-Glausch

Test COMPARE HALFWORD RELATIVE LONG instructions.
Test that the bytes following the second operand do not affect the instruction.
Test the sign extension performed on the second operand.

---
 tests/tcg/s390x/chrl.c          | 80 +++++++++++++++++++++++++++++++++
 tests/tcg/s390x/Makefile.target |  1 +
 2 files changed, 81 insertions(+)
 create mode 100644 tests/tcg/s390x/chrl.c
tests/tcg/s390x/chrl.c new file +80 -0
new file mode 100644
index 0000000000..b1c3a1c561
@@ -0,0 +1,80 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <stdint.h>
+
+static void test_chrl(void)
+{
+    uint32_t program_mask, cc;
+
+    asm volatile (
+        ".pushsection .rodata\n"
+        "0:\n\t"
+        ".short 1, 0x8000\n\t"
+        ".popsection\n\t"
+
+        "chrl %[r], 0b\n\t"
+        "ipm %[program_mask]\n"
+        : [program_mask] "=r" (program_mask)
+        : [r] "r" (1)
+    );
+
+    cc = program_mask >> 28;
+    assert(!cc);
+
+    asm volatile (
+        ".pushsection .rodata\n"
+        "0:\n\t"
+        ".short -1, 0x8000\n\t"
+        ".popsection\n\t"
+
+        "chrl %[r], 0b\n\t"
+        "ipm %[program_mask]\n"
+        : [program_mask] "=r" (program_mask)
+        : [r] "r" (-1)
+    );
+
+    cc = program_mask >> 28;
+    assert(!cc);
+}
+
+static void test_cghrl(void)
+{
+    uint32_t program_mask, cc;
+
+    asm volatile (
+        ".pushsection .rodata\n"
+        "0:\n\t"
+        ".short 1, 0x8000, 0, 0\n\t"
+        ".popsection\n\t"
+
+        "cghrl %[r], 0b\n\t"
+        "ipm %[program_mask]\n"
+        : [program_mask] "=r" (program_mask)
+        : [r] "r" (1L)
+    );
+
+    cc = program_mask >> 28;
+    assert(!cc);
+
+    asm volatile (
+        ".pushsection .rodata\n"
+        "0:\n\t"
+        ".short -1, 0x8000, 0, 0\n\t"
+        ".popsection\n\t"
+
+        "cghrl %[r], 0b\n\t"
+        "ipm %[program_mask]\n"
+        : [program_mask] "=r" (program_mask)
+        : [r] "r" (-1L)
+    );
+
+    cc = program_mask >> 28;
+    assert(!cc);
+}
+
+int main(void)
+{
+    test_chrl();
+    test_cghrl();
+    return EXIT_SUCCESS;
+}
tests/tcg/s390x/Makefile.target +1 -0
index 72ad309b27..a3d3beeffe 100644
@@ -28,6 +28,7 @@ TESTS+=div
 TESTS+=clst
 TESTS+=long-double
 TESTS+=cdsg
+TESTS+=chrl
 
 cdsg: CFLAGS+=-pthread
 cdsg: LDFLAGS+=-pthread
Signature · 1 line
2.39.1
Reviewed-by on v3 2/2
#4 lore raw

Re: [PATCH v3 2/2] tests/tcg/s390x: Add C(G)HRL test

Quoted 8 lines · Nina Schoetterl-Glausch

Test COMPARE HALFWORD RELATIVE LONG instructions.
Test that the bytes following the second operand do not affect the instruction.
Test the sign extension performed on the second operand.

---

Signature · 3 lines
Thanks,

David / dhildenb