|
From: <sv...@va...> - 2013-09-27 15:23:08
|
Author: sewardj
Date: Fri Sep 27 15:22:50 2013
New Revision: 13579
Log:
Add a test program of sorts, for XBEGIN and XTEST.
Added:
trunk/none/tests/amd64/tm1.c
trunk/none/tests/amd64/tm1.stderr.exp
trunk/none/tests/amd64/tm1.stdout.exp
trunk/none/tests/amd64/tm1.vgtest
Modified:
trunk/none/tests/amd64/Makefile.am
Modified: trunk/none/tests/amd64/Makefile.am
==============================================================================
--- trunk/none/tests/amd64/Makefile.am (original)
+++ trunk/none/tests/amd64/Makefile.am Fri Sep 27 15:22:50 2013
@@ -79,6 +79,7 @@
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 @@
endif
endif
if BUILD_AVX2_TESTS
- check_PROGRAMS += avx2-1
+ check_PROGRAMS += avx2-1 tm1
endif
if BUILD_BMI_TESTS
check_PROGRAMS += bmi
Added: trunk/none/tests/amd64/tm1.c
==============================================================================
--- trunk/none/tests/amd64/tm1.c (added)
+++ trunk/none/tests/amd64/tm1.c Fri Sep 27 15:22:50 2013
@@ -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;
+}
Added: trunk/none/tests/amd64/tm1.stderr.exp
==============================================================================
--- trunk/none/tests/amd64/tm1.stderr.exp (added)
+++ trunk/none/tests/amd64/tm1.stderr.exp Fri Sep 27 15:22:50 2013
@@ -0,0 +1,2 @@
+
+
Added: trunk/none/tests/amd64/tm1.stdout.exp
==============================================================================
--- trunk/none/tests/amd64/tm1.stdout.exp (added)
+++ trunk/none/tests/amd64/tm1.stdout.exp Fri Sep 27 15:22:50 2013
@@ -0,0 +1,2 @@
+transactionally_apply: ok = 0 (expected 0)
+xtest: rflags.Z = 1 (expected 1)
Added: trunk/none/tests/amd64/tm1.vgtest
==============================================================================
--- trunk/none/tests/amd64/tm1.vgtest (added)
+++ trunk/none/tests/amd64/tm1.vgtest Fri Sep 27 15:22:50 2013
@@ -0,0 +1,2 @@
+prog: tm1
+prereq: test -x tm1 && ../../../tests/x86_amd64_features amd64-avx
|