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
This commit is contained in:
Julian Seward 2011-01-17 12:34:33 +00:00
parent e513aa4606
commit 166dd7ea1c
5 changed files with 120 additions and 0 deletions

View 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 \

114
none/tests/x86/aad_aam.c Normal file
View File

@ -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;
}

View File

View File

@ -0,0 +1,2 @@
test begins
test completed

View File

@ -0,0 +1,2 @@
prog: aad_aam
vgopts: -q