|
From: <sv...@va...> - 2011-01-17 12:34:42
|
Author: sewardj Date: 2011-01-17 12:34:33 +0000 (Mon, 17 Jan 2011) New Revision: 11502 Log: Add tests for AAD and AAM (base 10 only). (Vince Weaver, vi...@cs...) Added: trunk/none/tests/x86/aad_aam.c trunk/none/tests/x86/aad_aam.stderr.exp trunk/none/tests/x86/aad_aam.stdout.exp trunk/none/tests/x86/aad_aam.vgtest Modified: trunk/none/tests/x86/Makefile.am Modified: trunk/none/tests/x86/Makefile.am =================================================================== --- trunk/none/tests/x86/Makefile.am 2011-01-17 11:42:19 UTC (rev 11501) +++ trunk/none/tests/x86/Makefile.am 2011-01-17 12:34:33 UTC (rev 11502) @@ -21,6 +21,7 @@ ## 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 @@ xadd.stdout.exp xadd.stderr.exp xadd.vgtest check_PROGRAMS = \ + aad_aam \ badseg \ bt_everything \ bt_literal \ Added: trunk/none/tests/x86/aad_aam.c =================================================================== --- trunk/none/tests/x86/aad_aam.c (rev 0) +++ trunk/none/tests/x86/aad_aam.c 2011-01-17 12:34:33 UTC (rev 11502) @@ -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; + +} Added: trunk/none/tests/x86/aad_aam.stderr.exp =================================================================== Added: trunk/none/tests/x86/aad_aam.stdout.exp =================================================================== --- trunk/none/tests/x86/aad_aam.stdout.exp (rev 0) +++ trunk/none/tests/x86/aad_aam.stdout.exp 2011-01-17 12:34:33 UTC (rev 11502) @@ -0,0 +1,2 @@ +test begins +test completed Added: trunk/none/tests/x86/aad_aam.vgtest =================================================================== --- trunk/none/tests/x86/aad_aam.vgtest (rev 0) +++ trunk/none/tests/x86/aad_aam.vgtest 2011-01-17 12:34:33 UTC (rev 11502) @@ -0,0 +1,2 @@ +prog: aad_aam +vgopts: -q |