From: Julian Seward Date: Mon, 16 Jul 2012 08:23:26 +0000 (+0000) Subject: Add tests for MOVBE -- an Intel-Atom-only instruction X-Git-Tag: svn/VALGRIND_3_8_0~118 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57c1e52b2d3e96b59910bc94ae0b8d6ed9a638ce;p=thirdparty%2Fvalgrind.git Add tests for MOVBE -- an Intel-Atom-only instruction git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12750 --- diff --git a/configure.in b/configure.in index 51a2f93a87..c7878c70ec 100644 --- a/configure.in +++ b/configure.in @@ -1754,6 +1754,27 @@ AC_MSG_RESULT([no]) AM_CONDITIONAL(BUILD_AVX_TESTS, test x$ac_have_as_avx = xyes) +# does the x86/amd64 assembler understand MOVBE? +# Note, this doesn't generate a C-level symbol. It generates a +# automake-level symbol (BUILD_MOVBE_TESTS), used in test Makefile.am's +AC_MSG_CHECKING([if x86/amd64 assembler knows the MOVBE insn]) + +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ + do { long long int x; + __asm__ __volatile__( + "movbe (%%rsp), %%r15" : : : "r15" ); } + while (0) +]])], [ +ac_have_as_movbe=yes +AC_MSG_RESULT([yes]) +], [ +ac_have_as_movbe=no +AC_MSG_RESULT([no]) +]) + +AM_CONDITIONAL(BUILD_MOVBE_TESTS, test x$ac_have_as_movbe = xyes) + + # Does the C compiler support the "ifunc" attribute # Note, this doesn't generate a C-level symbol. It generates a # automake-level symbol (BUILD_IFUNC_TESTS), used in test Makefile.am's diff --git a/none/tests/amd64/Makefile.am b/none/tests/amd64/Makefile.am index ef53fc4c14..0e490798a9 100644 --- a/none/tests/amd64/Makefile.am +++ b/none/tests/amd64/Makefile.am @@ -52,6 +52,7 @@ EXTRA_DIST = \ looper.stderr.exp looper.stdout.exp looper.vgtest \ loopnel.stderr.exp loopnel.stdout.exp loopnel.vgtest \ lzcnt64.stderr.exp lzcnt64.stdout.exp lzcnt64.vgtest \ + movbe.stderr.exp movbe.stdout.exp movbe.vgtest \ nan80and64.stderr.exp nan80and64.stdout.exp nan80and64.vgtest \ nibz_bennee_mmap.stderr.exp nibz_bennee_mmap.stdout.exp \ nibz_bennee_mmap.vgtest \ @@ -106,6 +107,9 @@ endif if BUILD_AVX_TESTS check_PROGRAMS += avx-1 endif +if BUILD_MOVBE_TESTS + check_PROGRAMS += movbe +endif # DDD: these need to be made to work on Darwin like the x86/ ones were. if ! VGCONF_OS_IS_DARWIN diff --git a/none/tests/amd64/movbe.c b/none/tests/amd64/movbe.c new file mode 100644 index 0000000000..4b23696b81 --- /dev/null +++ b/none/tests/amd64/movbe.c @@ -0,0 +1,81 @@ + +#include +#include +#include +#include + +typedef unsigned char UChar; +typedef unsigned int UInt; +typedef unsigned long int UWord; +typedef unsigned long long int ULong; + + +typedef struct { UChar cs[40]; } Block; + +void showBlock ( char* msg, Block* b ) +{ + int i; + printf(" %s ", msg); + for (i = 0; i < 40; i++) + printf("%02x", (UInt)b->cs[i]); + printf("\n"); +} + +UChar randUChar ( void ) +{ + static UInt seed = 80021; + seed = 1103515245 * seed + 12345; + return (seed >> 17) & 0xFF; +} + +void randBlock ( Block* b ) +{ + int i; + UChar* p = (UChar*)b; + for (i = 0; i < sizeof(Block); i++) + p[i] = randUChar(); +} + +/* Generate a function test_NAME, that tests the given insn. + The insn may only mention (%rax) and r9. */ + +#define GEN_test_Monly(_name, _mem_form) \ + \ + __attribute__ ((noinline)) static void test_##_name ( void ) \ + { \ + Block* b = memalign(32, sizeof(Block)); \ + randBlock(b); \ + printf("%s\n", #_name); \ + showBlock("before", b); \ + __asm__ __volatile__( \ + "leaq 16(%0),%%rax" "\n\t" \ + "movq 24(%0),%%r9" "\n\t" \ + _mem_form "\n\t" \ + "movq %%r9, 32(%0)" "\n\t" \ + : /*OUT*/ \ + : /*IN*/"r"(b) \ + : /*TRASH*/"r9","rax","memory","cc" \ + ); \ + showBlock("after ", b); \ + printf("\n"); \ + free(b); \ + } + +GEN_test_Monly( MOVBE_RtoM_64, "movbe %%r9, 1(%%rax)") +GEN_test_Monly( MOVBE_RtoM_32, "movbe %%r9d,1(%%rax)") +GEN_test_Monly( MOVBE_RtoM_16, "movbe %%r9w,1(%%rax)") + +GEN_test_Monly( MOVBE_MtoR_64, "movbe 1(%%rax), %%r9") +GEN_test_Monly( MOVBE_MtoR_32, "movbe 1(%%rax), %%r9d") +GEN_test_Monly( MOVBE_MtoR_16, "movbe 1(%%rax), %%r9w") + +int main ( void ) +{ + test_MOVBE_RtoM_64(); + test_MOVBE_RtoM_32(); + test_MOVBE_RtoM_16(); + test_MOVBE_MtoR_64(); + test_MOVBE_MtoR_32(); + test_MOVBE_MtoR_16(); + return 0; +} diff --git a/none/tests/amd64/movbe.stderr.exp b/none/tests/amd64/movbe.stderr.exp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/none/tests/amd64/movbe.stdout.exp b/none/tests/amd64/movbe.stdout.exp new file mode 100644 index 0000000000..ad779ba4c2 --- /dev/null +++ b/none/tests/amd64/movbe.stdout.exp @@ -0,0 +1,24 @@ +MOVBE_RtoM_64 + before 00571784494af2981ecac9199de375513bd127afa6e9c3690d6a95fac528657d501eefeec0d8b847 + after 00571784494af2981ecac9199de375513b7d6528c5fa956a0d6a95fac528657d0d6a95fac528657d + +MOVBE_RtoM_32 + before 84c4457d8560b160b244a056e51599fe2751bca75afbd2b6382dccdbc2829139fd673a5c2148a319 + after 84c4457d8560b160b244a056e51599fe27dbcc2d38fbd2b6382dccdbc2829139382dccdbc2829139 + +MOVBE_RtoM_16 + before 179e655064dc2a846b3e625d19775d06e540bc6839c44b4a36ed3550df9899d8979b83b70eb840d7 + after 179e655064dc2a846b3e625d19775d06e5ed366839c44b4a36ed3550df9899d836ed3550df9899d8 + +MOVBE_MtoR_64 + before 856c13b8709950cb8315cab0121ab056db93c0f8294addf95df605a7d127a7d31f195c53c95bf85f + after 856c13b8709950cb8315cab0121ab056db93c0f8294addf95df605a7d127a7d35df9dd4a29f8c093 + +MOVBE_MtoR_32 + before 3d6603cf39008e39979569ee6d5cbcd8966cf73d98a42d54e87fc9cb92bba12040ef72e29bf3afcf + after 3d6603cf39008e39979569ee6d5cbcd8966cf73d98a42d54e87fc9cb92bba120983df76c00000000 + +MOVBE_MtoR_16 + before 172ebcce16c982d16eb865944fab9d368adae4bb36b59768b76e2305226ee0f4069b4435908d7b40 + after 172ebcce16c982d16eb865944fab9d368adae4bb36b59768b76e2305226ee0f4e4da2305226ee0f4 + diff --git a/none/tests/amd64/movbe.vgtest b/none/tests/amd64/movbe.vgtest new file mode 100644 index 0000000000..f6d135736f --- /dev/null +++ b/none/tests/amd64/movbe.vgtest @@ -0,0 +1,2 @@ +prog: movbe +vgopts: -q