All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH RFCv2 0/2] tests/tcg: Vector instruction tests for target/s390x
@ 2019-02-27 21:15 David Hildenbrand
  2019-02-27 21:15 ` [Qemu-devel] [PATCH RFC2 1/2] tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT David Hildenbrand
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: David Hildenbrand @ 2019-02-27 21:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-s390x, Thomas Huth, Cornelia Huck, Richard Henderson,
	Alex Bennée, Philippe Mathieu-Daudé,
	David Hildenbrand

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

-- 
2.17.2

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

* [Qemu-devel] [PATCH RFC2 1/2] tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT
  2019-02-27 21:15 [Qemu-devel] [PATCH RFCv2 0/2] tests/tcg: Vector instruction tests for target/s390x David Hildenbrand
@ 2019-02-27 21:15 ` David Hildenbrand
  2019-02-28  7:22   ` David Hildenbrand
  2019-02-27 21:15 ` [Qemu-devel] [PATCH RFC2 2/2] tests/tcg: target/s390x: Test VECTOR LOAD GR FROM VR ELEMENT David Hildenbrand
  2019-02-27 21:23 ` [Qemu-devel] [PATCH RFCv2 0/2] tests/tcg: Vector instruction tests for target/s390x no-reply
  2 siblings, 1 reply; 5+ messages in thread
From: David Hildenbrand @ 2019-02-27 21:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-s390x, Thomas Huth, Cornelia Huck, Richard Henderson,
	Alex Bennée, Philippe Mathieu-Daudé,
	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 <david@redhat.com>
---
 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

diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 151dc075aa..474c2428bd 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -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
diff --git a/tests/tcg/s390x/helper.h b/tests/tcg/s390x/helper.h
new file mode 100644
index 0000000000..ecbd97519b
--- /dev/null
+++ b/tests/tcg/s390x/helper.h
@@ -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 */
diff --git a/tests/tcg/s390x/signal-helper.inc.c b/tests/tcg/s390x/signal-helper.inc.c
new file mode 100644
index 0000000000..c214356ca1
--- /dev/null
+++ b/tests/tcg/s390x/signal-helper.inc.c
@@ -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) {     \
+        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)
diff --git a/tests/tcg/s390x/vge.c b/tests/tcg/s390x/vge.c
new file mode 100644
index 0000000000..7760be3a1b
--- /dev/null
+++ b/tests/tcg/s390x/vge.c
@@ -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)
+{
+    asm volatile("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)
+{
+    asm volatile("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,
+    };
+    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);
+
+    /* invalid element number */
+    CHECK_SIGILL(vgeg(&v1, &v2, 0, 2));
+}
+
+int main(void)
+{
+    test_vgef();
+    test_vgeg();
+    return 0;
+}
-- 
2.17.2

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

* [Qemu-devel] [PATCH RFC2 2/2] tests/tcg: target/s390x: Test VECTOR LOAD GR FROM VR ELEMENT
  2019-02-27 21:15 [Qemu-devel] [PATCH RFCv2 0/2] tests/tcg: Vector instruction tests for target/s390x David Hildenbrand
  2019-02-27 21:15 ` [Qemu-devel] [PATCH RFC2 1/2] tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT David Hildenbrand
@ 2019-02-27 21:15 ` David Hildenbrand
  2019-02-27 21:23 ` [Qemu-devel] [PATCH RFCv2 0/2] tests/tcg: Vector instruction tests for target/s390x no-reply
  2 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand @ 2019-02-27 21:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-s390x, Thomas Huth, Cornelia Huck, Richard Henderson,
	Alex Bennée, Philippe Mathieu-Daudé,
	David Hildenbrand

Reuse the existing helpers.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 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

diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 474c2428bd..deffc4c525 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -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
diff --git a/tests/tcg/s390x/helper.h b/tests/tcg/s390x/helper.h
index ecbd97519b..790ced7ad7 100644
--- a/tests/tcg/s390x/helper.h
+++ b/tests/tcg/s390x/helper.h
@@ -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) {
diff --git a/tests/tcg/s390x/vlgv.c b/tests/tcg/s390x/vlgv.c
new file mode 100644
index 0000000000..2a4cca3bbb
--- /dev/null
+++ b/tests/tcg/s390x/vlgv.c
@@ -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)
+{
+    asm volatile("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;
+}
-- 
2.17.2

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

* Re: [Qemu-devel] [PATCH RFCv2 0/2] tests/tcg: Vector instruction tests for target/s390x
  2019-02-27 21:15 [Qemu-devel] [PATCH RFCv2 0/2] tests/tcg: Vector instruction tests for target/s390x David Hildenbrand
  2019-02-27 21:15 ` [Qemu-devel] [PATCH RFC2 1/2] tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT David Hildenbrand
  2019-02-27 21:15 ` [Qemu-devel] [PATCH RFC2 2/2] tests/tcg: target/s390x: Test VECTOR LOAD GR FROM VR ELEMENT David Hildenbrand
@ 2019-02-27 21:23 ` no-reply
  2 siblings, 0 replies; 5+ messages in thread
From: no-reply @ 2019-02-27 21:23 UTC (permalink / raw)
  To: david; +Cc: fam, qemu-devel, thuth, cohuck, f4bug, qemu-s390x, alex.bennee, rth

Patchew URL: https://patchew.org/QEMU/20190227211525.2470-1-david@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Message-id: 20190227211525.2470-1-david@redhat.com
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/20190227211525.2470-1-david@redhat.com -> patchew/20190227211525.2470-1-david@redhat.com
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/20190227211525.2470-1-david@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

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

* Re: [Qemu-devel] [PATCH RFC2 1/2] tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT
  2019-02-27 21:15 ` [Qemu-devel] [PATCH RFC2 1/2] tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT David Hildenbrand
@ 2019-02-28  7:22   ` David Hildenbrand
  0 siblings, 0 replies; 5+ messages in thread
From: David Hildenbrand @ 2019-02-28  7:22 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-s390x, Thomas Huth, Cornelia Huck, Richard Henderson,
	Alex Bennée, Philippe Mathieu-Daudé

On 27.02.19 22:15, David Hildenbrand wrote:
> 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 <david@redhat.com>
> ---
>  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
> 
> diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
> index 151dc075aa..474c2428bd 100644
> --- a/tests/tcg/s390x/Makefile.target
> +++ b/tests/tcg/s390x/Makefile.target
> @@ -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
> diff --git a/tests/tcg/s390x/helper.h b/tests/tcg/s390x/helper.h
> new file mode 100644
> index 0000000000..ecbd97519b
> --- /dev/null
> +++ b/tests/tcg/s390x/helper.h
> @@ -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/

> +
> +#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 */
> diff --git a/tests/tcg/s390x/signal-helper.inc.c b/tests/tcg/s390x/signal-helper.inc.c
> new file mode 100644
> index 0000000000..c214356ca1
> --- /dev/null
> +++ b/tests/tcg/s390x/signal-helper.inc.c
> @@ -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) {     \
> +        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)


> diff --git a/tests/tcg/s390x/vge.c b/tests/tcg/s390x/vge.c
> new file mode 100644
> index 0000000000..7760be3a1b
> --- /dev/null
> +++ b/tests/tcg/s390x/vge.c
> @@ -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)
> +{
> +    asm volatile("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)
> +{
> +    asm volatile("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,
> +    };
> +    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/

> +
> +    /* invalid element number */
> +    CHECK_SIGILL(vgeg(&v1, &v2, 0, 2));
> +}
> +
> +int main(void)
> +{
> +    test_vgef();
> +    test_vgeg();
> +    return 0;
> +}
> 

(reviewing my own code :) )

-- 

Thanks,

David / dhildenb

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

end of thread, other threads:[~2019-02-28  7:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-27 21:15 [Qemu-devel] [PATCH RFCv2 0/2] tests/tcg: Vector instruction tests for target/s390x David Hildenbrand
2019-02-27 21:15 ` [Qemu-devel] [PATCH RFC2 1/2] tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT David Hildenbrand
2019-02-28  7:22   ` David Hildenbrand
2019-02-27 21:15 ` [Qemu-devel] [PATCH RFC2 2/2] tests/tcg: target/s390x: Test VECTOR LOAD GR FROM VR ELEMENT David Hildenbrand
2019-02-27 21:23 ` [Qemu-devel] [PATCH RFCv2 0/2] tests/tcg: Vector instruction tests for target/s390x no-reply

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.