187 |
|
# endif |
188 |
|
#endif |
189 |
|
} ieee_nan; |
190 |
– |
}; |
190 |
|
|
191 |
< |
#if SIZEOF_LONG_DOUBLE == 12 |
192 |
< |
# undef USE_QUAD_DOUBLE |
193 |
< |
#elif SIZEOF_LONG_DOUBLE == 16 |
194 |
< |
# define USE_QUAD_DOUBLE |
191 |
> |
/* This format is used to extract the sign_exponent and mantissa parts only */ |
192 |
> |
struct { |
193 |
> |
#if UAE_FLOAT_WORD_ORDER == UAE_BIG_ENDIAN |
194 |
> |
unsigned int msw:32; |
195 |
> |
unsigned int lsw:32; |
196 |
|
#else |
197 |
< |
# error "unsupported long double format" |
197 |
> |
unsigned int lsw:32; |
198 |
> |
unsigned int msw:32; |
199 |
|
#endif |
200 |
+ |
} parts; |
201 |
+ |
}; |
202 |
|
|
203 |
< |
#ifndef USE_QUAD_DOUBLE |
203 |
> |
#ifdef USE_LONG_DOUBLE |
204 |
|
// IEEE-854 long double format |
205 |
|
union fpu_extended_shape { |
206 |
|
fpu_extended value; |
278 |
|
#endif |
279 |
|
} parts; |
280 |
|
}; |
281 |
< |
#else |
281 |
> |
#endif |
282 |
> |
|
283 |
> |
#ifdef USE_QUAD_DOUBLE |
284 |
|
// IEEE-854 quad double format |
285 |
|
union fpu_extended_shape { |
286 |
|
fpu_extended value; |
350 |
|
} parts32; |
351 |
|
#endif |
352 |
|
}; |
353 |
< |
#endif // !USE_QUAD_DOUBLE |
353 |
> |
#endif |
354 |
|
|
355 |
|
// Declare and initialize a pointer to a shape of the requested FP type |
356 |
|
#define fp_declare_init_shape(psvar, rfvar, ftype) \ |
370 |
|
|
371 |
|
PRIVATE inline bool FFPU fp_do_isnan(fpu_register const & r) |
372 |
|
{ |
368 |
– |
fp_declare_init_shape(sxp, r, extended); |
373 |
|
#ifdef BRANCHES_ARE_EXPENSIVE |
374 |
< |
#ifdef USE_QUAD_DOUBLE |
374 |
> |
#ifndef USE_LONG_DOUBLE |
375 |
> |
fp_declare_init_shape(sxp, r, double); |
376 |
> |
uae_s32 hx = sxp->parts.msw; |
377 |
> |
uae_s32 lx = sxp->parts.lsw; |
378 |
> |
hx &= 0x7fffffff; |
379 |
> |
hx |= (uae_u32)(lx | (-lx)) >> 31; |
380 |
> |
hx = 0x7ff00000 - hx; |
381 |
> |
return (int)(((uae_u32)hx) >> 31); |
382 |
> |
#elif USE_QUAD_DOUBLE |
383 |
> |
fp_declare_init_shape(sxp, r, extended); |
384 |
|
uae_s64 hx = sxp->parts64.msw; |
385 |
|
uae_s64 lx = sxp->parts64.lsw; |
386 |
|
hx &= 0x7fffffffffffffffLL; |
388 |
|
hx = 0x7fff000000000000LL - hx; |
389 |
|
return (int)((uae_u64)hx >> 63); |
390 |
|
#else |
391 |
+ |
fp_declare_init_shape(sxp, r, extended); |
392 |
|
uae_s32 se = sxp->parts.sign_exponent; |
393 |
|
uae_s32 hx = sxp->parts.msw; |
394 |
|
uae_s32 lx = sxp->parts.lsw; |
400 |
|
return (int)(((uae_u32)(se)) >> 16); |
401 |
|
#endif |
402 |
|
#else |
403 |
+ |
#ifndef USE_LONG_DOUBLE |
404 |
+ |
fp_declare_init_shape(sxp, r, double); |
405 |
+ |
return (sxp->ieee_nan.exponent == FP_DOUBLE_EXP_MAX) |
406 |
+ |
#else |
407 |
+ |
fp_declare_init_shape(sxp, r, extended); |
408 |
|
return (sxp->ieee_nan.exponent == FP_EXTENDED_EXP_MAX) |
409 |
+ |
#endif |
410 |
|
&& (sxp->ieee_nan.mantissa0 != 0) |
411 |
|
&& (sxp->ieee_nan.mantissa1 != 0) |
412 |
|
#ifdef USE_QUAD_DOUBLE |
426 |
|
|
427 |
|
PRIVATE inline bool FFPU fp_do_isinf(fpu_register const & r) |
428 |
|
{ |
409 |
– |
fp_declare_init_shape(sxp, r, extended); |
429 |
|
#ifdef BRANCHES_ARE_EXPENSIVE |
430 |
< |
#ifdef USE_QUAD_DOUBLE |
430 |
> |
#ifndef USE_LONG_DOUBLE |
431 |
> |
fp_declare_init_shape(sxp, r, double); |
432 |
> |
uae_s32 hx = sxp->parts.msw; |
433 |
> |
uae_s32 lx = sxp->parts.lsw; |
434 |
> |
lx |= (hx & 0x7fffffff) ^ 0x7ff00000; |
435 |
> |
lx |= -lx; |
436 |
> |
return ~(lx >> 31) & (hx >> 30); |
437 |
> |
#elif USE_QUAD_DOUBLE |
438 |
> |
fp_declare_init_shape(sxp, r, extended); |
439 |
|
uae_s64 hx = sxp->parts64.msw; |
440 |
|
uae_s64 lx = sxp->parts64.lsw; |
441 |
|
lx |= (hx & 0x7fffffffffffffffLL) ^ 0x7fff000000000000LL; |
442 |
|
lx |= -lx; |
443 |
|
return ~(lx >> 63) & (hx >> 62); |
444 |
|
#else |
445 |
+ |
fp_declare_init_shape(sxp, r, extended); |
446 |
|
uae_s32 se = sxp->parts.sign_exponent; |
447 |
|
uae_s32 hx = sxp->parts.msw; |
448 |
|
uae_s32 lx = sxp->parts.lsw; |
459 |
|
return ~(lx >> 31) & (1 - (se >> 14)); |
460 |
|
#endif |
461 |
|
#else |
462 |
+ |
#ifndef USE_LONG_DOUBLE |
463 |
+ |
fp_declare_init_shape(sxp, r, double); |
464 |
+ |
return (sxp->ieee_nan.exponent == FP_DOUBLE_EXP_MAX) |
465 |
+ |
#else |
466 |
+ |
fp_declare_init_shape(sxp, r, extended); |
467 |
|
return (sxp->ieee_nan.exponent == FP_EXTENDED_EXP_MAX) |
468 |
+ |
#endif |
469 |
|
&& (sxp->ieee_nan.mantissa0 == 0) |
470 |
|
&& (sxp->ieee_nan.mantissa1 == 0) |
471 |
|
#ifdef USE_QUAD_DOUBLE |
481 |
|
|
482 |
|
PRIVATE inline bool FFPU fp_do_isneg(fpu_register const & r) |
483 |
|
{ |
484 |
+ |
#ifndef USE_LONG_DOUBLE |
485 |
+ |
fp_declare_init_shape(sxp, r, double); |
486 |
+ |
#else |
487 |
|
fp_declare_init_shape(sxp, r, extended); |
488 |
< |
return (sxp->ieee.negative) |
489 |
< |
; |
488 |
> |
#endif |
489 |
> |
return sxp->ieee.negative; |
490 |
|
} |
491 |
|
|
492 |
|
#undef iszero |
495 |
|
PRIVATE inline bool FFPU fp_do_iszero(fpu_register const & r) |
496 |
|
{ |
497 |
|
// TODO: BRANCHES_ARE_EXPENSIVE |
498 |
+ |
#ifndef USE_LONG_DOUBLE |
499 |
+ |
fp_declare_init_shape(sxp, r, double); |
500 |
+ |
#else |
501 |
|
fp_declare_init_shape(sxp, r, extended); |
502 |
+ |
#endif |
503 |
|
return (sxp->ieee.exponent == 0) |
504 |
|
&& (sxp->ieee.mantissa0 == 0) |
505 |
|
&& (sxp->ieee.mantissa1 == 0) |
531 |
|
PRIVATE inline void FFPU make_nan(fpu_register & r) |
532 |
|
{ |
533 |
|
// FIXME: is that correct ? |
534 |
+ |
#ifndef USE_LONG_DOUBLE |
535 |
+ |
fp_declare_init_shape(sxp, r, double); |
536 |
+ |
sxp->ieee.exponent = FP_DOUBLE_EXP_MAX; |
537 |
+ |
sxp->ieee.mantissa0 = 0xfffff; |
538 |
+ |
#else |
539 |
|
fp_declare_init_shape(sxp, r, extended); |
540 |
|
sxp->ieee.exponent = FP_EXTENDED_EXP_MAX; |
541 |
|
sxp->ieee.mantissa0 = 0xffffffff; |
542 |
+ |
#endif |
543 |
|
sxp->ieee.mantissa1 = 0xffffffff; |
544 |
|
#ifdef USE_QUAD_DOUBLE |
545 |
|
sxp->ieee.mantissa2 = 0xffffffff; |
552 |
|
#if 1 |
553 |
|
r = +0.0; |
554 |
|
#else |
555 |
+ |
#ifndef USE_LONG_DOUBLE |
556 |
+ |
fp_declare_init_shape(sxp, r, double); |
557 |
+ |
#else |
558 |
|
fp_declare_init_shape(sxp, r, extended); |
559 |
+ |
#endif |
560 |
|
sxp->ieee.negative = 0; |
561 |
|
sxp->ieee.exponent = 0; |
562 |
|
sxp->ieee.mantissa0 = 0; |
573 |
|
#if 1 |
574 |
|
r = -0.0; |
575 |
|
#else |
576 |
+ |
#ifndef USE_LONG_DOUBLE |
577 |
+ |
fp_declare_init_shape(sxp, r, double); |
578 |
+ |
#else |
579 |
|
fp_declare_init_shape(sxp, r, extended); |
580 |
+ |
#endif |
581 |
|
sxp->ieee.negative = 1; |
582 |
|
sxp->ieee.exponent = 0; |
583 |
|
sxp->ieee.mantissa0 = 0; |
591 |
|
|
592 |
|
PRIVATE inline void FFPU make_inf_positive(fpu_register & r) |
593 |
|
{ |
594 |
+ |
#ifndef USE_LONG_DOUBLE |
595 |
+ |
fp_declare_init_shape(sxp, r, double); |
596 |
+ |
sxp->ieee_nan.exponent = FP_DOUBLE_EXP_MAX; |
597 |
+ |
#else |
598 |
|
fp_declare_init_shape(sxp, r, extended); |
540 |
– |
sxp->ieee_nan.negative = 0; |
599 |
|
sxp->ieee_nan.exponent = FP_EXTENDED_EXP_MAX; |
600 |
+ |
#endif |
601 |
+ |
sxp->ieee_nan.negative = 0; |
602 |
|
sxp->ieee_nan.mantissa0 = 0; |
603 |
|
sxp->ieee_nan.mantissa1 = 0; |
604 |
|
#ifdef USE_QUAD_DOUBLE |
609 |
|
|
610 |
|
PRIVATE inline void FFPU make_inf_negative(fpu_register & r) |
611 |
|
{ |
612 |
+ |
#ifndef USE_LONG_DOUBLE |
613 |
+ |
fp_declare_init_shape(sxp, r, double); |
614 |
+ |
sxp->ieee_nan.exponent = FP_DOUBLE_EXP_MAX; |
615 |
+ |
#else |
616 |
|
fp_declare_init_shape(sxp, r, extended); |
553 |
– |
sxp->ieee_nan.negative = 1; |
617 |
|
sxp->ieee_nan.exponent = FP_EXTENDED_EXP_MAX; |
618 |
+ |
#endif |
619 |
+ |
sxp->ieee_nan.negative = 1; |
620 |
|
sxp->ieee_nan.mantissa0 = 0; |
621 |
|
sxp->ieee_nan.mantissa1 = 0; |
622 |
|
#ifdef USE_QUAD_DOUBLE |
625 |
|
#endif |
626 |
|
} |
627 |
|
|
563 |
– |
PRIVATE inline void FFPU fast_scale(fpu_register & r, int add) |
564 |
– |
{ |
565 |
– |
fp_declare_init_shape(sxp, r, extended); |
566 |
– |
// TODO: overflow flags |
567 |
– |
int exp = sxp->ieee.exponent + add; |
568 |
– |
// FIXME: this test is not correct: see fpuop_fscale() |
569 |
– |
if (exp > FP_EXTENDED_EXP_BIAS) { |
570 |
– |
make_inf_positive(r); |
571 |
– |
} else if (exp < 0) { |
572 |
– |
// keep sign (+/- 0) |
573 |
– |
if (isneg(r)) |
574 |
– |
make_inf_negative(r); |
575 |
– |
else |
576 |
– |
make_inf_positive(r); |
577 |
– |
// p[FHI] &= 0x80000000; |
578 |
– |
} else { |
579 |
– |
sxp->ieee.exponent = exp; |
580 |
– |
// p[FHI] = (p[FHI] & 0x800FFFFF) | ((uae_u32)exp << 20); |
581 |
– |
} |
582 |
– |
} |
583 |
– |
|
628 |
|
PRIVATE inline fpu_register FFPU fast_fgetexp(fpu_register const & r) |
629 |
|
{ |
630 |
+ |
#ifndef USE_LONG_DOUBLE |
631 |
+ |
fp_declare_init_shape(sxp, r, double); |
632 |
+ |
return (sxp->ieee.exponent - FP_DOUBLE_EXP_BIAS); |
633 |
+ |
#else |
634 |
|
fp_declare_init_shape(sxp, r, extended); |
635 |
|
return (sxp->ieee.exponent - FP_EXTENDED_EXP_BIAS); |
636 |
+ |
#endif |
637 |
|
} |
638 |
|
|
639 |
|
// Normalize to range 1..2 |
640 |
|
PRIVATE inline void FFPU fast_remove_exponent(fpu_register & r) |
641 |
|
{ |
642 |
+ |
#ifndef USE_LONG_DOUBLE |
643 |
+ |
fp_declare_init_shape(sxp, r, double); |
644 |
+ |
sxp->ieee.exponent = FP_DOUBLE_EXP_BIAS; |
645 |
+ |
#else |
646 |
|
fp_declare_init_shape(sxp, r, extended); |
647 |
|
sxp->ieee.exponent = FP_EXTENDED_EXP_BIAS; |
648 |
+ |
#endif |
649 |
|
} |
650 |
|
|
651 |
|
// The sign of the quotient is the exclusive-OR of the sign bits |
652 |
|
// of the source and destination operands. |
653 |
|
PRIVATE inline uae_u32 FFPU get_quotient_sign(fpu_register const & ra, fpu_register const & rb) |
654 |
|
{ |
655 |
+ |
#ifndef USE_LONG_DOUBLE |
656 |
+ |
fp_declare_init_shape(sap, ra, double); |
657 |
+ |
fp_declare_init_shape(sbp, rb, double); |
658 |
+ |
#else |
659 |
|
fp_declare_init_shape(sap, ra, extended); |
660 |
|
fp_declare_init_shape(sbp, rb, extended); |
661 |
< |
return (((sap->ieee.mantissa0 ^ sbp->ieee.mantissa0) & 0x80000000) ? 0x800000 : 0); |
661 |
> |
#endif |
662 |
> |
return ((sap->ieee.negative ^ sbp->ieee.negative) ? FPSR_QUOTIENT_SIGN : 0); |
663 |
|
} |
664 |
|
|
665 |
|
/* -------------------------------------------------------------------------- */ |
666 |
|
/* --- Math functions --- */ |
667 |
|
/* -------------------------------------------------------------------------- */ |
668 |
|
|
669 |
< |
#if FPU_USE_ISO_C99 |
669 |
> |
#if FPU_USE_ISO_C99 && USE_LONG_DOUBLE |
670 |
|
# define fp_log logl |
671 |
|
# define fp_log10 log10l |
672 |
|
# define fp_exp expl |