(root)/
gcc-13.2.0/
libquadmath/
printf/
gmp-impl.h
       1  /* Include file for internal GNU MP types and definitions.
       2  
       3  Copyright (C) 1991, 1993, 1994, 1995, 1996, 2011 Free Software Foundation, Inc.
       4  
       5  This file is part of the GNU MP Library.
       6  
       7  The GNU MP Library is free software; you can redistribute it and/or modify
       8  it under the terms of the GNU Lesser General Public License as published by
       9  the Free Software Foundation; either version 2.1 of the License, or (at your
      10  option) any later version.
      11  
      12  The GNU MP Library is distributed in the hope that it will be useful, but
      13  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
      14  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
      15  License for more details.
      16  
      17  You should have received a copy of the GNU Lesser General Public License
      18  along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
      19  the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
      20  MA 02111-1307, USA. */
      21  
      22  #include <stdlib.h>
      23  #include "quadmath-imp.h"
      24  
      25  #undef alloca
      26  #define alloca __builtin_alloca
      27  
      28  #define ABS(x) (x >= 0 ? x : -x)
      29  #ifndef MIN
      30  #define MIN(l,o) ((l) < (o) ? (l) : (o))
      31  #endif
      32  #ifndef MAX
      33  #define MAX(h,i) ((h) > (i) ? (h) : (i))
      34  #endif
      35  
      36  #if __SIZEOF_LONG__ == 4 && __SIZEOF_LONG_LONG__ == 8 \
      37      && __SIZEOF_POINTER__ == 8
      38  /* Use 64-bit limbs on LLP64 targets.  */
      39  #define BITS_PER_MP_LIMB (__SIZEOF_LONG_LONG__ * __CHAR_BIT__)
      40  typedef unsigned long long int	mp_limb_t;
      41  typedef long long int		mp_limb_signed_t;
      42  #else
      43  #define BITS_PER_MP_LIMB (__SIZEOF_LONG__ * __CHAR_BIT__)
      44  typedef unsigned long int	mp_limb_t;
      45  typedef long int		mp_limb_signed_t;
      46  #endif
      47  #define BYTES_PER_MP_LIMB (BITS_PER_MP_LIMB / __CHAR_BIT__)
      48  
      49  typedef mp_limb_t *             mp_ptr;
      50  typedef const mp_limb_t *	mp_srcptr;
      51  typedef long int                mp_size_t;
      52  typedef long int                mp_exp_t;
      53  
      54  /* Define stuff for longlong.h.  */
      55  typedef unsigned int UQItype	__attribute__ ((mode (QI)));
      56  typedef 	 int SItype	__attribute__ ((mode (SI)));
      57  typedef unsigned int USItype	__attribute__ ((mode (SI)));
      58  typedef		 int DItype	__attribute__ ((mode (DI)));
      59  typedef unsigned int UDItype	__attribute__ ((mode (DI)));
      60  
      61  typedef mp_limb_t UWtype;
      62  typedef unsigned int UHWtype;
      63  #define W_TYPE_SIZE BITS_PER_MP_LIMB
      64  
      65  #ifdef HAVE_HIDDEN_VISIBILITY
      66  #define attribute_hidden __attribute__((__visibility__ ("hidden")))
      67  #else
      68  #define attribute_hidden
      69  #endif
      70  
      71  #include "longlong.h"
      72  
      73  /* Copy NLIMBS *limbs* from SRC to DST.  */
      74  #define MPN_COPY_INCR(DST, SRC, NLIMBS) \
      75    do {									\
      76      mp_size_t __i;							\
      77      for (__i = 0; __i < (NLIMBS); __i++)				\
      78        (DST)[__i] = (SRC)[__i];						\
      79    } while (0)
      80  #define MPN_COPY_DECR(DST, SRC, NLIMBS) \
      81    do {									\
      82      mp_size_t __i;							\
      83      for (__i = (NLIMBS) - 1; __i >= 0; __i--)				\
      84        (DST)[__i] = (SRC)[__i];						\
      85    } while (0)
      86  #define MPN_COPY MPN_COPY_INCR
      87  
      88  /* Zero NLIMBS *limbs* AT DST.  */
      89  #define MPN_ZERO(DST, NLIMBS) \
      90    do {									\
      91      mp_size_t __i;							\
      92      for (__i = 0; __i < (NLIMBS); __i++)				\
      93        (DST)[__i] = 0;							\
      94    } while (0)
      95  
      96  #define MPN_MUL_N_RECURSE(prodp, up, vp, size, tspace) \
      97    do {									\
      98      if ((size) < KARATSUBA_THRESHOLD)					\
      99        impn_mul_n_basecase (prodp, up, vp, size);			\
     100      else								\
     101        impn_mul_n (prodp, up, vp, size, tspace);			\
     102    } while (0)
     103  
     104  #define __MPN(x) __quadmath_mpn_##x
     105  
     106  /* Internal mpn calls */
     107  #define impn_mul_n_basecase	__MPN(impn_mul_n_basecase)
     108  #define impn_mul_n		__MPN(impn_mul_n)
     109  
     110  /* Prototypes for internal mpn calls.  */
     111  void impn_mul_n_basecase (mp_ptr prodp, mp_srcptr up, mp_srcptr vp,
     112  			  mp_size_t size) attribute_hidden;
     113  void impn_mul_n (mp_ptr prodp, mp_srcptr up, mp_srcptr vp, mp_size_t size,
     114  		 mp_ptr tspace) attribute_hidden;
     115  
     116  #define mpn_add_n		__MPN(add_n)
     117  #define mpn_addmul_1		__MPN(addmul_1)
     118  #define mpn_cmp			__MPN(cmp)
     119  #define mpn_divrem		__MPN(divrem)
     120  #define mpn_lshift		__MPN(lshift)
     121  #define mpn_mul			__MPN(mul)
     122  #define mpn_mul_1		__MPN(mul_1)
     123  #define mpn_rshift		__MPN(rshift)
     124  #define mpn_sub_n		__MPN(sub_n)
     125  #define mpn_submul_1		__MPN(submul_1)
     126  
     127  mp_limb_t mpn_add_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)
     128       attribute_hidden;
     129  mp_limb_t mpn_addmul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)
     130       attribute_hidden;
     131  int mpn_cmp (mp_srcptr, mp_srcptr, mp_size_t) attribute_hidden;
     132  mp_limb_t mpn_divrem (mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr,
     133  		      mp_size_t) attribute_hidden;
     134  mp_limb_t mpn_lshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int)
     135       attribute_hidden;
     136  mp_limb_t mpn_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)
     137       attribute_hidden;
     138  mp_limb_t mpn_mul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)
     139       attribute_hidden;
     140  mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, unsigned int)
     141       attribute_hidden;
     142  mp_limb_t mpn_sub_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)
     143       attribute_hidden;
     144  mp_limb_t mpn_submul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)
     145       attribute_hidden;
     146  
     147  #define mpn_extract_flt128 __MPN(extract_flt128)
     148  mp_size_t mpn_extract_flt128 (mp_ptr res_ptr, mp_size_t size, int *expt,
     149  			      int *is_neg, __float128 value) attribute_hidden;
     150  
     151  #define mpn_construct_float128 __MPN(construct_float128)
     152  __float128 mpn_construct_float128 (mp_srcptr frac_ptr, int expt, int sign)
     153       attribute_hidden;
     154  
     155  #define mpn_divmod(qp,np,nsize,dp,dsize) mpn_divrem (qp,0,np,nsize,dp,dsize)
     156  
     157  static inline mp_limb_t
     158  mpn_add_1 (register mp_ptr res_ptr,
     159  	   register mp_srcptr s1_ptr,
     160  	   register mp_size_t s1_size,
     161  	   register mp_limb_t s2_limb)
     162  {
     163    register mp_limb_t x;
     164  
     165    x = *s1_ptr++;
     166    s2_limb = x + s2_limb;
     167    *res_ptr++ = s2_limb;
     168    if (s2_limb < x)
     169      {
     170        while (--s1_size != 0)
     171  	{
     172  	  x = *s1_ptr++ + 1;
     173  	  *res_ptr++ = x;
     174  	  if (x != 0)
     175  	    goto fin;
     176  	}
     177  
     178        return 1;
     179      }
     180  
     181   fin:
     182    if (res_ptr != s1_ptr)
     183      {
     184        mp_size_t i;
     185        for (i = 0; i < s1_size - 1; i++)
     186  	res_ptr[i] = s1_ptr[i];
     187      }
     188    return 0;
     189  }