Commit ea76864009c3d7458b466123ae7cf10daafde53b

Authored by bellard
1 parent 43ce4dfe

more precise float rounding tests


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@230 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 25 additions and 4 deletions
tests/test-i386.c
... ... @@ -527,6 +527,12 @@ void test_fcvt(double a)
527 527 {
528 528 float fa;
529 529 long double la;
  530 + int16_t fpuc;
  531 + int i;
  532 + int64_t lla;
  533 + int ia;
  534 + int16_t wa;
  535 + double ra;
530 536  
531 537 fa = a;
532 538 la = a;
... ... @@ -535,9 +541,21 @@ void test_fcvt(double a)
535 541 printf("a=%016Lx\n", *(long long *)&a);
536 542 printf("la=%016Lx %04x\n", *(long long *)&la,
537 543 *(unsigned short *)((char *)(&la) + 8));
538   - printf("a=%f floor(a)=%f\n", a, floor(a));
539   - printf("a=%f ceil(a)=%f\n", a, ceil(a));
540   - printf("a=%f rint(a)=%f\n", a, rint(a));
  544 +
  545 + /* test all roundings */
  546 + asm volatile ("fstcw %0" : "=m" (fpuc));
  547 + for(i=0;i<4;i++) {
  548 + asm volatile ("fldcw %0" : : "m" ((fpuc & ~0x0c00) | (i << 10)));
  549 + asm volatile ("fist %0" : "=m" (wa) : "t" (a));
  550 + asm volatile ("fistl %0" : "=m" (ia) : "t" (a));
  551 + asm volatile ("fistpll %0" : "=m" (lla) : "t" (a) : "st");
  552 + asm volatile ("frndint ; fstl %0" : "=m" (ra) : "t" (a));
  553 + asm volatile ("fldcw %0" : : "m" (fpuc));
  554 + printf("(short)a = %d\n", wa);
  555 + printf("(int)a = %d\n", ia);
  556 + printf("(int64_t)a = %Ld\n", lla);
  557 + printf("rint(a) = %f\n", ra);
  558 + }
541 559 }
542 560  
543 561 #define TEST(N) \
... ... @@ -625,9 +643,12 @@ void test_floats(void)
625 643 test_fcmp(2, -1);
626 644 test_fcmp(2, 2);
627 645 test_fcmp(2, 3);
  646 + test_fcvt(0.5);
  647 + test_fcvt(-0.5);
628 648 test_fcvt(1.0/7.0);
629 649 test_fcvt(-1.0/9.0);
630   - test_fcvt(1e30);
  650 + test_fcvt(32768);
  651 + test_fcvt(-1e20);
631 652 test_fconst();
632 653 test_fbcd(1234567890123456);
633 654 test_fbcd(-123451234567890);
... ...