Commit ea76864009c3d7458b466123ae7cf10daafde53b
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,6 +527,12 @@ void test_fcvt(double a) | ||
| 527 | { | 527 | { |
| 528 | float fa; | 528 | float fa; |
| 529 | long double la; | 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 | fa = a; | 537 | fa = a; |
| 532 | la = a; | 538 | la = a; |
| @@ -535,9 +541,21 @@ void test_fcvt(double a) | @@ -535,9 +541,21 @@ void test_fcvt(double a) | ||
| 535 | printf("a=%016Lx\n", *(long long *)&a); | 541 | printf("a=%016Lx\n", *(long long *)&a); |
| 536 | printf("la=%016Lx %04x\n", *(long long *)&la, | 542 | printf("la=%016Lx %04x\n", *(long long *)&la, |
| 537 | *(unsigned short *)((char *)(&la) + 8)); | 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 | #define TEST(N) \ | 561 | #define TEST(N) \ |
| @@ -625,9 +643,12 @@ void test_floats(void) | @@ -625,9 +643,12 @@ void test_floats(void) | ||
| 625 | test_fcmp(2, -1); | 643 | test_fcmp(2, -1); |
| 626 | test_fcmp(2, 2); | 644 | test_fcmp(2, 2); |
| 627 | test_fcmp(2, 3); | 645 | test_fcmp(2, 3); |
| 646 | + test_fcvt(0.5); | ||
| 647 | + test_fcvt(-0.5); | ||
| 628 | test_fcvt(1.0/7.0); | 648 | test_fcvt(1.0/7.0); |
| 629 | test_fcvt(-1.0/9.0); | 649 | test_fcvt(-1.0/9.0); |
| 630 | - test_fcvt(1e30); | 650 | + test_fcvt(32768); |
| 651 | + test_fcvt(-1e20); | ||
| 631 | test_fconst(); | 652 | test_fconst(); |
| 632 | test_fbcd(1234567890123456); | 653 | test_fbcd(1234567890123456); |
| 633 | test_fbcd(-123451234567890); | 654 | test_fbcd(-123451234567890); |