From nobody Sun Feb 8 02:41:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551302397022586.1484934611344; Wed, 27 Feb 2019 13:19:57 -0800 (PST) Received: from localhost ([127.0.0.1]:50799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gz6cL-0007uq-VQ for importer@patchew.org; Wed, 27 Feb 2019 16:19:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gz6YD-0005bm-2R for qemu-devel@nongnu.org; Wed, 27 Feb 2019 16:15:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gz6YB-0001C7-69 for qemu-devel@nongnu.org; Wed, 27 Feb 2019 16:15:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50536) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gz6Y9-0001AK-8q; Wed, 27 Feb 2019 16:15:35 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AC8B757E3; Wed, 27 Feb 2019 21:15:31 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-82.ams2.redhat.com [10.36.116.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA15E2CB12; Wed, 27 Feb 2019 21:15:29 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 27 Feb 2019 22:15:24 +0100 Message-Id: <20190227211525.2470-2-david@redhat.com> In-Reply-To: <20190227211525.2470-1-david@redhat.com> References: <20190227211525.2470-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 27 Feb 2019 21:15:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC2 1/2] tests/tcg: target/s390x: Test VECTOR GATHER ELEMENT X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , David Hildenbrand , Cornelia Huck , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-s390x@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" As want to make use of vectors in constraints of inline asm statements, use -march=3Dz13. 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 --- 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.tar= get index 151dc075aa..474c2428bd 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -6,3 +6,9 @@ TESTS+=3Dipm TESTS+=3Dexrl-trt TESTS+=3Dexrl-trtr TESTS+=3Dpack + +VECTOR_TESTS=3Dvge +TESTS+=3D$(VECTOR_TESTS) + +#enable vectors and optimisation for vector tests +$(VECTOR_TESTS): CFLAGS+=3D-march=3Dz13 -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 + +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-h= elper.inc.c new file mode 100644 index 0000000000..c214356ca1 --- /dev/null +++ b/tests/tcg/s390x/signal-helper.inc.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include +#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 !=3D 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) =3D=3D SIG_ERR) { \ + check("SIGILL not registered", false); \ + } \ + if (setjmp(jmp_env) =3D=3D 0) { \ + STATEMENT; \ + check("SIGILL not triggered", false); \ + } \ + if (signal(SIGILL, SIG_DFL) =3D=3D 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 +#include +#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 =3D 0x12345678ul; + S390Vector v1 =3D { + .q[0] =3D -1ull, + .q[1] =3D -1ull, + }; + S390Vector v2 =3D { + .d[0] =3D -1, + .d[1] =3D -1, + .d[2] =3D 56789, + .d[3] =3D -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] =3D=3D data); + check("vgef: elements unmodified", v1.d[0] =3D=3D -1 && v1.d[1] =3D=3D= -1 && + v1.d[3] =3D=3D -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 =3D 0x123456789abcdefull; + S390Vector v1 =3D { + .q[0] =3D -1ull, + .q[1] =3D -1ull, + }; + S390Vector v2 =3D { + .q[0] =3D -1ull, + .q[1] =3D 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] =3D=3D data); + check("vgef: elements unmodified", v1.q[0] =3D=3D -1ull); + + /* invalid element number */ + CHECK_SIGILL(vgeg(&v1, &v2, 0, 2)); +} + +int main(void) +{ + test_vgef(); + test_vgeg(); + return 0; +} --=20 2.17.2 From nobody Sun Feb 8 02:41:18 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155130226643292.07260063618367; Wed, 27 Feb 2019 13:17:46 -0800 (PST) Received: from localhost ([127.0.0.1]:50781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gz6a1-0006LC-FO for importer@patchew.org; Wed, 27 Feb 2019 16:17:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gz6YD-0005bl-2K for qemu-devel@nongnu.org; Wed, 27 Feb 2019 16:15:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gz6YB-0001Cc-Sb for qemu-devel@nongnu.org; Wed, 27 Feb 2019 16:15:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38314) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gz6YB-0001BF-4A; Wed, 27 Feb 2019 16:15:35 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9489D30BDCCA; Wed, 27 Feb 2019 21:15:33 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-82.ams2.redhat.com [10.36.116.82]) by smtp.corp.redhat.com (Postfix) with ESMTP id E449318231; Wed, 27 Feb 2019 21:15:31 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 27 Feb 2019 22:15:25 +0100 Message-Id: <20190227211525.2470-3-david@redhat.com> In-Reply-To: <20190227211525.2470-1-david@redhat.com> References: <20190227211525.2470-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 27 Feb 2019 21:15:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC2 2/2] tests/tcg: target/s390x: Test VECTOR LOAD GR FROM VR ELEMENT X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , David Hildenbrand , Cornelia Huck , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-s390x@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Reuse the existing helpers. Signed-off-by: David Hildenbrand --- 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.tar= get index 474c2428bd..deffc4c525 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -8,6 +8,7 @@ TESTS+=3Dexrl-trtr TESTS+=3Dpack =20 VECTOR_TESTS=3Dvge +VECTOR_TESTS+=3Dvlgv TESTS+=3D$(VECTOR_TESTS) =20 #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; =20 +#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 +#include +#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 =3D { + .q[0] =3D 0x0011223344556677ull, + .q[1] =3D 0x8899aabbccddeeffull, + }; + uint64_t r1 =3D 0; + + /* Directly set all ignored bits to */ + vlgv(&r1, &v3, (void *)(7 | ~0xf), ES_8); + check("8 bit", r1 =3D=3D 0x77); + vlgv(&r1, &v3, (void *)(4 | ~0x7), ES_16); + check("16 bit", r1 =3D=3D 0x8899); + vlgv(&r1, &v3, (void *)(3 | ~0x3), ES_32); + check("32 bit", r1 =3D=3D 0xccddeeff); + vlgv(&r1, &v3, (void *)(1 | ~0x1), ES_64); + check("64 bit", r1 =3D=3D 0x8899aabbccddeeffull); + check("v3 not modified", v3.q[0] =3D=3D 0x0011223344556677ull && + v3.q[1] =3D=3D 0x8899aabbccddeeffull); + + CHECK_SIGILL(vlgv(&r1, &v3, NULL, ES_128)); + return 0; +} --=20 2.17.2