diff mbox series

[v2,2/2] tests/tcg/s390x: Add C(G)HRL test

Message ID 20230308210226.2847503-3-nsg@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series target/s390x: Fix emulation of C(G)HRL | expand

Commit Message

Nina Schoetterl-Glausch March 8, 2023, 9:02 p.m. UTC
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.

Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
---


I don't know what the coding style is for inline asm.
checkpatch.sh complains about the tabs inside the asm, which I find a
bit surprising given they're inside a string.
IMO emitting tabs makes sense in order to be consistent with gcc output.
I left the tabs in for now, but can remove them.


 tests/tcg/s390x/chrl.c          | 76 +++++++++++++++++++++++++++++++++
 tests/tcg/s390x/Makefile.target |  1 +
 2 files changed, 77 insertions(+)
 create mode 100644 tests/tcg/s390x/chrl.c

Comments

Richard Henderson March 8, 2023, 10:49 p.m. UTC | #1
On 3/8/23 13:02, Nina Schoetterl-Glausch wrote:
> 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.
> 
> Signed-off-by: Nina Schoetterl-Glausch<nsg@linux.ibm.com>
> ---

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
Thomas Huth March 9, 2023, 1:47 p.m. UTC | #2
On 08/03/2023 22.02, Nina Schoetterl-Glausch wrote:
> 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.
> 
> Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
> ---
> 
> 
> I don't know what the coding style is for inline asm.
> checkpatch.sh complains about the tabs inside the asm, which I find a
> bit surprising given they're inside a string.
> IMO emitting tabs makes sense in order to be consistent with gcc output.
> I left the tabs in for now, but can remove them.

I don't mind too much, but all the other files use spaces, not tabs, so I 
think it's maybe best to also use spaces here for consistency?

  Thomas
Nina Schoetterl-Glausch March 9, 2023, 2:55 p.m. UTC | #3
On Thu, 2023-03-09 at 14:47 +0100, Thomas Huth wrote:
> On 08/03/2023 22.02, Nina Schoetterl-Glausch wrote:
> > 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.
> > 
> > Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
> > ---
> > 
> > 
> > I don't know what the coding style is for inline asm.
> > checkpatch.sh complains about the tabs inside the asm, which I find a
> > bit surprising given they're inside a string.
> > IMO emitting tabs makes sense in order to be consistent with gcc output.
> > I left the tabs in for now, but can remove them.
> 
> I don't mind too much, but all the other files use spaces, not tabs, so I 
> think it's maybe best to also use spaces here for consistency?

Seems pretty inconsistent. Sometimes \t is used everywhere, sometimes some number of spaces.
I'll put \n\t at the end of lines, put the labels on a separate line and use a single space
between the mnemonic and the operands.
> 
>   Thomas
>
diff mbox series

Patch

diff --git a/tests/tcg/s390x/chrl.c b/tests/tcg/s390x/chrl.c
new file mode 100644
index 0000000000..fa33d43c59
--- /dev/null
+++ b/tests/tcg/s390x/chrl.c
@@ -0,0 +1,76 @@ 
+#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:	.short	1,0x8000\n"
+        "	.popsection\n"
+
+        "	chrl	%[r],0b\n"
+        "	ipm	%[program_mask]\n"
+        : [program_mask] "=r" (program_mask)
+        : [r] "r" (1)
+    );
+
+    cc = program_mask >> 28;
+    assert(!cc);
+
+    asm volatile (
+               ".pushsection .rodata\n"
+        "0:	.short	-1,0x8000\n"
+        "	.popsection\n"
+
+        "	chrl	%[r],0b\n"
+        "	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:	.short	1,0x8000,0,0\n"
+        "	.popsection\n"
+
+        "	cghrl	%[r],0b\n"
+        "	ipm	%[program_mask]\n"
+        : [program_mask] "=r" (program_mask)
+        : [r] "r" (1L)
+    );
+
+    cc = program_mask >> 28;
+    assert(!cc);
+
+    asm volatile (
+               ".pushsection .rodata\n"
+        "0:	.short	-1,0x8000,0,0\n"
+        "	.popsection\n"
+
+        "	cghrl	%[r],0b\n"
+        "	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;
+}
diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 72ad309b27..a3d3beeffe 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -28,6 +28,7 @@  TESTS+=div
 TESTS+=clst
 TESTS+=long-double
 TESTS+=cdsg
+TESTS+=chrl
 
 cdsg: CFLAGS+=-pthread
 cdsg: LDFLAGS+=-pthread