]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add tests for AAD and AAM (base 10 only).
authorJulian Seward <jseward@acm.org>
Mon, 17 Jan 2011 12:34:33 +0000 (12:34 +0000)
committerJulian Seward <jseward@acm.org>
Mon, 17 Jan 2011 12:34:33 +0000 (12:34 +0000)
(Vince Weaver, vince@csl.cornell.edu)

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11502

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

index 0fa2194c2e70a35f4fbeee87390e2efee25a66fd..5d72f2eae62ffc1012fe9dd8f64f2e4afe7864ae 100644 (file)
@@ -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 (file)
index 0000000..342044a
--- /dev/null
@@ -0,0 +1,114 @@
+/* This tests the somewhat obscure 32-bit Intel aam and aad instructions */
+/* by Vince Weaver (vince _at_ deater.net ) */
+
+#include <stdio.h>
+
+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 (file)
index 0000000..e69de29
diff --git a/none/tests/x86/aad_aam.stdout.exp b/none/tests/x86/aad_aam.stdout.exp
new file mode 100644 (file)
index 0000000..c8bde09
--- /dev/null
@@ -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 (file)
index 0000000..42655d5
--- /dev/null
@@ -0,0 +1,2 @@
+prog: aad_aam
+vgopts: -q