-
+ 0418E5BDE9C91CCF99BC408F3088AA1EF37C3F8318EBC3BABC9D9AB283A2ED3B158F0057ED885B0C336C69C4F58AC1FF4721D9188072DEC45391C0F2CCA7B250
smg_comms/mpi/include/longlong.h
(0 . 0)(1 . 226)
1622 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
1623 * Modified by No Such Labs. (C) 2015. See README.
1624 *
1625 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
1626 * SHA256(gnupg-1.4.10.tar.gz):
1627 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
1628 * (C) 1994-2005 Free Software Foundation, Inc.
1629 *
1630 * This program is free software: you can redistribute it and/or modify
1631 * it under the terms of the GNU General Public License as published by
1632 * the Free Software Foundation, either version 3 of the License, or
1633 * (at your option) any later version.
1634 *
1635 * This program is distributed in the hope that it will be useful,
1636 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1637 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1638 * GNU General Public License for more details.
1639 *
1640 * You should have received a copy of the GNU General Public License
1641 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1642 */
1643
1644 /* You have to define the following before including this file:
1645
1646 UWtype -- An unsigned type, default type for operations (typically a "word")
1647 UHWtype -- An unsigned type, at least half the size of UWtype.
1648 UDWtype -- An unsigned type, at least twice as large a UWtype
1649 W_TYPE_SIZE -- size in bits of UWtype
1650
1651 SItype, USItype -- Signed and unsigned 32 bit types.
1652 DItype, UDItype -- Signed and unsigned 64 bit types.
1653
1654 On a 32 bit machine UWtype should typically be USItype;
1655 on a 64 bit machine, UWtype should typically be UDItype.
1656 */
1657
1658 #define __BITS4 (W_TYPE_SIZE / 4)
1659 #define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
1660 #define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
1661 #define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
1662
1663 /* This is used to make sure no undesirable sharing between different libraries
1664 that use this file takes place. */
1665 #ifndef __MPN
1666 #define __MPN(x) __##x
1667 #endif
1668
1669 /***************************************
1670 *********** Generic Versions ********
1671 ***************************************/
1672 #if !defined (umul_ppmm) && defined (__umulsidi3)
1673 #define umul_ppmm(ph, pl, m0, m1) \
1674 { \
1675 UDWtype __ll = __umulsidi3 (m0, m1); \
1676 ph = (UWtype) (__ll >> W_TYPE_SIZE); \
1677 pl = (UWtype) __ll; \
1678 }
1679 #endif
1680
1681 #if !defined (__umulsidi3)
1682 #define __umulsidi3(u, v) \
1683 ({UWtype __hi, __lo; \
1684 umul_ppmm (__hi, __lo, u, v); \
1685 ((UDWtype) __hi << W_TYPE_SIZE) | __lo; })
1686 #endif
1687
1688 /* If this machine has no inline assembler, use C macros. */
1689
1690 #if !defined (add_ssaaaa)
1691 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
1692 do { \
1693 UWtype __x; \
1694 __x = (al) + (bl); \
1695 (sh) = (ah) + (bh) + (__x < (al)); \
1696 (sl) = __x; \
1697 } while (0)
1698 #endif
1699
1700 #if !defined (sub_ddmmss)
1701 #define sub_ddmmss(sh, sl, ah, al, bh, bl) \
1702 do { \
1703 UWtype __x; \
1704 __x = (al) - (bl); \
1705 (sh) = (ah) - (bh) - (__x > (al)); \
1706 (sl) = __x; \
1707 } while (0)
1708 #endif
1709
1710 #if !defined (umul_ppmm)
1711 #define umul_ppmm(w1, w0, u, v) \
1712 do { \
1713 UWtype __x0, __x1, __x2, __x3; \
1714 UHWtype __ul, __vl, __uh, __vh; \
1715 UWtype __u = (u), __v = (v); \
1716 \
1717 __ul = __ll_lowpart (__u); \
1718 __uh = __ll_highpart (__u); \
1719 __vl = __ll_lowpart (__v); \
1720 __vh = __ll_highpart (__v); \
1721 \
1722 __x0 = (UWtype) __ul * __vl; \
1723 __x1 = (UWtype) __ul * __vh; \
1724 __x2 = (UWtype) __uh * __vl; \
1725 __x3 = (UWtype) __uh * __vh; \
1726 \
1727 __x1 += __ll_highpart (__x0);/* this can't give carry */ \
1728 __x1 += __x2; /* but this indeed can */ \
1729 if (__x1 < __x2) /* did we get it? */ \
1730 __x3 += __ll_B; /* yes, add it in the proper pos. */ \
1731 \
1732 (w1) = __x3 + __ll_highpart (__x1); \
1733 (w0) = (__ll_lowpart (__x1) << W_TYPE_SIZE/2) + __ll_lowpart (__x0);\
1734 } while (0)
1735 #endif
1736
1737 #if !defined (umul_ppmm)
1738 #define smul_ppmm(w1, w0, u, v) \
1739 do { \
1740 UWtype __w1; \
1741 UWtype __m0 = (u), __m1 = (v); \
1742 umul_ppmm (__w1, w0, __m0, __m1); \
1743 (w1) = __w1 - (-(__m0 >> (W_TYPE_SIZE - 1)) & __m1) \
1744 - (-(__m1 >> (W_TYPE_SIZE - 1)) & __m0); \
1745 } while (0)
1746 #endif
1747
1748 /* Define this unconditionally, so it can be used for debugging. */
1749 #define __udiv_qrnnd_c(q, r, n1, n0, d) \
1750 do { \
1751 UWtype __d1, __d0, __q1, __q0, __r1, __r0, __m; \
1752 __d1 = __ll_highpart (d); \
1753 __d0 = __ll_lowpart (d); \
1754 \
1755 __r1 = (n1) % __d1; \
1756 __q1 = (n1) / __d1; \
1757 __m = (UWtype) __q1 * __d0; \
1758 __r1 = __r1 * __ll_B | __ll_highpart (n0); \
1759 if (__r1 < __m) \
1760 { \
1761 __q1--, __r1 += (d); \
1762 if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
1763 if (__r1 < __m) \
1764 __q1--, __r1 += (d); \
1765 } \
1766 __r1 -= __m; \
1767 \
1768 __r0 = __r1 % __d1; \
1769 __q0 = __r1 / __d1; \
1770 __m = (UWtype) __q0 * __d0; \
1771 __r0 = __r0 * __ll_B | __ll_lowpart (n0); \
1772 if (__r0 < __m) \
1773 { \
1774 __q0--, __r0 += (d); \
1775 if (__r0 >= (d)) \
1776 if (__r0 < __m) \
1777 __q0--, __r0 += (d); \
1778 } \
1779 __r0 -= __m; \
1780 \
1781 (q) = (UWtype) __q1 * __ll_B | __q0; \
1782 (r) = __r0; \
1783 } while (0)
1784
1785 /* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
1786 __udiv_w_sdiv (defined in libgcc or elsewhere). */
1787 #if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
1788 #define udiv_qrnnd(q, r, nh, nl, d) \
1789 do { \
1790 UWtype __r; \
1791 (q) = __MPN(udiv_w_sdiv) (&__r, nh, nl, d); \
1792 (r) = __r; \
1793 } while (0)
1794 #endif
1795
1796 /* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c. */
1797 #if !defined (udiv_qrnnd)
1798 #define UDIV_NEEDS_NORMALIZATION 1
1799 #define udiv_qrnnd __udiv_qrnnd_c
1800 #endif
1801
1802 #if !defined (count_leading_zeros)
1803 extern
1804 #ifdef __STDC__
1805 const
1806 #endif
1807 unsigned char __clz_tab[];
1808 #define MPI_INTERNAL_NEED_CLZ_TAB 1
1809 #define count_leading_zeros(count, x) \
1810 do { \
1811 UWtype __xr = (x); \
1812 UWtype __a; \
1813 \
1814 if (W_TYPE_SIZE <= 32) \
1815 { \
1816 __a = __xr < ((UWtype) 1 << 2*__BITS4) \
1817 ? (__xr < ((UWtype) 1 << __BITS4) ? 0 : __BITS4) \
1818 : (__xr < ((UWtype) 1 << 3*__BITS4) ? 2*__BITS4 : 3*__BITS4);\
1819 } \
1820 else \
1821 { \
1822 for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8) \
1823 if (((__xr >> __a) & 0xff) != 0) \
1824 break; \
1825 } \
1826 \
1827 (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a); \
1828 } while (0)
1829 /* This version gives a well-defined value for zero. */
1830 #define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
1831 #endif
1832
1833 #if !defined (count_trailing_zeros)
1834 /* Define count_trailing_zeros using count_leading_zeros. The latter might be
1835 defined in asm, but if it is not, the C version above is good enough. */
1836 #define count_trailing_zeros(count, x) \
1837 do { \
1838 UWtype __ctz_x = (x); \
1839 UWtype __ctz_c; \
1840 count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x); \
1841 (count) = W_TYPE_SIZE - 1 - __ctz_c; \
1842 } while (0)
1843 #endif
1844
1845 #ifndef UDIV_NEEDS_NORMALIZATION
1846 #define UDIV_NEEDS_NORMALIZATION 0
1847 #endif