From: Julian Seward Date: Fri, 9 May 2008 13:27:47 +0000 (+0000) Subject: Update to check fxrstor too. X-Git-Tag: svn/VALGRIND_3_4_1^2~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bca96b93d0aaa1b463ee7ee754bfa63151360e5;p=thirdparty%2Fvalgrind.git Update to check fxrstor too. git-svn-id: svn://svn.valgrind.org/vex/trunk@1837 --- diff --git a/VEX/test/fxsave.c b/VEX/test/fxsave.c index 5b0647e83c..655790757d 100644 --- a/VEX/test/fxsave.c +++ b/VEX/test/fxsave.c @@ -1,6 +1,8 @@ #include #include +#include +#include const unsigned int vec0[4] = { 0x12345678, 0x11223344, 0x55667788, 0x87654321 }; @@ -8,8 +10,46 @@ const unsigned int vec0[4] const unsigned int vec1[4] = { 0xABCDEF01, 0xAABBCCDD, 0xEEFF0011, 0x10FEDCBA }; +const unsigned int vecZ[4] + = { 0, 0, 0, 0 }; + +void do_fxsave ( void* p ) { + asm __volatile__("fxsave (%0)" : : "r" (p) : "memory" ); +} + +void do_fxrstor ( void* p ) { + asm __volatile__("fxrstor (%0)" : : "r" (p) : "memory" ); +} + +void do_zeroise ( void ) +{ + asm __volatile__("finit"); + asm __volatile__( + "fldz\n\t" + "fldz\n\t" + "fldz\n\t" + "fldz\n\t" + "fldz\n\t" + "fldz\n\t" + "fldz\n\t" + "fldz\n\t" + "finit\n"); + asm __volatile__("movups vecZ, %xmm0"); + asm __volatile__("movups vecZ, %xmm1"); + asm __volatile__("movups vecZ, %xmm2"); + asm __volatile__("movups vecZ, %xmm3"); + asm __volatile__("movups vecZ, %xmm4"); + asm __volatile__("movups vecZ, %xmm5"); + asm __volatile__("movups vecZ, %xmm6"); + asm __volatile__("movups vecZ, %xmm7"); + asm __volatile__( + "pushl $0\n\t" + "ldmxcsr 0(%esp)\n\t" + "addl $4,%esp\n"); +} + /* set up the FP and SSE state, and then dump it. */ -void do_fxsave ( void* p ) +void do_setup_then_fxsave ( void* p ) { asm __volatile__("finit"); asm __volatile__("fldpi"); @@ -27,7 +67,7 @@ void do_fxsave ( void* p ) asm __volatile__("movaps %xmm2, %xmm6"); asm __volatile__("movaps %xmm1, %xmm7"); asm __volatile__("xorps %xmm0, %xmm7"); - asm __volatile__("fxsave (%0)" : : "r" (p) : "memory" ); + do_fxsave (p); } int isFPLsbs ( int i ) @@ -44,17 +84,9 @@ int isFPLsbs ( int i ) return 0; } -int main ( int argc, char** argv ) +void show ( unsigned char* buf, int xx ) { int i; - unsigned char* buf = malloc(512); - int xx = argc > 1; - printf("Re-run with any arg to suppress least-significant\n" - " 16 bits of FP numbers\n"); - for (i = 0; i < 512; i++) - buf[i] = 0xFF; - - do_fxsave(buf); for (i = 0; i < 512; i++) { if ((i % 16) == 0) printf("%3d ", i); @@ -65,5 +97,40 @@ int main ( int argc, char** argv ) if (i > 0 && ((i % 16) == 15)) printf("\n"); } +} + + +int main ( int argc, char** argv ) +{ + unsigned char* buf1 = memalign(16,512); + unsigned char* buf2 = memalign(16,512); + unsigned char* buf3 = memalign(16,512); + int xx = argc > 1; + printf("Re-run with any arg to suppress least-significant\n" + " 16 bits of FP numbers\n"); + memset(buf1, 0x55, 512); + memset(buf2, 0x55, 512); + memset(buf3, 0x55, 512); + + /* Load up x87/xmm state and dump it. */ + do_setup_then_fxsave(buf1); + printf("\nBEFORE\n"); + show(buf1, xx); + + /* Zeroise x87/xmm state and dump it, to show that the + regs have been cleared out. */ + do_zeroise(); + do_fxsave(buf2); + printf("\nZEROED\n"); + show(buf2, xx); + + /* Reload x87/xmm state from buf1 and dump it in buf3. */ + do_fxrstor(buf1); + do_fxsave(buf3); + printf("\nRESTORED\n"); + show(buf3, xx); + + free(buf1); free(buf2); free(buf3); + return 0; }