]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 509517 - s390x: Add even/odd-lane memcheck test for VME etc.
authorAndreas Arnez <arnez@linux.ibm.com>
Wed, 10 Sep 2025 17:05:40 +0000 (19:05 +0200)
committerAndreas Arnez <arnez@linux.ibm.com>
Tue, 16 Sep 2025 14:38:04 +0000 (16:38 +0200)
Add an s390x-specific memcheck test case for the correct handling of
even/odd lanes with various vector insns.  The test fails before applying
the fix for Bug 509517 and succeeds afterwards.

.gitignore
NEWS
memcheck/tests/s390x/Makefile.am
memcheck/tests/s390x/vme.c [new file with mode: 0644]
memcheck/tests/s390x/vme.stderr.exp [new file with mode: 0644]
memcheck/tests/s390x/vme.stdout.exp [new file with mode: 0644]
memcheck/tests/s390x/vme.vgtest [new file with mode: 0644]

index 4eb477c0890f94f8fd0c3444fc6537358bb0efe5..9fb56ba0b91b60c7728f69eda1ab194998f529b7 100644 (file)
 /memcheck/tests/s390x/cu42
 /memcheck/tests/s390x/ltgjhe
 /memcheck/tests/s390x/tmxx
+/memcheck/tests/s390x/vme
 /memcheck/tests/s390x/vstrc
 /memcheck/tests/s390x/vfae
 /memcheck/tests/s390x/vistr
diff --git a/NEWS b/NEWS
index 04a30c9b94872514ad99d0b821785a296a75799d..7940ab4a0738efb10c304a65383443e75d0a912e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -136,6 +136,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 509107  memcheck/tests/duplicate_align_size_errors.cpp fails
 509139  Update BadSize error messages
 509258  FreeBSD: add jail_attach_jd and jail_remove_jd syscall wrappers
+509517  s390x: Even/odd lane confusion in various vector insns
 
 To see details of a given bug, visit
   https://bugs.kde.org/show_bug.cgi?id=XXXXXX
index 32a898ca5fc4fce1658df5ce2997e3757c2b441d..580fc1ee993e63b53c624cf47e5a725ff4e43167 100644 (file)
@@ -2,7 +2,7 @@ include $(top_srcdir)/Makefile.tool-tests.am
 
 dist_noinst_SCRIPTS = filter_stderr
 
-INSN_TESTS = cdsg cli cu21 cu42 ltgjhe tmxx vstrc vfae vistr vstrs
+INSN_TESTS = cdsg cli cu21 cu42 ltgjhe tmxx vstrc vfae vistr vstrs vme
 
 check_PROGRAMS = $(INSN_TESTS) 
 
