The snippets there are not suitable for testsuite integration.
Some compile with warnings or not at all (x87fxam.c, x87tst.c),
fpucw.c has no meaningful output. The remaining ones test x87
FPU state save / restore by dumping the state as hex bytes. That
would result in several .exp files because FPU state contains
instruction and data addresses.
+++ /dev/null
-
-#include <stdio.h>
-#include <stdlib.h>
-
-void do_fstenv ( void* p )
-{
- asm("movl 8(%esp), %eax ; fstenv (%eax)");
-}
-
-void do_fldenv ( void* p )
-{
- asm("movl 8(%esp), %eax ; fldenv (%eax)");
-}
-
-int main ( void )
-{
- int i;
- unsigned short* buf = malloc(14*sizeof(short));
- for (i = 0; i < 14; i++)
- buf[i] = i;
- buf[0] = 0x037f;
-
- do_fldenv(buf);
- do_fstenv(buf);
- for (i = 0; i < 14; i++) {
- printf("%04x ", buf[i]);
- if (i > 0 && ((i % 12) == 11))
- printf("\n");
- }
- printf("\n");
- return 0;
-}
+++ /dev/null
-
-#include <stdio.h>
-
-void fldcw_default ( void )
-{
- asm(" pushw $0x037F ; fldcw (%esp) ; addl $2, %esp");
-}
-
-void fldcw_exns ( void )
-{
- asm(" pushw $0x037E ; fldcw (%esp) ; addl $2, %esp");
-}
-
-void fldcw_precision ( void )
-{
- asm(" pushw $0x007F ; fldcw (%esp) ; addl $2, %esp");
-}
-
-void fldcw_rounding ( void )
-{
- asm(" pushw $0x077F ; fldcw (%esp) ; addl $2, %esp");
-}
-
-int main ( void )
-{
- printf("default\n");
- fldcw_default();
- printf("\n");
-
- printf("exns\n");
- fldcw_exns();
- printf("\n");
-
- printf("precision\n");
- fldcw_precision();
- printf("\n");
-
- printf("rounding\n");
- fldcw_rounding();
- printf("\n");
-
- return 0;
-}
+++ /dev/null
-
-#include <stdio.h>
-#include <stdlib.h>
-
-void do_fsave_interesting_stuff ( void* p )
-{
- asm __volatile__("fninit");
- asm __volatile__("fldpi");
- asm __volatile__("fld1");
- asm __volatile__("fldln2");
- asm __volatile__("fsave (%0)" : : "r" (p) : "memory" );
-}
-
-void do_fsave ( void* p )
-{
- asm __volatile__("fsave (%0)" : : "r" (p) : "memory" );
-}
-
-void do_frstor ( void* p )
-{
- asm __volatile__("frstor (%0)" : : "r" (p) : "memory" );
-}
-
-
-int isFPLsbs ( int i )
-{
- int q;
- q = 0; if (i == q || i == q+1) return 1;
- q = 10; if (i == q || i == q+1) return 1;
- q = 20; if (i == q || i == q+1) return 1;
- q = 30; if (i == q || i == q+1) return 1;
- q = 40; if (i == q || i == q+1) return 1;
- q = 50; if (i == q || i == q+1) return 1;
- q = 60; if (i == q || i == q+1) return 1;
- q = 70; if (i == q || i == q+1) return 1;
- return 0;
-}
-
-void show_fpustate ( unsigned char* buf, int hide64to80 )
-{
- int i;
- printf(" 0 ");
- for (i = 0; i < 14; i++)
- printf("%02x ", buf[i]);
- printf("\n");
-
- printf(" 14 ");
- for (i = 14; i < 28; i++)
- printf("%02x ", buf[i]);
- printf("\n");
-
- for (i = 0; i < 80; i++) {
- if ((i % 10) == 0)
- printf("%3d ", i+28);
- if (hide64to80 && isFPLsbs(i))
- printf("xx ");
- else
- printf("%02x ", buf[i+28]);
- if (i > 0 && ((i % 10) == 9))
- printf("\n");
- }
-}
-
-int main ( int argc, char** argv )
-{
- unsigned short* buf1 = malloc(54*sizeof(short));
- unsigned short* buf2 = malloc(54*sizeof(short));
- int xx = argc > 1;
- printf("Re-run with any arg to suppress least-significant\n"
- " 16 bits of FP numbers\n");
-
- /* Create an initial image. */
- do_fsave_interesting_stuff(buf1);
- show_fpustate( (unsigned char*)buf1, xx );
-
- /* Reload it into buf2. */
- do_frstor(buf1);
- do_fsave(buf2);
- show_fpustate( (unsigned char*)buf2, xx );
-
- return 0;
-}
+++ /dev/null
-
-#include <stdio.h>
-#include <stdlib.h>
-
-void do_fsave ( void* p )
-{
- asm __volatile__("fninit");
- asm __volatile__("fldpi");
- asm __volatile__("fld1");
- asm __volatile__("fldln2");
- asm __volatile__("fsave (%0)" : : "r" (p) : "memory" );
-}
-
-int isFPLsbs ( int i )
-{
- int q;
- q = 0; if (i == q || i == q+1) return 1;
- q = 10; if (i == q || i == q+1) return 1;
- q = 20; if (i == q || i == q+1) return 1;
- q = 30; if (i == q || i == q+1) return 1;
- q = 40; if (i == q || i == q+1) return 1;
- q = 50; if (i == q || i == q+1) return 1;
- q = 60; if (i == q || i == q+1) return 1;
- q = 70; if (i == q || i == q+1) return 1;
- return 0;
-}
-
-void show_fpustate ( unsigned char* buf, int hide64to80 )
-{
- int i;
- printf(" 0 ");
- for (i = 0; i < 14; i++)
- printf("%02x ", buf[i]);
- printf("\n");
-
- printf(" 14 ");
- for (i = 14; i < 28; i++)
- printf("%02x ", buf[i]);
- printf("\n");
-
- for (i = 0; i < 80; i++) {
- if ((i % 10) == 0)
- printf("%3d ", i+28);
- if (hide64to80 && isFPLsbs(i))
- printf("xx ");
- else
- printf("%02x ", buf[i+28]);
- if (i > 0 && ((i % 10) == 9))
- printf("\n");
- }
-}
-
-int main ( int argc, char** argv )
-{
- int i;
- unsigned char* buf = malloc(108);
- 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 < 108; i++)
- buf[i] = 0xAA;
-
- /* dump FPU state in buf, and show it. */
- do_fsave(buf);
- show_fpustate( buf, xx );
-
- return 0;
-}
+++ /dev/null
-
-#include <stdio.h>
-#include <stdlib.h>
-
-void do_fstenv ( void* p )
-{
- asm("fldpi ; fld1; fldln2 ; movl 8(%esp), %eax ; fstenv (%eax)");
-}
-
-int main ( void )
-{
- int i;
- unsigned int* buf = malloc(7*sizeof(int));
- do_fstenv(buf);
- for (i = 0; i < 7; i++) {
- printf("%08x ", buf[i]);
- if (i > 0 && ((i % 6) == 5))
- printf("\n");
- }
- printf("\n");
- return 0;
-}
+++ /dev/null
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <malloc.h>
-#include <string.h>
-
-const unsigned int vec0[4]
- = { 0x12345678, 0x11223344, 0x55667788, 0x87654321 };
-
-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_setup_then_fxsave ( void* p )
-{
- asm __volatile__("finit");
- asm __volatile__("fldpi");
- asm __volatile__("fld1");
- asm __volatile__("fldln2");
- asm __volatile__("fldlg2");
- asm __volatile__("fld %st(3)");
- asm __volatile__("fld %st(3)");
- asm __volatile__("movups vec0, %xmm0");
- asm __volatile__("movups vec1, %xmm1");
- asm __volatile__("xorps %xmm2, %xmm2");
- asm __volatile__("movaps %xmm2, %xmm3");
- asm __volatile__("movaps %xmm2, %xmm4");
- asm __volatile__("movaps %xmm2, %xmm5");
- asm __volatile__("movaps %xmm2, %xmm6");
- asm __volatile__("movaps %xmm1, %xmm7");
- asm __volatile__("xorps %xmm0, %xmm7");
- do_fxsave (p);
-}
-
-int isFPLsbs ( int i )
-{
- int q;
- q = 32; if (i == q || i == q+1) return 1;
- q = 48; if (i == q || i == q+1) return 1;
- q = 64; if (i == q || i == q+1) return 1;
- q = 80; if (i == q || i == q+1) return 1;
- q = 96; if (i == q || i == q+1) return 1;
- q = 112; if (i == q || i == q+1) return 1;
- q = 128; if (i == q || i == q+1) return 1;
- q = 144; if (i == q || i == q+1) return 1;
- return 0;
-}
-
-void show ( unsigned char* buf, int xx )
-{
- int i;
- for (i = 0; i < 512; i++) {
- if ((i % 16) == 0)
- printf("%3d ", i);
- if (xx && isFPLsbs(i))
- printf("xx ");
- else
- printf("%02x ", buf[i]);
- 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;
-}
+++ /dev/null
-
-#include <stdio.h>
-#include <math.h>
-
-double d;
-int i;
-
-extern void do_fxam ( void );
-
-asm(
-"\n"
-"do_fxam:\n"
-"\txorl %eax,%eax\n"
-"\tfld d\n"
-"\tfxam\n"
-"\tfnstsw %ax\n"
-"\tffree %st(0)\n"
-"\tmovl %eax, i\n"
-"\tret\n"
-);
-
-
-double inf ( void ) { return 1.0 / 0.0; }
-double nAn ( void ) { return 0.0 / 0.0; }
-double den ( void ) { return 9.1e-220 / 1e100; }
-
-/* Try positive and negative variants of: zero, infinity,
- nAn, and denorm */
-
-int main ( void )
-{
- d = 0.0; do_fxam(); printf("0x%4x: %f\n", i, d );
- d = -0.0; do_fxam(); printf("0x%4x: %f\n", i, d );
-
- d = inf(); do_fxam(); printf("0x%4x: %f\n", i, d );
- d = -inf(); do_fxam(); printf("0x%4x: %f\n", i, d );
-
- d = nAn(); do_fxam(); printf("0x%4x: %f\n", i, d );
- d = -nAn(); do_fxam(); printf("0x%4x: %f\n", i, d );
-
- d = den(); do_fxam(); printf("0x%4x: %f\n", i, d );
- d = -den(); do_fxam(); printf("0x%4x: %f\n", i, d );
- return 0;
-}
+++ /dev/null
-
-#include <stdio.h>
-#include <math.h>
-
-double d;
-int i;
-
-extern void do_tst ( void );
-
-asm(
-"\n"
-"do_tst:\n"
-"\txorl %eax,%eax\n"
-"\tfld d\n"
-"\tftst\n"
-"\tfnstsw %ax\n"
-"\tmovl %eax, i\n"
-"\tret\n"
-);
-
-int main ( void )
-{
- d = -1.23; do_tst(); printf("%f -> 0x%x\n", d, i );
- d = 0.0; do_tst(); printf("%f -> 0x%x\n", d, i );
- d = 9.87; do_tst(); printf("%f -> 0x%x\n", d, i );
- return 0;
-}