From: Julian Seward Date: Fri, 27 Sep 2013 15:22:50 +0000 (+0000) Subject: Add a test program of sorts, for XBEGIN and XTEST. X-Git-Tag: svn/VALGRIND_3_9_0~112 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a8d194303d2df94b5466a4daa8f17854d84628e;p=thirdparty%2Fvalgrind.git Add a test program of sorts, for XBEGIN and XTEST. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13579 --- diff --git a/none/tests/amd64/Makefile.am b/none/tests/amd64/Makefile.am index 90cde075b4..6e00b2cd88 100644 --- a/none/tests/amd64/Makefile.am +++ b/none/tests/amd64/Makefile.am @@ -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 index 0000000000..86a31b396d --- /dev/null +++ b/none/tests/amd64/tm1.c @@ -0,0 +1,62 @@ + +#include +#include + +/* 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 index 0000000000..139597f9cb --- /dev/null +++ b/none/tests/amd64/tm1.stderr.exp @@ -0,0 +1,2 @@ + + diff --git a/none/tests/amd64/tm1.stdout.exp b/none/tests/amd64/tm1.stdout.exp new file mode 100644 index 0000000000..14f4c02d1f --- /dev/null +++ b/none/tests/amd64/tm1.stdout.exp @@ -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 index 0000000000..69d93d4874 --- /dev/null +++ b/none/tests/amd64/tm1.vgtest @@ -0,0 +1,2 @@ +prog: tm1 +prereq: test -x tm1 && ../../../tests/x86_amd64_features amd64-avx