From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Richard Henderson <richard.henderson@linaro.org>,
David Hildenbrand <david@redhat.com>
Cc: qemu-devel@nongnu.org, Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH v2] tests/tcg/s390x: Add cdsg.c
Date: Tue, 29 Nov 2022 15:30:04 +0100 [thread overview]
Message-ID: <20221129143004.177852-1-iii@linux.ibm.com> (raw)
In-Reply-To: <2fb2b364-231d-1087-c516-c0144bac0979@redhat.com>
Add a simple test to prevent regressions.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
tests/tcg/s390x/Makefile.target | 4 ++
tests/tcg/s390x/cdsg.c | 84 +++++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+)
create mode 100644 tests/tcg/s390x/cdsg.c
diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target
index 1d454270c0e..523214dac33 100644
--- a/tests/tcg/s390x/Makefile.target
+++ b/tests/tcg/s390x/Makefile.target
@@ -27,6 +27,7 @@ TESTS+=noexec
TESTS+=div
TESTS+=clst
TESTS+=long-double
+TESTS+=cdsg
Z13_TESTS=vistr
$(Z13_TESTS): CFLAGS+=-march=z13 -O2
@@ -66,3 +67,6 @@ sha512-mvx: sha512.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
TESTS+=sha512-mvx
+
+cdsg: CFLAGS+=-pthread
+cdsg: LDFLAGS+=-pthread
diff --git a/tests/tcg/s390x/cdsg.c b/tests/tcg/s390x/cdsg.c
new file mode 100644
index 00000000000..28b5ac9a000
--- /dev/null
+++ b/tests/tcg/s390x/cdsg.c
@@ -0,0 +1,84 @@
+#include <assert.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+static volatile bool start;
+typedef unsigned long aligned_quadword[2] __attribute__((__aligned__(16)));
+static aligned_quadword val;
+
+static inline int cdsg(unsigned long *orig0, unsigned long *orig1,
+ unsigned long new0, unsigned long new1,
+ aligned_quadword *mem)
+{
+ register unsigned long r0 asm("r0");
+ register unsigned long r1 asm("r1");
+ register unsigned long r2 asm("r2");
+ register unsigned long r3 asm("r3");
+ int cc;
+
+ r0 = *orig0;
+ r1 = *orig1;
+ r2 = new0;
+ r3 = new1;
+ asm("cdsg %[r0],%[r2],%[db2]\n"
+ "ipm %[cc]"
+ : [r0] "+r" (r0)
+ , [r1] "+r" (r1)
+ , [db2] "+m" (*mem)
+ , [cc] "=r" (cc)
+ : [r2] "r" (r2)
+ , [r3] "r" (r3)
+ : "cc");
+ *orig0 = r0;
+ *orig1 = r1;
+
+ return (cc >> 28) & 3;
+}
+
+void *cdsg_loop(void *arg)
+{
+ unsigned long orig0, orig1, new0, new1;
+ int cc;
+ int i;
+
+ while (!start) {
+ }
+
+ orig0 = val[0];
+ orig1 = val[1];
+ for (i = 0; i < 1000;) {
+ new0 = orig0 + 1;
+ new1 = orig1 + 2;
+
+ cc = cdsg(&orig0, &orig1, new0, new1, &val);
+
+ if (cc == 0) {
+ orig0 = new0;
+ orig1 = new1;
+ i++;
+ } else {
+ assert(cc == 1);
+ }
+ }
+
+ return NULL;
+}
+
+int main(void)
+{
+ pthread_t thread;
+ int ret;
+
+ ret = pthread_create(&thread, NULL, cdsg_loop, NULL);
+ assert(ret == 0);
+ start = true;
+ cdsg_loop(NULL);
+ ret = pthread_join(thread, NULL);
+ assert(ret == 0);
+
+ assert(val[0] == 2000);
+ assert(val[1] == 4000);
+
+ return EXIT_SUCCESS;
+}
--
2.38.1
next prev parent reply other threads:[~2022-11-29 14:30 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-11 8:08 [PATCH for-8.0 v2 00/13] target/s390x: Use TCGv_i128 Richard Henderson
2022-11-11 8:08 ` [PATCH for-8.0 v2 01/13] tests/tcg/s390x: Add div.c Richard Henderson
2022-11-11 8:08 ` [PATCH for-8.0 v2 02/13] tests/tcg/s390x: Add clst.c Richard Henderson
2022-11-11 8:08 ` [PATCH for-8.0 v2 03/13] tests/tcg/s390x: Add long-double.c Richard Henderson
2022-11-11 8:08 ` [PATCH for-8.0 v2 04/13] target/s390x: Use a single return for helper_divs32/u32 Richard Henderson
2022-11-28 21:42 ` Ilya Leoshkevich
2022-11-11 8:08 ` [PATCH for-8.0 v2 05/13] target/s390x: Use a single return for helper_divs64/u64 Richard Henderson
2022-11-11 8:08 ` [PATCH for-8.0 v2 06/13] target/s390x: Use Int128 for return from CLST Richard Henderson
2022-11-11 8:08 ` [PATCH for-8.0 v2 07/13] target/s390x: Use Int128 for return from CKSM Richard Henderson
2022-11-11 8:08 ` [PATCH for-8.0 v2 08/13] target/s390x: Use Int128 for return from TRE Richard Henderson
2022-11-11 8:08 ` [PATCH for-8.0 v2 09/13] target/s390x: Copy wout_x1 to wout_x1_P Richard Henderson
2022-11-11 8:08 ` [PATCH for-8.0 v2 10/13] target/s390x: Use Int128 for returning float128 Richard Henderson
2022-11-28 21:53 ` Ilya Leoshkevich
2022-11-11 8:08 ` [PATCH for-8.0 v2 11/13] target/s390x: Use Int128 for passing float128 Richard Henderson
2022-11-28 22:07 ` Ilya Leoshkevich
2022-11-11 8:08 ` [PATCH for-8.0 v2 12/13] target/s390x: Use tcg_gen_atomic_cmpxchg_i128 for CDSG Richard Henderson
2022-11-28 23:40 ` Ilya Leoshkevich
2022-11-28 23:48 ` [PATCH] tests/tcg/s390x: Add cdsg.c Ilya Leoshkevich
2022-11-29 8:54 ` David Hildenbrand
2022-11-29 14:28 ` Ilya Leoshkevich
2022-11-29 14:30 ` Ilya Leoshkevich [this message]
2022-11-29 15:24 ` [PATCH v3] " Ilya Leoshkevich
2022-11-29 0:02 ` [PATCH for-8.0 v2 12/13] target/s390x: Use tcg_gen_atomic_cmpxchg_i128 for CDSG Richard Henderson
2022-11-11 8:08 ` [PATCH for-8.0 v2 13/13] target/s390x: Implement CC_OP_NZ in gen_op_calc_cc Richard Henderson
2022-11-28 23:45 ` Ilya Leoshkevich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221129143004.177852-1-iii@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=david@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.