tests/tcg: Vector instruction tests for target/s390x
v2 cover tests/tcg: Vector instruction tests for target/s390x
As I currently work on vector instruction support for s390x/tcg, for now I wrote my tests for kvm-unit-tests, but tests/tcg seems to be a better fit. The only tricky part is testing interrupt handling, but that also seems to be possible using some signal hackery.
This is only one test to discuss if the approach make sense. These patches only work when applied on top of:
https://github.com/davidhildenbrand/qemu/tree/vx
Before I go ahead and implement more tests, let's clarify if this is the way to go first.
RFC -> RFCv2:
- Dropped "tests/tcg: Allow targets to set the optimization level" -- Handle it directly from the Makefile
- Add a test for VECTOR GATHER ELEMENT
- Rework signal handling to work with more than one signal occurrence. Also simplify setting the signal handlers a bit.
David Hildenbrand (2):
tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT tests/tcg: target/s390x: Test VECTOR LOAD GR FROM VR ELEMENT
tests/tcg/s390x/Makefile.target | 7 +++ tests/tcg/s390x/helper.h | 28 +++++++++++ tests/tcg/s390x/signal-helper.inc.c | 46 ++++++++++++++++++ tests/tcg/s390x/vge.c | 75 +++++++++++++++++++++++++++++ tests/tcg/s390x/vlgv.c | 37 ++++++++++++++ 5 files changed, 193 insertions(+) create mode 100644 tests/tcg/s390x/helper.h create mode 100644 tests/tcg/s390x/signal-helper.inc.c create mode 100644 tests/tcg/s390x/vge.c create mode 100644 tests/tcg/s390x/vlgv.c
Signature · 1 line
2.17.2
PATCH v2 2/2 tests/tcg: target/s390x: Test VECTOR LOAD GR FROM VR ELEMENT
Reuse the existing helpers.
--- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/helper.h | 6 ++++++ tests/tcg/s390x/vlgv.c | 37 +++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 tests/tcg/s390x/vlgv.c
tests/tcg/s390x/Makefile.target +1 -0
@@ -8,6 +8,7 @@ TESTS+=exrl-trtr TESTS+=pack VECTOR_TESTS=vge +VECTOR_TESTS+=vlgv TESTS+=$(VECTOR_TESTS) #enable vectors and optimisation for vector tests
tests/tcg/s390x/helper.h +6 -0
@@ -11,6 +11,12 @@ typedef union S390Vector {uint8_t h[16 ]; } S390Vector; +#define ES_8 0 +#define ES_16 1 +#define ES_32 2 +#define ES_64 3 +#define ES_128 4 +static inline void check (const char *s,bool cond) {if (!cond) {
tests/tcg/s390x/vlgv.c new file +37 -0
@@ -0,0 +1,37 @@ +#include <stdint.h> +#include <unistd.h> +#include "signal-helper.inc.c" + +static inline void vlgv (uint64_t *r1,S390Vector *v3,const void *a2, +uint8_t m4) +{ + asmvolatile ("vlgv %[r1], %[v3], 0(%[a2]), %[m4]\n" + : [r1]"+d" (*r1), + [v3]"+v" (v3->v) + : [a2]"d" (a2), + [m4]"i" (m4)); +} + +int main (void ) +{ +S390Vector v3 = { + .q[0 ] =0x0011223344556677ull , + .q[1 ] =0x8899aabbccddeeffull , + }; +uint64_t r1 =0 ; + +/* Directly set all ignored bits to */ +vlgv (&r1, &v3, (void *)(7 | ~0xf ),ES_8 ); +check ("8 bit" , r1 ==0x77 ); +vlgv (&r1, &v3, (void *)(4 | ~0x7 ),ES_16 ); +check ("16 bit" , r1 ==0x8899 ); +vlgv (&r1, &v3, (void *)(3 | ~0x3 ),ES_32 ); +check ("32 bit" , r1 ==0xccddeeff ); +vlgv (&r1, &v3, (void *)(1 | ~0x1 ),ES_64 ); +check ("64 bit" , r1 ==0x8899aabbccddeeffull ); +check ("v3 not modified" , v3.q[0 ] ==0x0011223344556677ull && + v3.q[1 ] ==0x8899aabbccddeeffull ); + +CHECK_SIGILL (vlgv (&r1, &v3,NULL ,ES_128 )); +return 0 ; +}
Signature · 1 line
2.17.2
PATCH v2 1/2 tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT
In reply to David HildenbrandAs want to make use of vectors in constraints of inline asm statements, use -march=z13. To make it compile, use a reasonable optimization level (-O2).
Add some infrastructure for checking if SIGILL will be properly triggered. Take care of manually unblocking the signal before doing the longjmp, otherwise it will remain blocked and eventually lead to the default handler getting executed on the next signal.
Use "signal" for now although checkpatch complains about portability. We only care about linux for s390x. If that ever changes, I'll happly convert it ;)
--- tests/tcg/s390x/Makefile.target | 6 +++ tests/tcg/s390x/helper.h | 22 +++++++++ tests/tcg/s390x/signal-helper.inc.c | 46 ++++++++++++++++++ tests/tcg/s390x/vge.c | 75 +++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 tests/tcg/s390x/helper.h create mode 100644 tests/tcg/s390x/signal-helper.inc.c create mode 100644 tests/tcg/s390x/vge.c
tests/tcg/s390x/Makefile.target +6 -0
@@ -6,3 +6,9 @@ TESTS+=ipm TESTS+=exrl-trt TESTS+=exrl-trtr TESTS+=pack + +VECTOR_TESTS=vge +TESTS+=$(VECTOR_TESTS) + +#enable vectors and optimisation for vector tests +$(VECTOR_TESTS): CFLAGS+=-march=z13 -O2
tests/tcg/s390x/helper.h new file +22 -0
@@ -0,0 +1,22 @@ +#ifndef TEST_TCG_S390x_VECTOR_H +#define TEST_TCG_S390x_VECTOR_H + +#include <stdint.h> + +typedef union S390Vector { +__uint128_t v; +uint64_t q[2 ]; +uint32_t d[4 ]; +uint16_t w[8 ]; +uint8_t h[16 ]; +}S390Vector ; + +static inline void check (const char *s,bool cond) +{ +if (!cond) { +fprintf (stderr,"Check failed: %s\n" , s); +exit (-1 ); + } +} + +#endif /* TEST_TCG_S390x_VECTOR_H */
tests/tcg/s390x/signal-helper.inc.c new file +46 -0
46 lines not on this page · raw message
tests/tcg/s390x/vge.c new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.17.2
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH RFCv2 0/2] tests/tcg: Vector instruction tests for target/s390x
Type: series
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'455444cf7e tests/tcg: target/s390x: Test VECTOR LOAD GR FROM VR ELEMENT 2fb17c4fd7 tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT
=== OUTPUT BEGIN ===
1/2 Checking commit 2fb17c4fd731 (tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #38:
new file mode 100644
ERROR: use sigaction to establish signal handlers; signal is not portable #106: FILE: tests/tcg/s390x/signal-helper.inc.c:36:
+ if (signal(SIGILL, handle_sigill) == SIG_ERR) { \
total: 1 errors, 1 warnings, 152 lines checked
Patch 1/2 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
2/2 Checking commit 455444cf7e30 (tests/tcg: target/s390x: Test VECTOR LOAD GR FROM VR ELEMENT)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#42:
new file mode 100644
total: 0 errors, 1 warnings, 56 lines checked
Patch 2/2 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]
Re: [Qemu-devel] [PATCH RFC2 1/2] tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT
In reply to David HildenbrandQuoted 44 lines · David Hildenbrand
As want to make use of vectors in constraints of inline asm statements, use -march=z13. To make it compile, use a reasonable optimization level (-O2).
Add some infrastructure for checking if SIGILL will be properly triggered. Take care of manually unblocking the signal before doing the longjmp, otherwise it will remain blocked and eventually lead to the default handler getting executed on the next signal.
Use "signal" for now although checkpatch complains about portability. We only care about linux for s390x. If that ever changes, I'll happly convert it ;)
Signed-off-by David Hildenbrand <[email protected]>--- tests/tcg/s390x/Makefile.target | 6 +++ tests/tcg/s390x/helper.h | 22 +++++++++ tests/tcg/s390x/signal-helper.inc.c | 46 ++++++++++++++++++ tests/tcg/s390x/vge.c | 75 +++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 tests/tcg/s390x/helper.h create mode 100644 tests/tcg/s390x/signal-helper.inc.c create mode 100644 tests/tcg/s390x/vge.ctests/tcg/s390x/Makefile.target +6
-0@@ -6,3 +6,9 @@ TESTS+=ipm TESTS+=exrl-trt TESTS+=exrl-trtr TESTS+=pack + +VECTOR_TESTS=vge +TESTS+=$(VECTOR_TESTS) + +#enable vectors and optimisation for vector tests +$(VECTOR_TESTS): CFLAGS+=-march=z13 -O2tests/tcg/s390x/helper.h new file +0
-0
tests/tcg/s390x/helper.h line 2
Quoted 2 lines
tests/tcg/s390x/helper.h new file +2
-0@@ -0,0 +1,22 @@ +#ifndef TEST_TCG_S390x_VECTOR_H +#define TEST_TCG_S390x_VECTOR_H
s/TEST_TCG_S390x_VECTOR_H/TEST_TCG_S390X_HELPER_H/
Quoted 62 lines
tests/tcg/s390x/helper.h new file +20
-0+ +#include <stdint.h> + +typedef union S390Vector { +__uint128_t v; +uint64_t q[2 ]; +uint32_t d[4 ]; +uint16_t w[8 ]; +uint8_t h[16 ]; +}S390Vector ; + +static inline void check (const char *s,bool cond) +{ +if (!cond) { +fprintf (stderr,"Check failed: %s\n" , s); +exit (-1 ); + } +} + +#endif /* TEST_TCG_S390x_VECTOR_H */ tests/tcg/s390x/signal-helper.inc.c new file +36
-0@@ -0,0 +1,46 @@ +#include <stdlib.h> +#include <stdio.h> +#include <stdbool.h> +#include <signal.h> +#include <setjmp.h> +#include <errno.h> +#include "helper.h" + +jmp_buf jmp_env; + +static int signal_unblock (int sig) +{ +sigset_t intmask; + +if (sigemptyset (&intmask) || +sigaddset (&intmask, sig) || +sigprocmask (SIG_UNBLOCK , &intmask,NULL )) { +return -errno; + } +return 0 ; +} + +static void handle_sigill (int sig) +{ +if (sig !=SIGILL ) { +check ("Wrong signal received" , false); + } +if (signal_unblock (sig)) { +check ("Cannot unblock signal" , false); + } +longjmp (jmp_env,1 ); +} + +#define CHECK_SIGILL (STATEMENT ) \ +do { \ + if (signal(SIGILL, handle_sigill) == SIG_ERR) { \
tests/tcg/s390x/signal-helper.inc.c line 46
Quoted 10 lines
tests/tcg/s390x/signal-helper.inc.c new file +10
-0+check ("SIGILL not registered" , false); \ + } \ +if (setjmp (jmp_env) ==0 ) { \ +STATEMENT ; \ +check ("SIGILL not triggered" , false); \ + } \ +if (signal (SIGILL ,SIG_DFL ) ==SIG_ERR ) { \ +check ("SIGILL not registered" , false); \ + } \ +}while (0 )
So, this now boils down to (thanks Richard)
+jmp_buf jmp_env;
+
+static void handle_sigill(int sig)
+{
+ if (sig != SIGILL) {
+ check("Wrong signal received", false);
+ }
+ siglongjmp(jmp_env, 1);
+}
+
+#define CHECK_SIGILL(STATEMENT) \
+do { \
+ if (signal(SIGILL, handle_sigill) == SIG_ERR) { \
+ check("SIGILL not registered", false); \
+ } \
+ if (sigsetjmp(jmp_env, 1) == 0) { \
+ STATEMENT; \
+ check("SIGILL not triggered", false); \
+ } \
+ if (signal(SIGILL, SIG_DFL) == SIG_ERR) { \
+ check("SIGILL not registered", false); \
+ } \+} while (0)
Quoted 60 lines
tests/tcg/s390x/vge.c new file +54
-0@@ -0,0 +1,75 @@ +#include <stdint.h> +#include <unistd.h> +#include "signal-helper.inc.c" + +static inline void vgef (S390Vector *v1,S390Vector *v2,const void *a2, +uint8_t m3) +{ + asmvolatile ("vgef %[v1], 0(%[v2], %[a2]), %[m3]\n" + : [v1]"+v" (v1->v), + [v2]"+v" (v2->v) + : [a2]"d" (a2), + [m3]"i" (m3)); +} + +static void test_vgef (void ) +{ +uint32_t data =0x12345678ul ; +S390Vector v1 = { + .q[0 ] =-1ull , + .q[1 ] =-1ull , + }; +S390Vector v2 = { + .d[0 ] =-1 , + .d[1 ] =-1 , + .d[2 ] =56789 , + .d[3 ] =-1 , + }; + +/* load vector element number 2 with the data */ +vgef (&v1, &v2, (uint32_t *)((uint8_t *)&data -56789 ),2 ); +check ("vgef: element loaded" , v1.d[2 ] == data); +check ("vgef: elements unmodified" , v1.d[0 ] ==-1 && v1.d[1 ] ==-1 && + v1.d[3 ] ==-1 ); + +/* invalid element number */ +CHECK_SIGILL (vgef (&v1, &v2,0 ,4 )); +} + +static inline void vgeg (S390Vector *v1,S390Vector *v2,const void *a2, +uint8_t m3) +{ + asmvolatile ("vgeg %[v1], 0(%[v2], %[a2]), %[m3]\n" + : [v1]"+v" (v1->v), + [v2]"+v" (v2->v) + : [a2]"d" (a2), + [m3]"i" (m3)); +} + +static void test_vgeg (void ) +{ +uint64_t data =0x123456789abcdefull ; +S390Vector v1 = { + .q[0 ] =-1ull , + .q[1 ] =-1ull ,
tests/tcg/s390x/vge.c line 64
Quoted 10 lines
tests/tcg/s390x/vge.c new file +10
-0+ }; +S390Vector v2 = { + .q[0 ] =-1ull , + .q[1 ] =56789 , + }; + +/* load vector element number 1 with the data */ +vgeg (&v1, &v2, (uint64_t *)((uint8_t *)&data -56789 ),1 ); +check ("vgef: element loaded" , v1.q[1 ] == data); +check ("vgef: elements unmodified" , v1.q[0 ] ==-1ull );
s/vgef/vgeg/
tests/tcg/s390x/vge.c line 75
Quoted 12 lines
tests/tcg/s390x/vge.c new file +11
-0+ +/* invalid element number */ +CHECK_SIGILL (vgeg (&v1, &v2,0 ,2 )); +} + +int main (void ) +{ +test_vgef (); +test_vgeg (); +return 0 ; +}
(reviewing my own code :) )
Signature · 3 lines
Thanks, David / dhildenb