]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add a test program of sorts, for XBEGIN and XTEST.
authorJulian Seward <jseward@acm.org>
Fri, 27 Sep 2013 15:22:50 +0000 (15:22 +0000)
committerJulian Seward <jseward@acm.org>
Fri, 27 Sep 2013 15:22:50 +0000 (15:22 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13579

none/tests/amd64/Makefile.am
none/tests/amd64/tm1.c [new file with mode: 0644]
none/tests/amd64/tm1.stderr.exp [new file with mode: 0644]
none/tests/amd64/tm1.stdout.exp [new file with mode: 0644]
none/tests/amd64/tm1.vgtest [new file with mode: 0644]

index 90cde075b41fdcda5dfec3c3d9015e54d3237ccb..6e00b2cd882d164ede23d5a62e418df38139c5f0 100644 (file)
@@ -79,6 +79,7 @@ EXTRA_DIST = \
        sse4-64.stdout.exp-older-glibc \
        slahf-amd64.stderr.exp slahf-amd64.stdout.exp \
        slahf-amd64.vgtest \
+       tm1.vgtest tm1.stderr.exp tm1.stdout.exp \
        xadd.stderr.exp xadd.stdout.exp xadd.vgtest
 
 check_PROGRAMS = \
@@ -113,7 +114,7 @@ if BUILD_VPCLMULQDQ_TESTS
 endif
 endif
 if BUILD_AVX2_TESTS
-  check_PROGRAMS += avx2-1
+  check_PROGRAMS += avx2-1 tm1
 endif
 if BUILD_BMI_TESTS
  check_PROGRAMS += bmi
diff --git a/none/tests/amd64/tm1.c b/none/tests/amd64/tm1.c
new file mode 100644 (file)
index 0000000..86a31b3
--- /dev/null
@@ -0,0 +1,62 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/* An ultra-lame test program for RTM support, as available
+   on Haswell CPUs. */
+
+/* Attempt to run f(arg) as a transaction, and return a Boolean
+   indicating success or otherwise. */
+
+__attribute__((noinline))
+static int transactionally_apply ( void(*f)(void*), void* arg )
+{
+  register int ok;
+  __asm__ __volatile__(
+     "  xbegin .Lzzqqfail" );
+  f(arg);
+  __asm__ __volatile__( 
+     /* This is a bit tricky.  If the transaction succeeds, control
+        will flow to this point.  If it fails, control continues at
+        .Lzzqqfail, with the machine state looking the same as it did
+        immediately before the xbegin was executed. */
+     "  xend           \n\t"  /* declare the transaction to be complete */
+     "  movl $1,%0     \n\t"  /* "ok = 1" */
+     "  jmp .Lzzqqout  \n\t"  /* jump to the merge point */
+     ".Lzzqqfail:      \n\t"  /* it failed .. */
+     "  movl $0,%0     \n\t"  /* "ok = 0" */
+     ".Lzzqqout:       \n\t"  /* this is the merge point */
+     : "=r"(ok) : : "cc", "rax"
+  );
+  return ok;
+}
+
+void testfn ( void* arg )
+{
+}
+
+int main ( void )
+{
+  long long int ok = transactionally_apply ( testfn, NULL );
+  printf("transactionally_apply: ok = %lld (expected %d)\n", ok, 0);
+
+  __asm__ __volatile__(
+    "movq $0, %%rax  \n\t"
+    "xtest           \n\t"   
+    "setz %%al       \n\t"
+    "movq %%rax, %0  \n\t"
+    : "=r"(ok) : : "cc","rax"
+  );
+  printf("xtest: rflags.Z = %lld (expected %d)\n", ok, 1);
+
+  /*
+  printf("testing XACQUIRE / XRELEASE\n");
+  int n = 0;
+  __asm__ __volatile__(
+     "xacquire lock incl (%0)   \n\t"
+     "xrelease lock decl (%0)   \n\t"
+     : : "r"(&n) : "cc", "memory"
+  );
+  */
+  return 0;
+}
diff --git a/none/tests/amd64/tm1.stderr.exp b/none/tests/amd64/tm1.stderr.exp
new file mode 100644 (file)
index 0000000..139597f
--- /dev/null
@@ -0,0 +1,2 @@
+
+
diff --git a/none/tests/amd64/tm1.stdout.exp b/none/tests/amd64/tm1.stdout.exp
new file mode 100644 (file)
index 0000000..14f4c02
--- /dev/null
@@ -0,0 +1,2 @@
+transactionally_apply: ok = 0 (expected 0)
+xtest: rflags.Z = 1 (expected 1)
diff --git a/none/tests/amd64/tm1.vgtest b/none/tests/amd64/tm1.vgtest
new file mode 100644 (file)
index 0000000..69d93d4
--- /dev/null
@@ -0,0 +1,2 @@
+prog: tm1
+prereq: test -x tm1 && ../../../tests/x86_amd64_features amd64-avx