From 166dd7ea1c20dc9f456f725341a9dc0e64242773 Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Mon, 17 Jan 2011 12:34:33 +0000 Subject: [PATCH] Add tests for AAD and AAM (base 10 only). (Vince Weaver, vince@csl.cornell.edu) git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11502 --- none/tests/x86/Makefile.am | 2 + none/tests/x86/aad_aam.c | 114 ++++++++++++++++++++++++++++++ none/tests/x86/aad_aam.stderr.exp | 0 none/tests/x86/aad_aam.stdout.exp | 2 + none/tests/x86/aad_aam.vgtest | 2 + 5 files changed, 120 insertions(+) create mode 100644 none/tests/x86/aad_aam.c create mode 100644 none/tests/x86/aad_aam.stderr.exp create mode 100644 none/tests/x86/aad_aam.stdout.exp create mode 100644 none/tests/x86/aad_aam.vgtest diff --git a/none/tests/x86/Makefile.am b/none/tests/x86/Makefile.am index 0fa2194c2..5d72f2eae 100644 --- a/none/tests/x86/Makefile.am +++ b/none/tests/x86/Makefile.am @@ -21,6 +21,7 @@ endif ## FIXME: move lzcnt32 to SSE4 conditionalisation, when that happens. EXTRA_DIST = \ + aad_aam.stdout.exp aad_aam.stderr.exp aad_aam.vgtest \ badseg.stderr.exp badseg.stdout.exp badseg.vgtest \ bt_everything.stderr.exp bt_everything.stdout.exp bt_everything.vgtest \ bt_literal.stderr.exp bt_literal.stdout.exp bt_literal.vgtest \ @@ -61,6 +62,7 @@ EXTRA_DIST = \ xadd.stdout.exp xadd.stderr.exp xadd.vgtest check_PROGRAMS = \ + aad_aam \ badseg \ bt_everything \ bt_literal \ diff --git a/none/tests/x86/aad_aam.c b/none/tests/x86/aad_aam.c new file mode 100644 index 000000000..342044ac3 --- /dev/null +++ b/none/tests/x86/aad_aam.c @@ -0,0 +1,114 @@ +/* This tests the somewhat obscure 32-bit Intel aam and aad instructions */ +/* by Vince Weaver (vince _at_ deater.net ) */ + +#include + +int parity(int v) { + + int i; + int p = 1; + + for (i = 0; i < 8; i++) + p ^= (1 & (v >> i)); + return p; +} + +int main(int argc, char **argv) { + + printf("test begins\n"); + unsigned short i,out; + unsigned int flags; + int cf,pf,af,zf,sf,of; + + /* test AAM */ + + for(i=0;i<65535;i++) { + // printf("%d, %d, %d\n",i,(i&0xff)/10,(i&0xff)%10); + out=i; + __asm__ __volatile__ ("mov %2 ,%%ax\n" + "aam\n" + "pushf\n" + "mov %%ax, %0\n" + "pop %%eax\n" + "mov %%eax, %1\n" + :"=r"(out), "=r"(flags) /* outputs */ + :"r"(out) /* input */ + :"%eax" /* clobbered */ + ); + cf=!!(flags&0x1); + pf=!!(flags&0x4); + af=!!(flags&0x10); + zf=!!(flags&0x40); + sf=!!(flags&0x80); + of=!!(flags&0x800); + + // printf("%d, %d, %d, ",i,(out>>8)&0xff,out&0xff); + // printf("%x CF=%d PF=%d AF=%d ZF=%d SF=%d OF=%d\n", + // flags,cf,pf,af,zf,sf,of); + + if (zf && ((out&0xff)!=0)) { + printf("Error with aam (zf)!\n"); + } + if (pf != parity(out&0xff)) { + printf("Error with aam (pf)!\n"); + } + if (sf != !!(out&0x80)) { + printf("Error with aam (sf)!\n"); + } + + + if ( ((out>>8)&0xff) != ((i&0xff)/10)) { + printf("Error with aam!\n"); + } + if ( (out&0xff) != ((i&0xff)%10)) { + printf("Error with aam!\n"); + } + + } + + /* test AAD */ + + for(i=0;i<65535;i++) { + // printf("%x, %d\n",i, ((((i>>8)&0xff)*10)+(i&0xff))&0xff ); + out=i; + __asm__ __volatile__ ("mov %2 ,%%ax\n" + "aad\n" + "pushf\n" + "mov %%ax, %0\n" + "pop %%eax\n" + "mov %%eax, %1\n" + :"=r"(out), "=r"(flags) /* outputs */ + :"r"(out) /* input */ + :"%eax" /* clobbered */ +); + + cf=!!(flags&0x1); + pf=!!(flags&0x4); + af=!!(flags&0x10); + zf=!!(flags&0x40); + sf=!!(flags&0x80); + of=!!(flags&0x800); + + // printf("%x, %d ",i,out); + // printf("%x CF=%d PF=%d AF=%d ZF=%d SF=%d OF=%d\n", + // flags,cf,pf,af,zf,sf,of); + + if (zf && ((out&0xff)!=0)) { + printf("Error with aad (zf)!\n"); + } + if (pf != parity(out&0xff)) { + printf("Error with aad (pf)!\n"); + } + if (sf != !!(out&0x80)) { + printf("Error with aad (sf) %d %d!\n",sf,!!(out&0x80)); + } + + if ( out != ( ((((i>>8)&0xff)*10)+(i&0xff))&0xff) ) { + printf("Error with aad!\n"); + } + } + + printf("test completed\n"); + return 0; + +} diff --git a/none/tests/x86/aad_aam.stderr.exp b/none/tests/x86/aad_aam.stderr.exp new file mode 100644 index 000000000..e69de29bb diff --git a/none/tests/x86/aad_aam.stdout.exp b/none/tests/x86/aad_aam.stdout.exp new file mode 100644 index 000000000..c8bde09b2 --- /dev/null +++ b/none/tests/x86/aad_aam.stdout.exp @@ -0,0 +1,2 @@ +test begins +test completed diff --git a/none/tests/x86/aad_aam.vgtest b/none/tests/x86/aad_aam.vgtest new file mode 100644 index 000000000..42655d530 --- /dev/null +++ b/none/tests/x86/aad_aam.vgtest @@ -0,0 +1,2 @@ +prog: aad_aam +vgopts: -q