5 #include "tests/malloc.h"
8 const unsigned int vec0
[4]
9 = { 0x12345678, 0x11223344, 0x55667788, 0x87654321 };
11 const unsigned int vec1
[4]
12 = { 0xABCDEF01, 0xAABBCCDD, 0xEEFF0011, 0x10FEDCBA };
14 const unsigned int vecZ
[4]
17 void do_fxsave ( void* p
) {
18 asm __volatile__("fxsave (%0)" : : "r" (p
) : "memory" );
21 void do_fxrstor ( void* p
) {
22 asm __volatile__("fxrstor (%0)" : : "r" (p
) : "memory" );
25 void do_zeroise ( void )
27 asm __volatile__("finit");
38 asm __volatile__("movups " VG_SYM(vecZ
) ", %xmm0");
39 asm __volatile__("movups " VG_SYM(vecZ
) ", %xmm1");
40 asm __volatile__("movups " VG_SYM(vecZ
) ", %xmm2");
41 asm __volatile__("movups " VG_SYM(vecZ
) ", %xmm3");
42 asm __volatile__("movups " VG_SYM(vecZ
) ", %xmm4");
43 asm __volatile__("movups " VG_SYM(vecZ
) ", %xmm5");
44 asm __volatile__("movups " VG_SYM(vecZ
) ", %xmm6");
45 asm __volatile__("movups " VG_SYM(vecZ
) ", %xmm7");
52 /* set up the FP and SSE state, and then dump it. */
53 void do_setup_then_fxsave ( void* p
)
55 asm __volatile__("finit");
56 asm __volatile__("fldpi");
57 asm __volatile__("fld1");
58 asm __volatile__("fldln2");
59 asm __volatile__("fldlg2");
60 asm __volatile__("fld %st(3)");
61 asm __volatile__("fld %st(3)");
62 asm __volatile__("movups " VG_SYM(vec0
) ", %xmm0");
63 asm __volatile__("movups " VG_SYM(vec1
) ", %xmm1");
64 asm __volatile__("xorps %xmm2, %xmm2");
65 asm __volatile__("movaps %xmm2, %xmm3");
66 asm __volatile__("movaps %xmm2, %xmm4");
67 asm __volatile__("movaps %xmm2, %xmm5");
68 asm __volatile__("movaps %xmm2, %xmm6");
69 asm __volatile__("movaps %xmm1, %xmm7");
70 asm __volatile__("xorps %xmm0, %xmm7");
74 int isFPLsbs ( int i
)
77 q
= 32; if (i
== q
|| i
== q
+1) return 1;
78 q
= 48; if (i
== q
|| i
== q
+1) return 1;
79 q
= 64; if (i
== q
|| i
== q
+1) return 1;
80 q
= 80; if (i
== q
|| i
== q
+1) return 1;
81 q
= 96; if (i
== q
|| i
== q
+1) return 1;
82 q
= 112; if (i
== q
|| i
== q
+1) return 1;
83 q
= 128; if (i
== q
|| i
== q
+1) return 1;
84 q
= 144; if (i
== q
|| i
== q
+1) return 1;
88 void show ( unsigned char* buf
, int xx
)
91 for (i
= 0; i
< 512; i
++) {
94 if (xx
&& isFPLsbs(i
))
97 printf("%02x ", buf
[i
]);
98 if (i
> 0 && ((i
% 16) == 15))
104 int main ( int argc
, char** argv
)
106 unsigned char* buf1
= memalign16(512);
107 unsigned char* buf2
= memalign16(512);
108 unsigned char* buf3
= memalign16(512);
110 printf("Re-run with any arg to suppress least-significant\n"
111 " 16 bits of FP numbers\n");
112 memset(buf1
, 0x55, 512);
113 memset(buf2
, 0x55, 512);
114 memset(buf3
, 0x55, 512);
116 /* Load up x87/xmm state and dump it. */
117 do_setup_then_fxsave(buf1
);
118 printf("\nBEFORE\n");
121 /* Zeroise x87/xmm state and dump it, to show that the
122 regs have been cleared out. */
125 printf("\nZEROED\n");
128 /* Reload x87/xmm state from buf1 and dump it in buf3. */
131 printf("\nRESTORED\n");
134 free(buf1
); free(buf2
); free(buf3
);