Revision 9d8e9c09 tests/test-i386.c

b/tests/test-i386.c
424 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 527
static void *call_end __init_call = NULL;
429 528

  
......
437 536
        func = *ptr++;
438 537
        func();
439 538
    }
539
    test_bsx();
440 540
    test_mul();
441 541
    test_jcc();
442 542
    test_lea();
543
    test_floats();
443 544
    return 0;
444 545
}

Also available in: Unified diff