Home | History | Annotate | Download | only in amd64
      1 
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 
      5 const unsigned int vec0[4]
      6    = { 0x12345678, 0x11223344, 0x55667788, 0x87654321 };
      7 
      8 const unsigned int vec1[4]
      9    = { 0xABCDEF01, 0xAABBCCDD, 0xEEFF0011, 0x10FEDCBA };
     10 
     11 /* set up the FP and SSE state, and then dump it. */
     12 void do_fxsave ( void* p )
     13 {
     14    asm __volatile__("finit");
     15    asm __volatile__("fldpi");
     16    asm __volatile__("fld1");
     17    asm __volatile__("fldln2");
     18    asm __volatile__("fldlg2");
     19    asm __volatile__("fld %st(3)");
     20    asm __volatile__("fld %st(3)");
     21    asm __volatile__("fld1");
     22    asm __volatile__("movups (%0), %%xmm0" : : "r"(&vec0[0]) : "xmm0" );
     23    asm __volatile__("movups (%0), %%xmm1" : : "r"(&vec1[0]) : "xmm1" );
     24    asm __volatile__("xorps  %xmm2, %xmm2");
     25    asm __volatile__("movaps %xmm0, %xmm3");
     26    asm __volatile__("movaps %xmm1, %xmm4");
     27    asm __volatile__("movaps %xmm2, %xmm5");
     28    asm __volatile__("movaps %xmm0, %xmm6");
     29    asm __volatile__("movaps %xmm1, %xmm7");
     30    asm __volatile__("movaps %xmm1, %xmm8");
     31    asm __volatile__("movaps %xmm2, %xmm9");
     32    asm __volatile__("movaps %xmm0, %xmm10");
     33    asm __volatile__("movaps %xmm1, %xmm11");
     34    asm __volatile__("movaps %xmm1, %xmm12");
     35    asm __volatile__("movaps %xmm2, %xmm13");
     36    asm __volatile__("movaps %xmm0, %xmm14");
     37    asm __volatile__("movaps %xmm1, %xmm15");
     38    asm __volatile__("fxsave (%0)" : : "r" (p) : "memory" );
     39 }
     40 
     41 int isFPLsbs ( int i )
     42 {
     43    int q;
     44    q = 32; if (i == q || i == q+1) return 1;
     45    q = 48; if (i == q || i == q+1) return 1;
     46    q = 64; if (i == q || i == q+1) return 1;
     47    q = 80; if (i == q || i == q+1) return 1;
     48    q = 96; if (i == q || i == q+1) return 1;
     49    q = 112; if (i == q || i == q+1) return 1;
     50    q = 128; if (i == q || i == q+1) return 1;
     51    q = 144; if (i == q || i == q+1) return 1;
     52    return 0;
     53 }
     54 
     55 int main ( int argc, char** argv )
     56 {
     57    int i, j;
     58    unsigned char* buf = malloc(512);
     59    int xx = 1; /* argc > 1;
     60    printf("Re-run with any arg to suppress least-significant\n"
     61           "   16 bits of FP numbers\n");
     62 	       */
     63    for (i = 0; i < 512; i++)
     64       buf[i] = 0x55;
     65 
     66    do_fxsave(buf);
     67    for (j = 0; j < 512; j++) {
     68       i = (j & 0xFFF0) + (15 - (j & 0xF));
     69       if ((j % 16) == 0)
     70          printf("%3d   ", j);
     71       if (xx && isFPLsbs(i))
     72 	 printf("xx ");
     73       else
     74          printf("%02x ", buf[i]);
     75       if (j > 0 && ((j % 16) == 15))
     76           printf("\n");
     77    }
     78    return 0;
     79 }
     80