Commit 9d8e9c09932455a21c57559925def82361b23a09
1 parent
d57c4e01
bsx/float tests
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@21 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
103 additions
and
2 deletions
tests/Makefile
| @@ -13,14 +13,14 @@ hello: hello.c | @@ -13,14 +13,14 @@ hello: hello.c | ||
| 13 | $(CC) -nostdlib $(CFLAGS) -static $(LDFLAGS) -o $@ $< | 13 | $(CC) -nostdlib $(CFLAGS) -static $(LDFLAGS) -o $@ $< |
| 14 | 14 | ||
| 15 | test1: test1.c | 15 | test1: test1.c |
| 16 | - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< | 16 | + $(CC) $(CFLAGS) -static $(LDFLAGS) -o $@ $< |
| 17 | 17 | ||
| 18 | test2: test2.c | 18 | test2: test2.c |
| 19 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< | 19 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< |
| 20 | 20 | ||
| 21 | # i386 emulation test (dump various opcodes) */ | 21 | # i386 emulation test (dump various opcodes) */ |
| 22 | test-i386: test-i386.c test-i386.h test-i386-shift.h test-i386-muldiv.h | 22 | test-i386: test-i386.c test-i386.h test-i386-shift.h test-i386-muldiv.h |
| 23 | - $(CC) $(CFLAGS) $(LDFLAGS) -static -o $@ $< | 23 | + $(CC) $(CFLAGS) $(LDFLAGS) -static -o $@ $< -lm |
| 24 | 24 | ||
| 25 | test: test-i386 | 25 | test: test-i386 |
| 26 | ./test-i386 > test-i386.ref | 26 | ./test-i386 > test-i386.ref |
tests/test-i386.c
| @@ -424,6 +424,105 @@ void test_mul(void) | @@ -424,6 +424,105 @@ void test_mul(void) | ||
| 424 | test_divl(0x12343, 0x12345678, 0x81234567); | 424 | test_divl(0x12343, 0x12345678, 0x81234567); |
| 425 | } | 425 | } |
| 426 | 426 | ||
| 427 | +#define TEST_BSX(op, size, op0)\ | ||
| 428 | +{\ | ||
| 429 | + int res, val, resz;\ | ||
| 430 | + val = op0;\ | ||
| 431 | + asm("xorl %1, %1 ; " #op " %" size "2, %" size "0 ; setz %b1" \ | ||
| 432 | + : "=r" (res), "=q" (resz)\ | ||
| 433 | + : "g" (val));\ | ||
| 434 | + printf("%-10s A=%08x R=%08x %d\n", #op, val, resz ? 0 : res, resz);\ | ||
| 435 | +} | ||
| 436 | + | ||
| 437 | +void test_bsx(void) | ||
| 438 | +{ | ||
| 439 | + TEST_BSX(bsrw, "w", 0); | ||
| 440 | + TEST_BSX(bsrw, "w", 0x12340128); | ||
| 441 | + TEST_BSX(bsrl, "", 0); | ||
| 442 | + TEST_BSX(bsrl, "", 0x00340128); | ||
| 443 | + TEST_BSX(bsfw, "w", 0); | ||
| 444 | + TEST_BSX(bsfw, "w", 0x12340128); | ||
| 445 | + TEST_BSX(bsfl, "", 0); | ||
| 446 | + TEST_BSX(bsfl, "", 0x00340128); | ||
| 447 | +} | ||
| 448 | + | ||
| 449 | +void test_fops(double a, double b) | ||
| 450 | +{ | ||
| 451 | + printf("a=%f b=%f a+b=%f\n", a, b, a + b); | ||
| 452 | + printf("a=%f b=%f a-b=%f\n", a, b, a - b); | ||
| 453 | + printf("a=%f b=%f a*b=%f\n", a, b, a * b); | ||
| 454 | + printf("a=%f b=%f a/b=%f\n", a, b, a / b); | ||
| 455 | + printf("a=%f b=%f fmod(a, b)=%f\n", a, b, fmod(a, b)); | ||
| 456 | + printf("a=%f sqrt(a)=%f\n", a, sqrt(a)); | ||
| 457 | + printf("a=%f sin(a)=%f\n", a, sin(a)); | ||
| 458 | + printf("a=%f cos(a)=%f\n", a, cos(a)); | ||
| 459 | + printf("a=%f tan(a)=%f\n", a, tan(a)); | ||
| 460 | + printf("a=%f log(a)=%f\n", a, log(a)); | ||
| 461 | + printf("a=%f exp(a)=%f\n", a, exp(a)); | ||
| 462 | + printf("a=%f b=%f atan2(a, b)=%f\n", a, b, atan2(a, b)); | ||
| 463 | + /* just to test some op combining */ | ||
| 464 | + printf("a=%f asin(sin(a))=%f\n", a, asin(sin(a))); | ||
| 465 | + printf("a=%f acos(cos(a))=%f\n", a, acos(cos(a))); | ||
| 466 | + printf("a=%f atan(tan(a))=%f\n", a, atan(tan(a))); | ||
| 467 | + | ||
| 468 | +} | ||
| 469 | + | ||
| 470 | +void test_fcmp(double a, double b) | ||
| 471 | +{ | ||
| 472 | + printf("(%f<%f)=%d\n", | ||
| 473 | + a, b, a < b); | ||
| 474 | + printf("(%f<=%f)=%d\n", | ||
| 475 | + a, b, a <= b); | ||
| 476 | + printf("(%f==%f)=%d\n", | ||
| 477 | + a, b, a == b); | ||
| 478 | + printf("(%f>%f)=%d\n", | ||
| 479 | + a, b, a > b); | ||
| 480 | + printf("(%f<=%f)=%d\n", | ||
| 481 | + a, b, a >= b); | ||
| 482 | +} | ||
| 483 | + | ||
| 484 | +void test_fcvt(double a) | ||
| 485 | +{ | ||
| 486 | + float fa; | ||
| 487 | + long double la; | ||
| 488 | + | ||
| 489 | + fa = a; | ||
| 490 | + la = a; | ||
| 491 | + printf("(float)%f = %f\n", a, fa); | ||
| 492 | + printf("(long double)%f = %Lf\n", a, la); | ||
| 493 | + printf("a=%f floor(a)=%f\n", a, floor(a)); | ||
| 494 | + printf("a=%f ceil(a)=%f\n", a, ceil(a)); | ||
| 495 | + printf("a=%f rint(a)=%f\n", a, rint(a)); | ||
| 496 | +} | ||
| 497 | + | ||
| 498 | +#define TEST(N) \ | ||
| 499 | + asm("fld" #N : "=t" (a)); \ | ||
| 500 | + printf("fld" #N "= %f\n", a); | ||
| 501 | + | ||
| 502 | +void test_fconst(void) | ||
| 503 | +{ | ||
| 504 | + double a; | ||
| 505 | + TEST(1); | ||
| 506 | + TEST(l2t); | ||
| 507 | + TEST(l2e); | ||
| 508 | + TEST(pi); | ||
| 509 | + TEST(lg2); | ||
| 510 | + TEST(ln2); | ||
| 511 | + TEST(z); | ||
| 512 | +} | ||
| 513 | + | ||
| 514 | +void test_floats(void) | ||
| 515 | +{ | ||
| 516 | + test_fops(2, 3); | ||
| 517 | + test_fops(1.4, -5); | ||
| 518 | + test_fcmp(2, -1); | ||
| 519 | + test_fcmp(2, 2); | ||
| 520 | + test_fcmp(2, 3); | ||
| 521 | + test_fcvt(1.0/7.0); | ||
| 522 | + test_fcvt(-1.0/9.0); | ||
| 523 | + test_fcvt(1e30); | ||
| 524 | + test_fconst(); | ||
| 525 | +} | ||
| 427 | 526 | ||
| 428 | static void *call_end __init_call = NULL; | 527 | static void *call_end __init_call = NULL; |
| 429 | 528 | ||
| @@ -437,8 +536,10 @@ int main(int argc, char **argv) | @@ -437,8 +536,10 @@ int main(int argc, char **argv) | ||
| 437 | func = *ptr++; | 536 | func = *ptr++; |
| 438 | func(); | 537 | func(); |
| 439 | } | 538 | } |
| 539 | + test_bsx(); | ||
| 440 | test_mul(); | 540 | test_mul(); |
| 441 | test_jcc(); | 541 | test_jcc(); |
| 442 | test_lea(); | 542 | test_lea(); |
| 543 | + test_floats(); | ||
| 443 | return 0; | 544 | return 0; |
| 444 | } | 545 | } |