| @@ -1608,35 +1608,39 @@ NAME (TYPE x, int m) | | | @@ -1608,35 +1608,39 @@ NAME (TYPE x, int m) |
1608 | #define CONCAT2(A,B) _CONCAT2(A,B) | | 1608 | #define CONCAT2(A,B) _CONCAT2(A,B) |
1609 | #define _CONCAT2(A,B) A##B | | 1609 | #define _CONCAT2(A,B) A##B |
1610 | | | 1610 | |
1611 | /* All of these would be present in a full C99 implementation of <math.h> | | 1611 | /* All of these would be present in a full C99 implementation of <math.h> |
1612 | and <complex.h>. Our problem is that only a few systems have such full | | 1612 | and <complex.h>. Our problem is that only a few systems have such full |
1613 | implementations. Further, libgcc_s.so isn't currently linked against | | 1613 | implementations. Further, libgcc_s.so isn't currently linked against |
1614 | libm.so, and even for systems that do provide full C99, the extra overhead | | 1614 | libm.so, and even for systems that do provide full C99, the extra overhead |
1615 | of all programs using libgcc having to link against libm. So avoid it. */ | | 1615 | of all programs using libgcc having to link against libm. So avoid it. */ |
1616 | | | 1616 | |
1617 | #define isnan(x) __builtin_expect ((x) != (x), 0) | | 1617 | #define isnan(x) __builtin_expect ((x) != (x), 0) |
1618 | #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1) | | 1618 | #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1) |
1619 | #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0) | | 1619 | #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0) |
1620 | | | 1620 | |
| | | 1621 | #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT |
1621 | #define INFINITY CONCAT2(__builtin_inf, CEXT) () | | 1622 | #define INFINITY CONCAT2(__builtin_inf, CEXT) () |
| | | 1623 | #endif |
1622 | #define I 1i | | 1624 | #define I 1i |
1623 | | | 1625 | |
1624 | /* Helpers to make the following code slightly less gross. */ | | 1626 | /* Helpers to make the following code slightly less gross. */ |
1625 | #define COPYSIGN CONCAT2(__builtin_copysign, CEXT) | | 1627 | #define COPYSIGN CONCAT2(__builtin_copysign, CEXT) |
1626 | #define FABS CONCAT2(__builtin_fabs, CEXT) | | 1628 | #define FABS CONCAT2(__builtin_fabs, CEXT) |
1627 | | | 1629 | |
1628 | /* Verify that MTYPE matches up with CEXT. */ | | 1630 | /* Verify that MTYPE matches up with CEXT. */ |
| | | 1631 | #ifdef INFINITY |
1629 | extern void *compile_type_assert[sizeof(INFINITY) == sizeof(MTYPE) ? 1 : -1]; | | 1632 | extern void *compile_type_assert[sizeof(INFINITY) == sizeof(MTYPE) ? 1 : -1]; |
| | | 1633 | #endif |
1630 | | | 1634 | |
1631 | /* Ensure that we've lost any extra precision. */ | | 1635 | /* Ensure that we've lost any extra precision. */ |
1632 | #if NOTRUNC | | 1636 | #if NOTRUNC |
1633 | # define TRUNC(x) | | 1637 | # define TRUNC(x) |
1634 | #else | | 1638 | #else |
1635 | # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x)) | | 1639 | # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x)) |
1636 | #endif | | 1640 | #endif |
1637 | | | 1641 | |
1638 | #if defined(L_mulsc3) || defined(L_muldc3) \ | | 1642 | #if defined(L_mulsc3) || defined(L_muldc3) \ |
1639 | || defined(L_mulxc3) || defined(L_multc3) | | 1643 | || defined(L_mulxc3) || defined(L_multc3) |
1640 | | | 1644 | |
1641 | CTYPE | | 1645 | CTYPE |
1642 | CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d) | | 1646 | CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d) |
| @@ -1646,26 +1650,27 @@ CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, | | | @@ -1646,26 +1650,27 @@ CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, |
1646 | ac = a * c; | | 1650 | ac = a * c; |
1647 | bd = b * d; | | 1651 | bd = b * d; |
1648 | ad = a * d; | | 1652 | ad = a * d; |
1649 | bc = b * c; | | 1653 | bc = b * c; |
1650 | | | 1654 | |
1651 | TRUNC (ac); | | 1655 | TRUNC (ac); |
1652 | TRUNC (bd); | | 1656 | TRUNC (bd); |
1653 | TRUNC (ad); | | 1657 | TRUNC (ad); |
1654 | TRUNC (bc); | | 1658 | TRUNC (bc); |
1655 | | | 1659 | |
1656 | x = ac - bd; | | 1660 | x = ac - bd; |
1657 | y = ad + bc; | | 1661 | y = ad + bc; |
1658 | | | 1662 | |
| | | 1663 | #ifdef INFINITY |
1659 | if (isnan (x) && isnan (y)) | | 1664 | if (isnan (x) && isnan (y)) |
1660 | { | | 1665 | { |
1661 | /* Recover infinities that computed as NaN + iNaN. */ | | 1666 | /* Recover infinities that computed as NaN + iNaN. */ |
1662 | _Bool recalc = 0; | | 1667 | _Bool recalc = 0; |
1663 | if (isinf (a) || isinf (b)) | | 1668 | if (isinf (a) || isinf (b)) |
1664 | { | | 1669 | { |
1665 | /* z is infinite. "Box" the infinity and change NaNs in | | 1670 | /* z is infinite. "Box" the infinity and change NaNs in |
1666 | the other factor to 0. */ | | 1671 | the other factor to 0. */ |
1667 | a = COPYSIGN (isinf (a) ? 1 : 0, a); | | 1672 | a = COPYSIGN (isinf (a) ? 1 : 0, a); |
1668 | b = COPYSIGN (isinf (b) ? 1 : 0, b); | | 1673 | b = COPYSIGN (isinf (b) ? 1 : 0, b); |
1669 | if (isnan (c)) c = COPYSIGN (0, c); | | 1674 | if (isnan (c)) c = COPYSIGN (0, c); |
1670 | if (isnan (d)) d = COPYSIGN (0, d); | | 1675 | if (isnan (d)) d = COPYSIGN (0, d); |
1671 | recalc = 1; | | 1676 | recalc = 1; |
| @@ -1687,26 +1692,27 @@ CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, | | | @@ -1687,26 +1692,27 @@ CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, |
1687 | /* Recover infinities from overflow by changing NaNs to 0. */ | | 1692 | /* Recover infinities from overflow by changing NaNs to 0. */ |
1688 | if (isnan (a)) a = COPYSIGN (0, a); | | 1693 | if (isnan (a)) a = COPYSIGN (0, a); |
1689 | if (isnan (b)) b = COPYSIGN (0, b); | | 1694 | if (isnan (b)) b = COPYSIGN (0, b); |
1690 | if (isnan (c)) c = COPYSIGN (0, c); | | 1695 | if (isnan (c)) c = COPYSIGN (0, c); |
1691 | if (isnan (d)) d = COPYSIGN (0, d); | | 1696 | if (isnan (d)) d = COPYSIGN (0, d); |
1692 | recalc = 1; | | 1697 | recalc = 1; |
1693 | } | | 1698 | } |
1694 | if (recalc) | | 1699 | if (recalc) |
1695 | { | | 1700 | { |
1696 | x = INFINITY * (a * c - b * d); | | 1701 | x = INFINITY * (a * c - b * d); |
1697 | y = INFINITY * (a * d + b * c); | | 1702 | y = INFINITY * (a * d + b * c); |
1698 | } | | 1703 | } |
1699 | } | | 1704 | } |
| | | 1705 | #endif |
1700 | | | 1706 | |
1701 | return x + I * y; | | 1707 | return x + I * y; |
1702 | } | | 1708 | } |
1703 | #endif /* complex multiply */ | | 1709 | #endif /* complex multiply */ |
1704 | | | 1710 | |
1705 | #if defined(L_divsc3) || defined(L_divdc3) \ | | 1711 | #if defined(L_divsc3) || defined(L_divdc3) \ |
1706 | || defined(L_divxc3) || defined(L_divtc3) | | 1712 | || defined(L_divxc3) || defined(L_divtc3) |
1707 | | | 1713 | |
1708 | CTYPE | | 1714 | CTYPE |
1709 | CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d) | | 1715 | CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d) |
1710 | { | | 1716 | { |
1711 | MTYPE denom, ratio, x, y; | | 1717 | MTYPE denom, ratio, x, y; |
1712 | | | 1718 | |
| @@ -1721,53 +1727,55 @@ CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b, | | | @@ -1721,53 +1727,55 @@ CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b, |
1721 | x = ((a * ratio) + b) / denom; | | 1727 | x = ((a * ratio) + b) / denom; |
1722 | y = ((b * ratio) - a) / denom; | | 1728 | y = ((b * ratio) - a) / denom; |
1723 | } | | 1729 | } |
1724 | else | | 1730 | else |
1725 | { | | 1731 | { |
1726 | ratio = d / c; | | 1732 | ratio = d / c; |
1727 | denom = (d * ratio) + c; | | 1733 | denom = (d * ratio) + c; |
1728 | x = ((b * ratio) + a) / denom; | | 1734 | x = ((b * ratio) + a) / denom; |
1729 | y = (b - (a * ratio)) / denom; | | 1735 | y = (b - (a * ratio)) / denom; |
1730 | } | | 1736 | } |
1731 | | | 1737 | |
1732 | /* Recover infinities and zeros that computed as NaN+iNaN; the only cases | | 1738 | /* Recover infinities and zeros that computed as NaN+iNaN; the only cases |
1733 | are nonzero/zero, infinite/finite, and finite/infinite. */ | | 1739 | are nonzero/zero, infinite/finite, and finite/infinite. */ |
| | | 1740 | #ifdef INFINITY |
1734 | if (isnan (x) && isnan (y)) | | 1741 | if (isnan (x) && isnan (y)) |
1735 | { | | 1742 | { |
1736 | if (c == 0.0 && d == 0.0 && (!isnan (a) || !isnan (b))) | | 1743 | if (c == 0.0 && d == 0.0 && (!isnan (a) || !isnan (b))) |
1737 | { | | 1744 | { |
1738 | x = COPYSIGN (INFINITY, c) * a; | | 1745 | x = COPYSIGN (INFINITY, c) * a; |
1739 | y = COPYSIGN (INFINITY, c) * b; | | 1746 | y = COPYSIGN (INFINITY, c) * b; |
1740 | } | | 1747 | } |
1741 | else if ((isinf (a) || isinf (b)) && isfinite (c) && isfinite (d)) | | 1748 | else if ((isinf (a) || isinf (b)) && isfinite (c) && isfinite (d)) |
1742 | { | | 1749 | { |
1743 | a = COPYSIGN (isinf (a) ? 1 : 0, a); | | 1750 | a = COPYSIGN (isinf (a) ? 1 : 0, a); |
1744 | b = COPYSIGN (isinf (b) ? 1 : 0, b); | | 1751 | b = COPYSIGN (isinf (b) ? 1 : 0, b); |
1745 | x = INFINITY * (a * c + b * d); | | 1752 | x = INFINITY * (a * c + b * d); |
1746 | y = INFINITY * (b * c - a * d); | | 1753 | y = INFINITY * (b * c - a * d); |
1747 | } | | 1754 | } |
1748 | else if ((isinf (c) || isinf (d)) && isfinite (a) && isfinite (b)) | | 1755 | else if ((isinf (c) || isinf (d)) && isfinite (a) && isfinite (b)) |
1749 | { | | 1756 | { |
1750 | c = COPYSIGN (isinf (c) ? 1 : 0, c); | | 1757 | c = COPYSIGN (isinf (c) ? 1 : 0, c); |
1751 | d = COPYSIGN (isinf (d) ? 1 : 0, d); | | 1758 | d = COPYSIGN (isinf (d) ? 1 : 0, d); |
1752 | x = 0.0 * (a * c + b * d); | | 1759 | x = 0.0 * (a * c + b * d); |
1753 | y = 0.0 * (b * c - a * d); | | 1760 | y = 0.0 * (b * c - a * d); |
1754 | } | | 1761 | } |
1755 | } | | 1762 | } |
| | | 1763 | #endif |
1756 | | | 1764 | |
1757 | return x + I * y; | | 1765 | return x + I * y; |
1758 | } | | 1766 | } |
1759 | #endif /* complex divide */ | | 1767 | #endif /* complex divide */ |
1760 | | | 1768 | #undef INFINITY |
1761 | #endif /* all complex float routines */ | | 1769 | #endif /* all complex float routines */ |
1762 | | | 1770 | |
1763 | /* From here on down, the routines use normal data types. */ | | 1771 | /* From here on down, the routines use normal data types. */ |
1764 | | | 1772 | |
1765 | #define SItype bogus_type | | 1773 | #define SItype bogus_type |
1766 | #define USItype bogus_type | | 1774 | #define USItype bogus_type |
1767 | #define DItype bogus_type | | 1775 | #define DItype bogus_type |
1768 | #define UDItype bogus_type | | 1776 | #define UDItype bogus_type |
1769 | #define SFtype bogus_type | | 1777 | #define SFtype bogus_type |
1770 | #define DFtype bogus_type | | 1778 | #define DFtype bogus_type |
1771 | #undef Wtype | | 1779 | #undef Wtype |
1772 | #undef UWtype | | 1780 | #undef UWtype |
1773 | #undef HWtype | | 1781 | #undef HWtype |