1 /* Include file for internal GNU MP types and definitions.
3 Copyright (C) 1991, 1993, 1994, 1995, 1996, 2011 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
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.
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.
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. */
23 #include "quadmath-imp.h"
26 #define alloca __builtin_alloca
28 #define ABS(x) (x >= 0 ? x : -x)
30 #define MIN(l,o) ((l) < (o) ? (l) : (o))
33 #define MAX(h,i) ((h) > (i) ? (h) : (i))
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
;
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
;
47 #define BYTES_PER_MP_LIMB (BITS_PER_MP_LIMB / __CHAR_BIT__)
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
;
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
)));
61 typedef mp_limb_t UWtype
;
62 typedef unsigned int UHWtype
;
63 #define W_TYPE_SIZE BITS_PER_MP_LIMB
65 #ifdef HAVE_HIDDEN_VISIBILITY
66 #define attribute_hidden __attribute__((__visibility__ ("hidden")))
68 #define attribute_hidden
73 /* Copy NLIMBS *limbs* from SRC to DST. */
74 #define MPN_COPY_INCR(DST, SRC, NLIMBS) \
77 for (__i = 0; __i < (NLIMBS); __i++) \
78 (DST)[__i] = (SRC)[__i]; \
80 #define MPN_COPY_DECR(DST, SRC, NLIMBS) \
83 for (__i = (NLIMBS) - 1; __i >= 0; __i--) \
84 (DST)[__i] = (SRC)[__i]; \
86 #define MPN_COPY MPN_COPY_INCR
88 /* Zero NLIMBS *limbs* AT DST. */
89 #define MPN_ZERO(DST, NLIMBS) \
92 for (__i = 0; __i < (NLIMBS); __i++) \
96 #define MPN_MUL_N_RECURSE(prodp, up, vp, size, tspace) \
98 if ((size) < KARATSUBA_THRESHOLD) \
99 impn_mul_n_basecase (prodp, up, vp, size); \
101 impn_mul_n (prodp, up, vp, size, tspace); \
104 #define __MPN(x) __quadmath_mpn_##x
106 /* Internal mpn calls */
107 #define impn_mul_n_basecase __MPN(impn_mul_n_basecase)
108 #define impn_mul_n __MPN(impn_mul_n)
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
;
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)
127 mp_limb_t
mpn_add_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
)
129 mp_limb_t
mpn_addmul_1 (mp_ptr
, mp_srcptr
, mp_size_t
, mp_limb_t
)
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)
136 mp_limb_t
mpn_mul (mp_ptr
, mp_srcptr
, mp_size_t
, mp_srcptr
, mp_size_t
)
138 mp_limb_t
mpn_mul_1 (mp_ptr
, mp_srcptr
, mp_size_t
, mp_limb_t
)
140 mp_limb_t
mpn_rshift (mp_ptr
, mp_srcptr
, mp_size_t
, unsigned int)
142 mp_limb_t
mpn_sub_n (mp_ptr
, mp_srcptr
, mp_srcptr
, mp_size_t
)
144 mp_limb_t
mpn_submul_1 (mp_ptr
, mp_srcptr
, mp_size_t
, mp_limb_t
)
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
;
151 #define mpn_construct_float128 __MPN(construct_float128)
152 __float128
mpn_construct_float128 (mp_srcptr frac_ptr
, int expt
, int sign
)
155 #define mpn_divmod(qp,np,nsize,dp,dsize) mpn_divrem (qp,0,np,nsize,dp,dsize)
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
)
163 register mp_limb_t x
;
166 s2_limb
= x
+ s2_limb
;
167 *res_ptr
++ = s2_limb
;
170 while (--s1_size
!= 0)
182 if (res_ptr
!= s1_ptr
)
185 for (i
= 0; i
< s1_size
- 1; i
++)
186 res_ptr
[i
] = s1_ptr
[i
];