7 const unsigned int vec0
[4]
8 = { 0x12345678, 0x11223344, 0x55667788, 0x87654321 };
10 const unsigned int vec1
[4]
11 = { 0xABCDEF01, 0xAABBCCDD, 0xEEFF0011, 0x10FEDCBA };
13 const unsigned int vecZ
[4]
16 void do_fxsave ( void* p
) {
17 asm __volatile__("fxsave (%0)" : : "r" (p
) : "memory" );
20 void do_fxrstor ( void* p
) {
21 asm __volatile__("fxrstor (%0)" : : "r" (p
) : "memory" );
24 void do_zeroise ( void )
26 asm __volatile__("finit");
37 asm __volatile__("movups vecZ, %xmm0");
38 asm __volatile__("movups vecZ, %xmm1");
39 asm __volatile__("movups vecZ, %xmm2");
40 asm __volatile__("movups vecZ, %xmm3");
41 asm __volatile__("movups vecZ, %xmm4");
42 asm __volatile__("movups vecZ, %xmm5");
43 asm __volatile__("movups vecZ, %xmm6");
44 asm __volatile__("movups vecZ, %xmm7");
51 /* set up the FP and SSE state, and then dump it. */
52 void do_setup_then_fxsave ( void* p
)
54 asm __volatile__("finit");
55 asm __volatile__("fldpi");
56 asm __volatile__("fld1");
57 asm __volatile__("fldln2");
58 asm __volatile__("fldlg2");
59 asm __volatile__("fld %st(3)");
60 asm __volatile__("fld %st(3)");
61 asm __volatile__("movups vec0, %xmm0");
62 asm __volatile__("movups vec1, %xmm1");
63 asm __volatile__("xorps %xmm2, %xmm2");
64 asm __volatile__("movaps %xmm2, %xmm3");
65 asm __volatile__("movaps %xmm2, %xmm4");
66 asm __volatile__("movaps %xmm2, %xmm5");
67 asm __volatile__("movaps %xmm2, %xmm6");
68 asm __volatile__("movaps %xmm1, %xmm7");
69 asm __volatile__("xorps %xmm0, %xmm7");
73 int isFPLsbs ( int i
)
76 q
= 32; if (i
== q
|| i
== q
+1) return 1;
77 q
= 48; if (i
== q
|| i
== q
+1) return 1;
78 q
= 64; if (i
== q
|| i
== q
+1) return 1;
79 q
= 80; if (i
== q
|| i
== q
+1) return 1;
80 q
= 96; if (i
== q
|| i
== q
+1) return 1;
81 q
= 112; if (i
== q
|| i
== q
+1) return 1;
82 q
= 128; if (i
== q
|| i
== q
+1) return 1;
83 q
= 144; if (i
== q
|| i
== q
+1) return 1;
87 void show ( unsigned char* buf
, int xx
)
90 for (i
= 0; i
< 512; i
++) {
93 if (xx
&& isFPLsbs(i
))
96 printf("%02x ", buf
[i
]);
97 if (i
> 0 && ((i
% 16) == 15))
103 int main ( int argc
, char** argv
)
105 unsigned char* buf1
= memalign(16,512);
106 unsigned char* buf2
= memalign(16,512);
107 unsigned char* buf3
= memalign(16,512);
109 printf("Re-run with any arg to suppress least-significant\n"
110 " 16 bits of FP numbers\n");
111 memset(buf1
, 0x55, 512);
112 memset(buf2
, 0x55, 512);
113 memset(buf3
, 0x55, 512);
115 /* Load up x87/xmm state and dump it. */
116 do_setup_then_fxsave(buf1
);
117 printf("\nBEFORE\n");
120 /* Zeroise x87/xmm state and dump it, to show that the
121 regs have been cleared out. */
124 printf("\nZEROED\n");
127 /* Reload x87/xmm state from buf1 and dump it in buf3. */
130 printf("\nRESTORED\n");
133 free(buf1
); free(buf2
); free(buf3
);