1 |
|
/* |
2 |
|
* fpu/mathlib.h - Floating-point math support library |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2001 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2008 Christian Bauer |
5 |
|
* |
6 |
|
* MC68881/68040 fpu emulation |
7 |
|
* |
395 |
|
return (int)(((uae_u32)(se)) >> 16); |
396 |
|
#endif |
397 |
|
#else |
398 |
< |
#ifndef USE_LONG_DOUBLE |
399 |
< |
fp_declare_init_shape(sxp, r, double); |
400 |
< |
return (sxp->ieee_nan.exponent == FP_DOUBLE_EXP_MAX) |
401 |
< |
#else |
398 |
> |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
399 |
|
fp_declare_init_shape(sxp, r, extended); |
400 |
|
return (sxp->ieee_nan.exponent == FP_EXTENDED_EXP_MAX) |
401 |
+ |
#else |
402 |
+ |
fp_declare_init_shape(sxp, r, double); |
403 |
+ |
return (sxp->ieee_nan.exponent == FP_DOUBLE_EXP_MAX) |
404 |
|
#endif |
405 |
|
&& (sxp->ieee_nan.mantissa0 != 0) |
406 |
|
&& (sxp->ieee_nan.mantissa1 != 0) |
454 |
|
return ~(lx >> 31) & (1 - (se >> 14)); |
455 |
|
#endif |
456 |
|
#else |
457 |
< |
#ifndef USE_LONG_DOUBLE |
458 |
< |
fp_declare_init_shape(sxp, r, double); |
459 |
< |
return (sxp->ieee_nan.exponent == FP_DOUBLE_EXP_MAX) |
460 |
< |
#else |
457 |
> |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
458 |
|
fp_declare_init_shape(sxp, r, extended); |
459 |
|
return (sxp->ieee_nan.exponent == FP_EXTENDED_EXP_MAX) |
460 |
+ |
#else |
461 |
+ |
fp_declare_init_shape(sxp, r, double); |
462 |
+ |
return (sxp->ieee_nan.exponent == FP_DOUBLE_EXP_MAX) |
463 |
|
#endif |
464 |
|
&& (sxp->ieee_nan.mantissa0 == 0) |
465 |
|
&& (sxp->ieee_nan.mantissa1 == 0) |
476 |
|
|
477 |
|
PRIVATE inline bool FFPU fp_do_isneg(fpu_register const & r) |
478 |
|
{ |
479 |
< |
#ifndef USE_LONG_DOUBLE |
480 |
< |
fp_declare_init_shape(sxp, r, double); |
481 |
< |
#else |
479 |
> |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
480 |
|
fp_declare_init_shape(sxp, r, extended); |
481 |
+ |
#else |
482 |
+ |
fp_declare_init_shape(sxp, r, double); |
483 |
|
#endif |
484 |
|
return sxp->ieee.negative; |
485 |
|
} |
490 |
|
PRIVATE inline bool FFPU fp_do_iszero(fpu_register const & r) |
491 |
|
{ |
492 |
|
// TODO: BRANCHES_ARE_EXPENSIVE |
493 |
< |
#ifndef USE_LONG_DOUBLE |
494 |
< |
fp_declare_init_shape(sxp, r, double); |
495 |
< |
#else |
493 |
> |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
494 |
|
fp_declare_init_shape(sxp, r, extended); |
495 |
+ |
#else |
496 |
+ |
fp_declare_init_shape(sxp, r, double); |
497 |
|
#endif |
498 |
|
return (sxp->ieee.exponent == 0) |
499 |
|
&& (sxp->ieee.mantissa0 == 0) |
526 |
|
PRIVATE inline void FFPU make_nan(fpu_register & r) |
527 |
|
{ |
528 |
|
// FIXME: is that correct ? |
529 |
< |
#ifndef USE_LONG_DOUBLE |
530 |
< |
fp_declare_init_shape(sxp, r, double); |
531 |
< |
sxp->ieee.exponent = FP_DOUBLE_EXP_MAX; |
532 |
< |
sxp->ieee.mantissa0 = 0xfffff; |
533 |
< |
#else |
529 |
> |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
530 |
|
fp_declare_init_shape(sxp, r, extended); |
531 |
|
sxp->ieee.exponent = FP_EXTENDED_EXP_MAX; |
532 |
|
sxp->ieee.mantissa0 = 0xffffffff; |
533 |
+ |
#else |
534 |
+ |
fp_declare_init_shape(sxp, r, double); |
535 |
+ |
sxp->ieee.exponent = FP_DOUBLE_EXP_MAX; |
536 |
+ |
sxp->ieee.mantissa0 = 0xfffff; |
537 |
|
#endif |
538 |
|
sxp->ieee.mantissa1 = 0xffffffff; |
539 |
|
#ifdef USE_QUAD_DOUBLE |
547 |
|
#if 1 |
548 |
|
r = +0.0; |
549 |
|
#else |
550 |
< |
#ifndef USE_LONG_DOUBLE |
551 |
< |
fp_declare_init_shape(sxp, r, double); |
552 |
< |
#else |
550 |
> |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
551 |
|
fp_declare_init_shape(sxp, r, extended); |
552 |
+ |
#else |
553 |
+ |
fp_declare_init_shape(sxp, r, double); |
554 |
|
#endif |
555 |
|
sxp->ieee.negative = 0; |
556 |
|
sxp->ieee.exponent = 0; |
568 |
|
#if 1 |
569 |
|
r = -0.0; |
570 |
|
#else |
571 |
< |
#ifndef USE_LONG_DOUBLE |
572 |
< |
fp_declare_init_shape(sxp, r, double); |
573 |
< |
#else |
571 |
> |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
572 |
|
fp_declare_init_shape(sxp, r, extended); |
573 |
+ |
#else |
574 |
+ |
fp_declare_init_shape(sxp, r, double); |
575 |
|
#endif |
576 |
|
sxp->ieee.negative = 1; |
577 |
|
sxp->ieee.exponent = 0; |
586 |
|
|
587 |
|
PRIVATE inline void FFPU make_inf_positive(fpu_register & r) |
588 |
|
{ |
589 |
< |
#ifndef USE_LONG_DOUBLE |
590 |
< |
fp_declare_init_shape(sxp, r, double); |
591 |
< |
sxp->ieee_nan.exponent = FP_DOUBLE_EXP_MAX; |
592 |
< |
#else |
589 |
> |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
590 |
|
fp_declare_init_shape(sxp, r, extended); |
591 |
|
sxp->ieee_nan.exponent = FP_EXTENDED_EXP_MAX; |
592 |
+ |
#else |
593 |
+ |
fp_declare_init_shape(sxp, r, double); |
594 |
+ |
sxp->ieee_nan.exponent = FP_DOUBLE_EXP_MAX; |
595 |
|
#endif |
596 |
|
sxp->ieee_nan.negative = 0; |
597 |
|
sxp->ieee_nan.mantissa0 = 0; |
604 |
|
|
605 |
|
PRIVATE inline void FFPU make_inf_negative(fpu_register & r) |
606 |
|
{ |
607 |
< |
#ifndef USE_LONG_DOUBLE |
608 |
< |
fp_declare_init_shape(sxp, r, double); |
609 |
< |
sxp->ieee_nan.exponent = FP_DOUBLE_EXP_MAX; |
610 |
< |
#else |
607 |
> |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
608 |
|
fp_declare_init_shape(sxp, r, extended); |
609 |
|
sxp->ieee_nan.exponent = FP_EXTENDED_EXP_MAX; |
610 |
+ |
#else |
611 |
+ |
fp_declare_init_shape(sxp, r, double); |
612 |
+ |
sxp->ieee_nan.exponent = FP_DOUBLE_EXP_MAX; |
613 |
|
#endif |
614 |
|
sxp->ieee_nan.negative = 1; |
615 |
|
sxp->ieee_nan.mantissa0 = 0; |
622 |
|
|
623 |
|
PRIVATE inline fpu_register FFPU fast_fgetexp(fpu_register const & r) |
624 |
|
{ |
625 |
< |
#ifndef USE_LONG_DOUBLE |
626 |
< |
fp_declare_init_shape(sxp, r, double); |
627 |
< |
return (sxp->ieee.exponent - FP_DOUBLE_EXP_BIAS); |
628 |
< |
#else |
625 |
> |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
626 |
|
fp_declare_init_shape(sxp, r, extended); |
627 |
|
return (sxp->ieee.exponent - FP_EXTENDED_EXP_BIAS); |
628 |
+ |
#else |
629 |
+ |
fp_declare_init_shape(sxp, r, double); |
630 |
+ |
return (sxp->ieee.exponent - FP_DOUBLE_EXP_BIAS); |
631 |
|
#endif |
632 |
|
} |
633 |
|
|
634 |
|
// Normalize to range 1..2 |
635 |
|
PRIVATE inline void FFPU fast_remove_exponent(fpu_register & r) |
636 |
|
{ |
637 |
< |
#ifndef USE_LONG_DOUBLE |
638 |
< |
fp_declare_init_shape(sxp, r, double); |
639 |
< |
sxp->ieee.exponent = FP_DOUBLE_EXP_BIAS; |
640 |
< |
#else |
637 |
> |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
638 |
|
fp_declare_init_shape(sxp, r, extended); |
639 |
|
sxp->ieee.exponent = FP_EXTENDED_EXP_BIAS; |
640 |
+ |
#else |
641 |
+ |
fp_declare_init_shape(sxp, r, double); |
642 |
+ |
sxp->ieee.exponent = FP_DOUBLE_EXP_BIAS; |
643 |
|
#endif |
644 |
|
} |
645 |
|
|
647 |
|
// of the source and destination operands. |
648 |
|
PRIVATE inline uae_u32 FFPU get_quotient_sign(fpu_register const & ra, fpu_register const & rb) |
649 |
|
{ |
650 |
< |
#ifndef USE_LONG_DOUBLE |
651 |
< |
fp_declare_init_shape(sap, ra, double); |
652 |
< |
fp_declare_init_shape(sbp, rb, double); |
653 |
< |
#else |
650 |
> |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
651 |
|
fp_declare_init_shape(sap, ra, extended); |
652 |
|
fp_declare_init_shape(sbp, rb, extended); |
653 |
+ |
#else |
654 |
+ |
fp_declare_init_shape(sap, ra, double); |
655 |
+ |
fp_declare_init_shape(sbp, rb, double); |
656 |
|
#endif |
657 |
|
return ((sap->ieee.negative ^ sbp->ieee.negative) ? FPSR_QUOTIENT_SIGN : 0); |
658 |
|
} |
661 |
|
/* --- Math functions --- */ |
662 |
|
/* -------------------------------------------------------------------------- */ |
663 |
|
|
664 |
< |
#if FPU_USE_ISO_C99 && USE_LONG_DOUBLE |
664 |
> |
#if FPU_USE_ISO_C99 && (USE_LONG_DOUBLE || USE_QUAD_DOUBLE) |
665 |
|
# ifdef HAVE_LOGL |
666 |
|
# define fp_log logl |
667 |
|
# endif |
785 |
|
# define fp_ceil ceil |
786 |
|
#endif |
787 |
|
|
788 |
< |
#if defined(FPU_IEEE) && defined(X86_ASSEMBLY) |
788 |
> |
#if defined(FPU_IEEE) && defined(USE_X87_ASSEMBLY) |
789 |
|
// Assembly optimized support functions. Taken from glibc 2.2.2 |
790 |
|
|
791 |
|
#undef fp_log |
923 |
|
|
924 |
|
PRIVATE inline fpu_extended fp_do_sgn1(fpu_extended x) |
925 |
|
{ |
926 |
+ |
#if USE_LONG_DOUBLE || USE_QUAD_DOUBLE |
927 |
|
fp_declare_init_shape(sxp, x, extended); |
928 |
|
sxp->ieee_nan.exponent = FP_EXTENDED_EXP_MAX; |
929 |
|
sxp->ieee_nan.one = 1; |
930 |
+ |
#else |
931 |
+ |
fp_declare_init_shape(sxp, x, double); |
932 |
+ |
sxp->ieee_nan.exponent = FP_DOUBLE_EXP_MAX; |
933 |
+ |
#endif |
934 |
|
sxp->ieee_nan.quiet_nan = 0; |
935 |
|
sxp->ieee_nan.mantissa0 = 0; |
936 |
|
sxp->ieee_nan.mantissa1 = 0; |
1110 |
|
|
1111 |
|
DEFINE_ROUND_FUNC(nearest, 0x000) |
1112 |
|
|
1113 |
< |
#endif /* X86_ASSEMBLY */ |
1113 |
> |
#endif /* USE_X87_ASSEMBLY */ |
1114 |
|
|
1115 |
|
#ifndef fp_round_to_minus_infinity |
1116 |
|
#define fp_round_to_minus_infinity(x) fp_floor(x) |