diff --git a/memcheck/tests/s390x/vme.c b/memcheck/tests/s390x/vme.c
new file mode 100644 (file)
index 0000000..1e29b09
--- /dev/null
@@ -0,0 +1,101 @@
+#define VECTOR __attribute__((vector_size(16)))
+
+typedef unsigned char VECTOR uchar_v;
+
+volatile char     tmp;
+static const char use_idx[] = "01234567890abcdefghijklmnopqrstu";
+
+static void depend_on(uchar_v v)
+{
+   int val = 0;
+   for (int i = 0; i < 16; i++)
+      val += v[i];
+   tmp = use_idx[val & 31];
+}
+
+static void pretend_write(uchar_v* v) { __asm__("" : "=m"(*v) : :); }
+
+enum evenodd { even, odd };
+
+static uchar_v
+init_vec(uchar_v v, unsigned char es, enum evenodd e, unsigned char val)
+{
+   int mask = 1 << es;
+   int last = (mask - 1) & 15;
+
+   for (int i = 0; i < 16; i++) {
+      if ((i & mask) == (e == even ? 0 : mask))
+         v[i] = ((i & last) == last) ? val : 0;
+   }
+   return v;
+}
+
+#define GEN_TEST2(mnem, es)                                                    \
+   static void test_##mnem##_##es(uchar_v x, enum evenodd e)                   \
+   {                                                                           \
+      uchar_v res;                                                             \
+      uchar_v a = init_vec(x, es, e, 2);                                       \
+      uchar_v b = init_vec(x, es, e, 3);                                       \
+      __asm__(#mnem " %[v1],%[v2],%[v3]," #es                                  \
+              : [v1] "=v"(res)                                                 \
+              : [v2] "v"(a), [v3] "v"(b));                                     \
+      depend_on(res);                                                          \
+   }
+
+#define GEN_TEST3(mnem, es)                                                    \
+   static void test_##mnem##_##es(uchar_v x, enum evenodd e)                   \
+   {                                                                           \
+      uchar_v z = { 0 };                                                  \
+      uchar_v res;                                                             \
+      uchar_v a = init_vec(x, es, e, 2);                                       \
+      uchar_v b = init_vec(x, es, e, 3);                                       \
+      uchar_v c = init_vec(z, es, e, 4);                                       \
+      __asm__(#mnem " %[v1],%[v2],%[v3],%[v4]," #es                            \
+              : [v1] "=v"(res)                                                 \
+              : [v2] "v"(a), [v3] "v"(b), [v4] "v"(c));                        \
+      depend_on(res);                                                          \
+   }
+
+GEN_TEST2(vme, 0)
+GEN_TEST2(vme, 1)
+GEN_TEST2(vme, 2)
+GEN_TEST2(vmo, 2)
+GEN_TEST2(vmle, 1)
+GEN_TEST2(vmlo, 2)
+
+GEN_TEST3(vmae, 0)
+GEN_TEST3(vmale, 1)
+GEN_TEST3(vmao, 2)
+GEN_TEST3(vmalo, 2)
+
+static void do_valid(uchar_v x)
+{
+   test_vme_0(x, even);
+   test_vme_1(x, even);
+   test_vme_2(x, even);
+   test_vmo_2(x, odd);
+   test_vmle_1(x, even);
+   test_vmlo_2(x, odd);
+   test_vmae_0(x, even);
+   test_vmale_1(x, even);
+   test_vmao_2(x, odd);
+   test_vmalo_2(x, odd);
+}
+
+static void do_invalid(uchar_v x)
+{
+   test_vme_0(x, odd);
+   test_vme_1(x, odd);
+   test_vme_2(x, odd);
+   test_vmo_2(x, even);
+   test_vmale_1(x, odd);
+}
+
+int main(void)
+{
+   uchar_v x;
+   pretend_write(&x);
+   do_valid(x);
+   do_invalid(x);
+   return 0;
+}
diff --git a/memcheck/tests/s390x/vme.stderr.exp b/memcheck/tests/s390x/vme.stderr.exp
new file mode 100644 (file)
index 0000000..a66b80b
--- /dev/null
@@ -0,0 +1,30 @@
+Use of uninitialised value of size 8
+   at 0x........: depend_on (vme.c:13)
+   by 0x........: test_vme_0 (vme.c:59)
+   by 0x........: do_invalid (vme.c:87)
+   by 0x........: main (vme.c:99)
+
+Use of uninitialised value of size 8
+   at 0x........: depend_on (vme.c:13)
+   by 0x........: test_vme_1 (vme.c:60)
+   by 0x........: do_invalid (vme.c:88)
+   by 0x........: main (vme.c:99)
+
+Use of uninitialised value of size 8
+   at 0x........: depend_on (vme.c:13)
+   by 0x........: test_vme_2 (vme.c:61)
+   by 0x........: do_invalid (vme.c:89)
+   by 0x........: main (vme.c:99)
+
+Use of uninitialised value of size 8
+   at 0x........: depend_on (vme.c:13)
+   by 0x........: test_vmo_2 (vme.c:62)
+   by 0x........: do_invalid (vme.c:90)
+   by 0x........: main (vme.c:99)
+
+Use of uninitialised value of size 8
+   at 0x........: depend_on (vme.c:13)
+   by 0x........: test_vmale_1 (vme.c:67)
+   by 0x........: do_invalid (vme.c:91)
+   by 0x........: main (vme.c:99)
+
diff --git a/memcheck/tests/s390x/vme.stdout.exp b/memcheck/tests/s390x/vme.stdout.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/memcheck/tests/s390x/vme.vgtest b/memcheck/tests/s390x/vme.vgtest
new file mode 100644 (file)
index 0000000..b35858e
--- /dev/null
@@ -0,0 +1,2 @@
+prog: vme
+vgopts: -q