1 /* Include file for internal GNU MP types and definitions.
2
3 THE CONTENTS OF THIS FILE ARE FOR INTERNAL USE AND ARE ALMOST CERTAIN TO
4 BE SUBJECT TO INCOMPATIBLE CHANGES IN FUTURE GNU MP RELEASES.
5
6 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000 Free Software
7 Foundation, Inc.
8
9 This file is part of the GNU MP Library.
10
11 The GNU MP Library is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 2.1 of the License, or (at your
14 option) any later version.
15
16 The GNU MP Library is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 License for more details.
20
21 You should have received a copy of the GNU Lesser General Public License
22 along with the GNU MP Library; see the file COPYING.LIB. If not, write to
23 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 MA 02111-1307, USA. */
25
26 /* config.h. Generated automatically by configure. */
27 /* config.in. Generated automatically from configure.in by autoheader. */
28 /*
29 Copyright (C) 2000 Free Software Foundation, Inc.
30
31 This file is part of the GNU MP Library.
32
33 The GNU MP Library is free software; you can redistribute it and/or modify
34 it under the terms of the GNU Lesser General Public License as published by
35 the Free Software Foundation; either version 2.1 of the License, or (at your
36 option) any later version.
37
38 The GNU MP Library is distributed in the hope that it will be useful, but
39 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
40 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
41 License for more details.
42
43 You should have received a copy of the GNU Lesser General Public License
44 along with the GNU MP Library; see the file COPYING.LIB. If not, write to
45 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
46 MA 02111-1307, USA.
47 */
48
49 /* Name of package */
50 #define PACKAGE "gmp"
51
52 /* Define if the system has the type `void'. */
53 #define HAVE_VOID 1
54
55 /* Define if cpp supports the ANSI # stringizing operator. */
56 #define HAVE_STRINGIZE 1
57
58 /* Version number of package */
59 #define VERSION "3.1.1"
60
61 #include "gmp-mparam.h"
62 /* #include "longlong.h" */
63
64 /* When using gcc, make sure to use its builtin alloca. */
65 #if ! defined (alloca) && defined (__GNUC__)
66 #define alloca __builtin_alloca
67 #define HAVE_ALLOCA
68 #endif
69
70 /* When using cc, do whatever necessary to allow use of alloca. For many
71 machines, this means including alloca.h. IBM's compilers need a #pragma
72 in "each module that needs to use alloca". */
73 #if ! defined (alloca)
74 /* We need lots of variants for MIPS, to cover all versions and perversions
75 of OSes for MIPS. */
76 #if defined (__mips) || defined (MIPSEL) || defined (MIPSEB) \
77 || defined (_MIPSEL) || defined (_MIPSEB) || defined (__sgi) \
78 || defined (__alpha) || defined (__sparc) || defined (sparc) \
79 || defined (__ksr__)
80 #include <alloca.h>
81 #define HAVE_ALLOCA
82 #endif
83 #if defined (_IBMR2)
84 #pragma alloca
85 #define HAVE_ALLOCA
86 #endif
87 #if defined (__DECC)
88 #define alloca(x) __ALLOCA(x)
89 #define HAVE_ALLOCA
90 #endif
91 #endif
92
93 #if defined (alloca)
94 #define HAVE_ALLOCA
95 #endif
96
97 /* Racket: we turn off alloca to avoid stack-overflow issues. */
98 #undef HAVE_ALLOCA
99
100 #if ! defined (HAVE_ALLOCA) || USE_STACK_ALLOC
101
102 struct tmp_marker
103 {
104 struct gmp_tmp_stack *which_chunk;
105 void *alloc_point;
106 };
107
108 typedef struct tmp_marker tmp_marker;
109
110 #if __STDC__
111 void *__gmp_tmp_alloc (unsigned long);
112 void __gmp_tmp_mark (tmp_marker *);
113 void __gmp_tmp_free (tmp_marker *);
114 #else
115 void *__gmp_tmp_alloc ();
116 void __gmp_tmp_mark ();
117 void __gmp_tmp_free ();
118 #endif
119
120 #ifndef __TMP_ALIGN
121 #define __TMP_ALIGN 8
122 #endif
123
124 #define TMP_DECL(marker) tmp_marker marker
125 #define TMP_ALLOC(size) \
126 __gmp_tmp_alloc (((unsigned long) (size) + __TMP_ALIGN - 1) & -__TMP_ALIGN)
127 #define TMP_MARK(marker) __gmp_tmp_mark (&marker)
128 #define TMP_FREE(marker) __gmp_tmp_free (&marker)
129 #else
130 #define TMP_DECL(m)
131 #define TMP_ALLOC(x) alloca(x)
132 #define TMP_MARK(m)
133 #define TMP_FREE(m)
134 #endif
135
136 /* Allocating various types. */
137 #define TMP_ALLOC_TYPE(n,type) ((type *) TMP_ALLOC ((n) * sizeof (type)))
138 #define TMP_ALLOC_LIMBS(n) TMP_ALLOC_TYPE(n,mp_limb_t)
139 #define TMP_ALLOC_MP_PTRS(n) TMP_ALLOC_TYPE(n,mp_ptr)
140
141
142 #if ! defined (__GNUC__) /* FIXME: Test for C++ compilers here,
143 __DECC understands __inline */
144 #define inline /* Empty */
145 #endif
146
147 #define ABS(x) (x >= 0 ? x : -x)
148 #define MIN(l,o) ((l) < (o) ? (l) : (o))
149 #define MAX(h,i) ((h) > (i) ? (h) : (i))
150 #define numberof(x) (sizeof (x) / sizeof ((x)[0]))
151
152 /* Field access macros. */
153 #define SIZ(x) ((x)->_mp_size)
154 #define ABSIZ(x) ABS (SIZ (x))
155 #define PTR(x) ((x)->_mp_d)
156 #define LIMBS(x) ((x)->_mp_d)
157 #define EXP(x) ((x)->_mp_exp)
158 #define PREC(x) ((x)->_mp_prec)
159 #define ALLOC(x) ((x)->_mp_alloc)
160
161 /* Extra casts because shorts are promoted to ints by "~" and "<<". "-1"
162 rather than "1" in SIGNED_TYPE_MIN avoids warnings from some compilers
163 about arithmetic overflow. */
164 #define UNSIGNED_TYPE_MAX(type) ((type) ~ (type) 0)
165 #define UNSIGNED_TYPE_HIGHBIT(type) ((type) ~ (UNSIGNED_TYPE_MAX(type) >> 1))
166 #define SIGNED_TYPE_MIN(type) (((type) -1) << (8*sizeof(type)-1))
167 #define SIGNED_TYPE_MAX(type) ((type) ~ SIGNED_TYPE_MIN(type))
168 #define SIGNED_TYPE_HIGHBIT(type) SIGNED_TYPE_MIN(type)
169
170 #define MP_LIMB_T_MAX UNSIGNED_TYPE_MAX (mp_limb_t)
171 #define MP_LIMB_T_HIGHBIT UNSIGNED_TYPE_HIGHBIT (mp_limb_t)
172
173 #define MP_SIZE_T_MAX SIGNED_TYPE_MAX (mp_size_t)
174
175 #ifndef ULONG_MAX
176 #define ULONG_MAX UNSIGNED_TYPE_MAX (unsigned long)
177 #endif
178 #define ULONG_HIGHBIT UNSIGNED_TYPE_HIGHBIT (unsigned long)
179 #define LONG_HIGHBIT SIGNED_TYPE_HIGHBIT (long)
180 #ifndef LONG_MAX
181 #define LONG_MAX SIGNED_TYPE_MAX (long)
182 #endif
183
184 #ifndef USHORT_MAX
185 #define USHORT_MAX UNSIGNED_TYPE_MAX (unsigned short)
186 #endif
187 #define USHORT_HIGHBIT UNSIGNED_TYPE_HIGHBIT (unsigned short)
188 #define SHORT_HIGHBIT SIGNED_TYPE_HIGHBIT (short)
189 #ifndef SHORT_MAX
190 #define SHORT_MAX SIGNED_TYPE_MAX (short)
191 #endif
192
193
194 /* Swap macros. */
195
196 #define MP_LIMB_T_SWAP(x, y) \
197 do { \
198 mp_limb_t __mp_limb_t_swap__tmp = (x); \
199 (x) = (y); \
200 (y) = __mp_limb_t_swap__tmp; \
201 } while (0)
202 #define MP_SIZE_T_SWAP(x, y) \
203 do { \
204 mp_size_t __mp_size_t_swap__tmp = (x); \
205 (x) = (y); \
206 (y) = __mp_size_t_swap__tmp; \
207 } while (0)
208
209 #define MP_PTR_SWAP(x, y) \
210 do { \
211 mp_ptr __mp_ptr_swap__tmp = (x); \
212 (x) = (y); \
213 (y) = __mp_ptr_swap__tmp; \
214 } while (0)
215 #define MP_SRCPTR_SWAP(x, y) \
216 do { \
217 mp_srcptr __mp_srcptr_swap__tmp = (x); \
218 (x) = (y); \
219 (y) = __mp_srcptr_swap__tmp; \
220 } while (0)
221
222 #define MPN_PTR_SWAP(xp,xs, yp,ys) \
223 do { \
224 MP_PTR_SWAP (xp, yp); \
225 MP_SIZE_T_SWAP (xs, ys); \
226 } while(0)
227 #define MPN_SRCPTR_SWAP(xp,xs, yp,ys) \
228 do { \
229 MP_SRCPTR_SWAP (xp, yp); \
230 MP_SIZE_T_SWAP (xs, ys); \
231 } while(0)
232
233 #define MPZ_PTR_SWAP(x, y) \
234 do { \
235 mpz_ptr __mpz_ptr_swap__tmp = (x); \
236 (x) = (y); \
237 (y) = __mpz_ptr_swap__tmp; \
238 } while (0)
239 #define MPZ_SRCPTR_SWAP(x, y) \
240 do { \
241 mpz_srcptr __mpz_srcptr_swap__tmp = (x); \
242 (x) = (y); \
243 (y) = __mpz_srcptr_swap__tmp; \
244 } while (0)
245
246
247 #if defined (__cplusplus)
248 extern "C" {
249 #endif
250
251 /* FIXME: These are purely internal, so do a search and replace to change
252 them to __gmp forms, rather than using these macros. */
253 #define _mp_allocate_func __gmp_allocate_func
254 #define _mp_reallocate_func __gmp_reallocate_func
255 #define _mp_free_func __gmp_free_func
256 #define _mp_default_allocate __gmp_default_allocate
257 #define _mp_default_reallocate __gmp_default_reallocate
258 #define _mp_default_free __gmp_default_free
259
260 extern void * (*_mp_allocate_func) _PROTO ((size_t));
261 extern void * (*_mp_reallocate_func) _PROTO ((void *, size_t, size_t));
262 extern void (*_mp_free_func) _PROTO ((void *, size_t));
263
264 void *_mp_default_allocate _PROTO ((size_t));
265 void *_mp_default_reallocate _PROTO ((void *, size_t, size_t));
266 void _mp_default_free _PROTO ((void *, size_t));
267
268 #define _MP_ALLOCATE_FUNC_TYPE(n,type) \
269 ((type *) (*_mp_allocate_func) ((n) * sizeof (type)))
270 #define _MP_ALLOCATE_FUNC_LIMBS(n) _MP_ALLOCATE_FUNC_TYPE(n,mp_limb_t)
271
272 #define _MP_FREE_FUNC_TYPE(p,n,type) (*_mp_free_func) (p, (n) * sizeof (type))
273 #define _MP_FREE_FUNC_LIMBS(p,n) _MP_FREE_FUNC_TYPE(p,n,mp_limb_t)
274
275
276 #if (__STDC__-0) || defined (__cplusplus)
277
278 #else
279
280 #define const /* Empty */
281 #define signed /* Empty */
282
283 #endif
284
285 #if defined (__GNUC__) && defined (__i386__)
286 #if 0 /* check that these actually improve things */
287 #define MPN_COPY_INCR(DST, SRC, N) \
288 __asm__ ("cld\n\trep\n\tmovsl" : : \
289 "D" (DST), "S" (SRC), "c" (N) : \
290 "cx", "di", "si", "memory")
291 #define MPN_COPY_DECR(DST, SRC, N) \
292 __asm__ ("std\n\trep\n\tmovsl" : : \
293 "D" ((DST) + (N) - 1), "S" ((SRC) + (N) - 1), "c" (N) : \
294 "cx", "di", "si", "memory")
295 #define MPN_NORMALIZE_NOT_ZERO(P, N) \
296 do { \
297 __asm__ ("std\n\trepe\n\tscasl" : "=c" (N) : \
298 "a" (0), "D" ((P) + (N) - 1), "0" (N) : \
299 "cx", "di"); \
300 (N)++; \
301 } while (0)
302 #endif
303 #endif
304
305 #if HAVE_NATIVE_mpn_copyi
306 #define mpn_copyi __MPN(copyi)
307 void mpn_copyi _PROTO ((mp_ptr, mp_srcptr, mp_size_t));
308 #endif
309
310 /* Remap names of internal mpn functions. */
311 #define __clz_tab __MPN(clz_tab)
312 #define mpn_udiv_w_sdiv __MPN(udiv_w_sdiv)
313 #define mpn_reciprocal __MPN(reciprocal)
314
315 #define mpn_sb_divrem_mn __MPN(sb_divrem_mn)
316 #define mpn_bz_divrem_n __MPN(bz_divrem_n)
317 /* #define mpn_tdiv_q __MPN(tdiv_q) */
318
319 #define mpn_kara_mul_n __MPN(kara_mul_n)
320 void mpn_kara_mul_n _PROTO((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t, mp_ptr));
321
322 #define mpn_kara_sqr_n __MPN(kara_sqr_n)
323 void mpn_kara_sqr_n _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_ptr));
324
325 #define mpn_toom3_mul_n __MPN(toom3_mul_n)
326 void mpn_toom3_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t,mp_ptr));
327
328 #define mpn_toom3_sqr_n __MPN(toom3_sqr_n)
329 void mpn_toom3_sqr_n _PROTO((mp_ptr, mp_srcptr, mp_size_t, mp_ptr));
330
331 #define mpn_fft_best_k __MPN(fft_best_k)
332 int mpn_fft_best_k _PROTO ((mp_size_t n, int sqr));
333
334 #define mpn_mul_fft __MPN(mul_fft)
335 void mpn_mul_fft _PROTO ((mp_ptr op, mp_size_t pl,
336 mp_srcptr n, mp_size_t nl,
337 mp_srcptr m, mp_size_t ml,
338 int k));
339
340 #define mpn_mul_fft_full __MPN(mul_fft_full)
341 void mpn_mul_fft_full _PROTO ((mp_ptr op,
342 mp_srcptr n, mp_size_t nl,
343 mp_srcptr m, mp_size_t ml));
344
345 #define mpn_fft_next_size __MPN(fft_next_size)
346 mp_size_t mpn_fft_next_size _PROTO ((mp_size_t pl, int k));
347
348 mp_limb_t mpn_sb_divrem_mn _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t));
349 mp_limb_t mpn_bz_divrem_n _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t));
350 /* void mpn_tdiv_q _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)); */
351
352 /* Copy NLIMBS *limbs* from SRC to DST, NLIMBS==0 allowed. */
353 #ifndef MPN_COPY_INCR
354 #if HAVE_NATIVE_mpn_copyi
355 #define MPN_COPY_INCR(DST, SRC, NLIMBS) mpn_copyi (DST, SRC, NLIMBS)
356 #else
357 #define MPN_COPY_INCR(DST, SRC, NLIMBS) \
358 do { \
359 mp_size_t __i; \
360 for (__i = 0; __i < (NLIMBS); __i++) \
361 (DST)[__i] = (SRC)[__i]; \
362 } while (0)
363 #endif
364 #endif
365
366 #if HAVE_NATIVE_mpn_copyd
367 #define mpn_copyd __MPN(copyd)
368 void mpn_copyd _PROTO ((mp_ptr, mp_srcptr, mp_size_t));
369 #endif
370
371 /* NLIMBS==0 allowed */
372 #ifndef MPN_COPY_DECR
373 #if HAVE_NATIVE_mpn_copyd
374 #define MPN_COPY_DECR(DST, SRC, NLIMBS) mpn_copyd (DST, SRC, NLIMBS)
375 #else
376 #define MPN_COPY_DECR(DST, SRC, NLIMBS) \
377 do { \
378 mp_size_t __i; \
379 for (__i = (NLIMBS) - 1; __i >= 0; __i--) \
380 (DST)[__i] = (SRC)[__i]; \
381 } while (0)
382 #endif
383 #endif
384
385 /* Define MPN_COPY for vector computers. Since #pragma cannot be in a macro,
386 rely on function inlining. */
387 #if defined (_CRAY) || defined (__uxp__)
388 static inline void
_MPN_COPY(d,s,n)389 _MPN_COPY (d, s, n) mp_ptr d; mp_srcptr s; mp_size_t n;
390 {
391 int i; /* Faster for Cray with plain int */
392 #pragma _CRI ivdep /* Cray PVP systems */
393 #pragma loop noalias d,s /* Fujitsu VPP systems */
394 for (i = 0; i < n; i++)
395 d[i] = s[i];
396 }
397 #define MPN_COPY _MPN_COPY
398 #endif
399
400 #ifndef MPN_COPY
401 #define MPN_COPY MPN_COPY_INCR
402 #endif
403
404 /* Zero NLIMBS *limbs* AT DST. */
405 #ifndef MPN_ZERO
406 #define MPN_ZERO(DST, NLIMBS) \
407 do { \
408 mp_size_t __i; \
409 for (__i = 0; __i < (NLIMBS); __i++) \
410 (DST)[__i] = 0; \
411 } while (0)
412 #endif
413
414 #ifndef MPN_NORMALIZE
415 #define MPN_NORMALIZE(DST, NLIMBS) \
416 do { \
417 while (NLIMBS > 0) \
418 { \
419 if ((DST)[(NLIMBS) - 1] != 0) \
420 break; \
421 NLIMBS--; \
422 } \
423 } while (0)
424 #endif
425 #ifndef MPN_NORMALIZE_NOT_ZERO
426 #define MPN_NORMALIZE_NOT_ZERO(DST, NLIMBS) \
427 do { \
428 while (1) \
429 { \
430 if ((DST)[(NLIMBS) - 1] != 0) \
431 break; \
432 NLIMBS--; \
433 } \
434 } while (0)
435 #endif
436
437 /* Strip least significant zero limbs from ptr,size by incrementing ptr and
438 decrementing size. The number in ptr,size must be non-zero, ie. size!=0
439 and somewhere a non-zero limb. */
440 #define MPN_STRIP_LOW_ZEROS_NOT_ZERO(ptr, size) \
441 do \
442 { \
443 ASSERT ((size) != 0); \
444 while ((ptr)[0] == 0) \
445 { \
446 (ptr)++; \
447 (size)--; \
448 ASSERT (size >= 0); \
449 } \
450 } \
451 while (0)
452
453 /* Initialize X of type mpz_t with space for NLIMBS limbs. X should be a
454 temporary variable; it will be automatically cleared out at function
455 return. We use __x here to make it possible to accept both mpz_ptr and
456 mpz_t arguments. */
457 #define MPZ_TMP_INIT(X, NLIMBS) \
458 do { \
459 mpz_ptr __x = (X); \
460 __x->_mp_alloc = (NLIMBS); \
461 __x->_mp_d = (mp_ptr) TMP_ALLOC ((NLIMBS) * BYTES_PER_MP_LIMB); \
462 } while (0)
463
464 /* Realloc for an mpz_t WHAT if it has less thann NEEDED limbs. */
465 #define MPZ_REALLOC(what,needed) \
466 do { \
467 if ((needed) > ALLOC (what)) \
468 _mpz_realloc (what, needed); \
469 } while (0)
470
471 /* If KARATSUBA_MUL_THRESHOLD is not already defined, define it to a
472 value which is good on most machines. */
473 #ifndef KARATSUBA_MUL_THRESHOLD
474 #define KARATSUBA_MUL_THRESHOLD 32
475 #endif
476
477 /* If TOOM3_MUL_THRESHOLD is not already defined, define it to a
478 value which is good on most machines. */
479 #ifndef TOOM3_MUL_THRESHOLD
480 #define TOOM3_MUL_THRESHOLD 256
481 #endif
482
483 #ifndef KARATSUBA_SQR_THRESHOLD
484 #define KARATSUBA_SQR_THRESHOLD (2*KARATSUBA_MUL_THRESHOLD)
485 #endif
486
487 #ifndef TOOM3_SQR_THRESHOLD
488 #define TOOM3_SQR_THRESHOLD (2*TOOM3_MUL_THRESHOLD)
489 #endif
490
491 /* First k to use for an FFT modF multiply. A modF FFT is an order
492 log(2^k)/log(2^(k-1)) algorithm, so k=3 is merely 1.5 like karatsuba,
493 whereas k=4 is 1.33 which is faster than toom3 at 1.485. */
494 #define FFT_FIRST_K 4
495
496 /* Threshold at which FFT should be used to do a modF NxN -> N multiply. */
497 #ifndef FFT_MODF_MUL_THRESHOLD
498 #define FFT_MODF_MUL_THRESHOLD (TOOM3_MUL_THRESHOLD * 3)
499 #endif
500 #ifndef FFT_MODF_SQR_THRESHOLD
501 #define FFT_MODF_SQR_THRESHOLD (TOOM3_SQR_THRESHOLD * 3)
502 #endif
503
504 /* Threshold at which FFT should be used to do an NxN -> 2N multiply. This
505 will be a size where FFT is using k=7 or k=8, since an FFT-k used for an
506 NxN->2N multiply and not recursing into itself is an order
507 log(2^k)/log(2^(k-2)) algorithm, so it'll be at least k=7 at 1.39 which
508 is the first better than toom3. */
509 #ifndef FFT_MUL_THRESHOLD
510 #define FFT_MUL_THRESHOLD (FFT_MODF_MUL_THRESHOLD * 10)
511 #endif
512 #ifndef FFT_SQR_THRESHOLD
513 #define FFT_SQR_THRESHOLD (FFT_MODF_SQR_THRESHOLD * 10)
514 #endif
515
516 /* Table of thresholds for successive modF FFT "k"s. The first entry is
517 where FFT_FIRST_K+1 should be used, the second FFT_FIRST_K+2,
518 etc. See mpn_fft_best_k(). */
519 #ifndef FFT_MUL_TABLE
520 #define FFT_MUL_TABLE \
521 { TOOM3_MUL_THRESHOLD * 4, /* k=5 */ \
522 TOOM3_MUL_THRESHOLD * 8, /* k=6 */ \
523 TOOM3_MUL_THRESHOLD * 16, /* k=7 */ \
524 TOOM3_MUL_THRESHOLD * 32, /* k=8 */ \
525 TOOM3_MUL_THRESHOLD * 96, /* k=9 */ \
526 TOOM3_MUL_THRESHOLD * 288, /* k=10 */ \
527 0 }
528 #endif
529 #ifndef FFT_SQR_TABLE
530 #define FFT_SQR_TABLE \
531 { TOOM3_SQR_THRESHOLD * 4, /* k=5 */ \
532 TOOM3_SQR_THRESHOLD * 8, /* k=6 */ \
533 TOOM3_SQR_THRESHOLD * 16, /* k=7 */ \
534 TOOM3_SQR_THRESHOLD * 32, /* k=8 */ \
535 TOOM3_SQR_THRESHOLD * 96, /* k=9 */ \
536 TOOM3_SQR_THRESHOLD * 288, /* k=10 */ \
537 0 }
538 #endif
539
540 #ifndef FFT_TABLE_ATTRS
541 #define FFT_TABLE_ATTRS static const
542 #endif
543
544 #define MPN_FFT_TABLE_SIZE 16
545
546
547 /* Return non-zero if xp,xsize and yp,ysize overlap.
548 If xp+xsize<=yp there's no overlap, or if yp+ysize<=xp there's no
549 overlap. If both these are false, there's an overlap. */
550 #define MPN_OVERLAP_P(xp, xsize, yp, ysize) \
551 ((xp) + (xsize) > (yp) && (yp) + (ysize) > (xp))
552
553
554 /* ASSERT() is a private assertion checking scheme, similar to <assert.h>.
555 ASSERT() does the check only if WANT_ASSERT is selected, ASSERT_ALWAYS()
556 does it always. Generally assertions are meant for development, but
557 might help when looking for a problem later too.
558
559 ASSERT_NOCARRY() uses ASSERT() to check the expression is zero, but if
560 assertion checking is disabled, the expression is still evaluated. This
561 is meant for use with routines like mpn_add_n() where the return value
562 represents a carry or whatever that shouldn't occur. For example,
563 ASSERT_NOCARRY (mpn_add_n (rp, s1p, s2p, size)); */
564
565 #ifdef __LINE__
566 #define ASSERT_LINE __LINE__
567 #else
568 #define ASSERT_LINE -1
569 #endif
570
571 #ifdef __FILE__
572 #define ASSERT_FILE __FILE__
573 #else
574 #define ASSERT_FILE ""
575 #endif
576
577 static int __gmp_assert_fail _PROTO((const char *filename, int linenum,
578 const char *expr));
579
580 #if HAVE_STRINGIZE
581 #define ASSERT_FAIL(expr) __gmp_assert_fail (ASSERT_FILE, ASSERT_LINE, #expr)
582 #else
583 #define ASSERT_FAIL(expr) __gmp_assert_fail (ASSERT_FILE, ASSERT_LINE, "expr")
584 #endif
585
586 #if HAVE_VOID
587 #define CAST_TO_VOID (void)
588 #else
589 #define CAST_TO_VOID
590 #endif
591
592 #define ASSERT_ALWAYS(expr) ((expr) ? 0 : ASSERT_FAIL (expr))
593
594 #if WANT_ASSERT
595 #define ASSERT(expr) ASSERT_ALWAYS (expr)
596 #define ASSERT_NOCARRY(expr) ASSERT_ALWAYS ((expr) == 0)
597
598 #else
599 #define ASSERT(expr) (CAST_TO_VOID 0)
600 #define ASSERT_NOCARRY(expr) (expr)
601 #endif
602
603
604 #if HAVE_NATIVE_mpn_com_n
605 #define mpn_com_n __MPN(com_n)
606 void mpn_com_n _PROTO ((mp_ptr, mp_srcptr, mp_size_t));
607 #else
608 #define mpn_com_n(d,s,n) \
609 do \
610 { \
611 mp_ptr __d = (d); \
612 mp_srcptr __s = (s); \
613 mp_size_t __n = (n); \
614 do \
615 *__d++ = ~ *__s++; \
616 while (--__n); \
617 } \
618 while (0)
619 #endif
620
621 #define MPN_LOGOPS_N_INLINE(d,s1,s2,n,dop,op,s2op) \
622 do \
623 { \
624 mp_ptr __d = (d); \
625 mp_srcptr __s1 = (s1); \
626 mp_srcptr __s2 = (s2); \
627 mp_size_t __n = (n); \
628 do \
629 *__d++ = dop (*__s1++ op s2op *__s2++); \
630 while (--__n); \
631 } \
632 while (0)
633
634 #if HAVE_NATIVE_mpn_and_n
635 #define mpn_and_n __MPN(and_n)
636 void mpn_and_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
637 #else
638 #define mpn_and_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n, ,&, )
639 #endif
640
641 #if HAVE_NATIVE_mpn_andn_n
642 #define mpn_andn_n __MPN(andn_n)
643 void mpn_andn_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
644 #else
645 #define mpn_andn_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n, ,&,~)
646 #endif
647
648 #if HAVE_NATIVE_mpn_nand_n
649 #define mpn_nand_n __MPN(nand_n)
650 void mpn_nand_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
651 #else
652 #define mpn_nand_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n,~,&, )
653 #endif
654
655 #if HAVE_NATIVE_mpn_ior_n
656 #define mpn_ior_n __MPN(ior_n)
657 void mpn_ior_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
658 #else
659 #define mpn_ior_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n, ,|, )
660 #endif
661
662 #if HAVE_NATIVE_mpn_iorn_n
663 #define mpn_iorn_n __MPN(iorn_n)
664 void mpn_iorn_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
665 #else
666 #define mpn_iorn_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n, ,|,~)
667 #endif
668
669 #if HAVE_NATIVE_mpn_nior_n
670 #define mpn_nior_n __MPN(nior_n)
671 void mpn_nior_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
672 #else
673 #define mpn_nior_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n,~,|, )
674 #endif
675
676 #if HAVE_NATIVE_mpn_xor_n
677 #define mpn_xor_n __MPN(xor_n)
678 void mpn_xor_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
679 #else
680 #define mpn_xor_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n, ,^, )
681 #endif
682
683 #if HAVE_NATIVE_mpn_xnor_n
684 #define mpn_xnor_n __MPN(xnor_n)
685 void mpn_xnor_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
686 #else
687 #define mpn_xnor_n(d,s1,s2,n) MPN_LOGOPS_N_INLINE(d,s1,s2,n,~,^, )
688 #endif
689
690 /* Structure for conversion between internal binary format and
691 strings in base 2..36. */
692 struct bases
693 {
694 /* Number of digits in the conversion base that always fits in an mp_limb_t.
695 For example, for base 10 on a machine where a mp_limb_t has 32 bits this
696 is 9, since 10**9 is the largest number that fits into a mp_limb_t. */
697 int chars_per_limb;
698
699 /* log(2)/log(conversion_base) */
700 double chars_per_bit_exactly;
701
702 /* base**chars_per_limb, i.e. the biggest number that fits a word, built by
703 factors of base. Exception: For 2, 4, 8, etc, big_base is log2(base),
704 i.e. the number of bits used to represent each digit in the base. */
705 mp_limb_t big_base;
706
707 /* A BITS_PER_MP_LIMB bit approximation to 1/big_base, represented as a
708 fixed-point number. Instead of dividing by big_base an application can
709 choose to multiply by big_base_inverted. */
710 mp_limb_t big_base_inverted;
711 };
712
713 #define __mp_bases __MPN(mp_bases)
714 extern const struct bases __mp_bases[];
715 extern mp_size_t __gmp_default_fp_limb_precision;
716
717 #if defined (__i386__)
718 #define TARGET_REGISTER_STARVED 1
719 #else
720 #define TARGET_REGISTER_STARVED 0
721 #endif
722
723 #if defined (__arm__)
724 # define HAVE_NATIVE_mpn_invert_limb 1
725 #endif
726
727 /* Use a library function for invert_limb, if available. */
728 #if ! defined (invert_limb) && HAVE_NATIVE_mpn_invert_limb
729 #define mpn_invert_limb __MPN(invert_limb)
730 mp_limb_t mpn_invert_limb _PROTO ((mp_limb_t));
731 #define invert_limb(invxl,xl) (invxl = __MPN(invert_limb) (xl))
732 #endif
733
734 #ifndef invert_limb
735 #define invert_limb(invxl,xl) \
736 do { \
737 mp_limb_t dummy USED_ONLY_SOMETIMES; \
738 if (xl << 1 == 0) \
739 invxl = ~(mp_limb_t) 0; \
740 else \
741 udiv_qrnnd (invxl, dummy, -xl, 0, xl); \
742 } while (0)
743 #endif
744
745 /* Divide the two-limb number in (NH,,NL) by D, with DI being the largest
746 limb not larger than (2**(2*BITS_PER_MP_LIMB))/D - (2**BITS_PER_MP_LIMB).
747 If this would yield overflow, DI should be the largest possible number
748 (i.e., only ones). For correct operation, the most significant bit of D
749 has to be set. Put the quotient in Q and the remainder in R. */
750 #define udiv_qrnnd_preinv(q, r, nh, nl, d, di) \
751 do { \
752 mp_limb_t _q, _r; \
753 mp_limb_t _ql USED_ONLY_SOMETIMES; \
754 mp_limb_t _xh, _xl; \
755 umul_ppmm (_q, _ql, (nh), (di)); \
756 _q += (nh); /* DI is 2**BITS_PER_MP_LIMB too small */\
757 umul_ppmm (_xh, _xl, _q, (d)); \
758 sub_ddmmss (_xh, _r, (nh), (nl), _xh, _xl); \
759 if (_xh != 0) \
760 { \
761 sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \
762 _q += 1; \
763 if (_xh != 0) \
764 { \
765 sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \
766 _q += 1; \
767 } \
768 } \
769 if (_r >= (d)) \
770 { \
771 _r -= (d); \
772 _q += 1; \
773 } \
774 (r) = _r; \
775 (q) = _q; \
776 } while (0)
777 /* Like udiv_qrnnd_preinv, but for for any value D. DNORM is D shifted left
778 so that its most significant bit is set. LGUP is ceil(log2(D)). */
779 #define udiv_qrnnd_preinv2gen(q, r, nh, nl, d, di, dnorm, lgup) \
780 do { \
781 mp_limb_t _n2, _n10, _n1, _nadj, _q1; \
782 mp_limb_t _xh, _xl; \
783 _n2 = ((nh) << (BITS_PER_MP_LIMB - (lgup))) + ((nl) >> 1 >> (l - 1));\
784 _n10 = (nl) << (BITS_PER_MP_LIMB - (lgup)); \
785 _n1 = ((mp_limb_signed_t) _n10 >> (BITS_PER_MP_LIMB - 1)); \
786 _nadj = _n10 + (_n1 & (dnorm)); \
787 umul_ppmm (_xh, _xl, di, _n2 - _n1); \
788 add_ssaaaa (_xh, _xl, _xh, _xl, 0, _nadj); \
789 _q1 = ~(_n2 + _xh); \
790 umul_ppmm (_xh, _xl, _q1, d); \
791 add_ssaaaa (_xh, _xl, _xh, _xl, nh, nl); \
792 _xh -= (d); \
793 (r) = _xl + ((d) & _xh); \
794 (q) = _xh - _q1; \
795 } while (0)
796 /* Exactly like udiv_qrnnd_preinv, but branch-free. It is not clear which
797 version to use. */
798 #define udiv_qrnnd_preinv2norm(q, r, nh, nl, d, di) \
799 do { \
800 mp_limb_t _n2, _n10, _n1, _nadj, _q1; \
801 mp_limb_t _xh, _xl; \
802 _n2 = (nh); \
803 _n10 = (nl); \
804 _n1 = ((mp_limb_signed_t) _n10 >> (BITS_PER_MP_LIMB - 1)); \
805 _nadj = _n10 + (_n1 & (d)); \
806 umul_ppmm (_xh, _xl, di, _n2 - _n1); \
807 add_ssaaaa (_xh, _xl, _xh, _xl, 0, _nadj); \
808 _q1 = ~(_n2 + _xh); \
809 umul_ppmm (_xh, _xl, _q1, d); \
810 add_ssaaaa (_xh, _xl, _xh, _xl, nh, nl); \
811 _xh -= (d); \
812 (r) = _xl + ((d) & _xh); \
813 (q) = _xh - _q1; \
814 } while (0)
815
816
817 /* modlimb_invert() sets "inv" to the multiplicative inverse of "n" modulo
818 2^BITS_PER_MP_LIMB, ie. so that inv*n == 1 mod 2^BITS_PER_MP_LIMB.
819 "n" must be odd (otherwise such an inverse doesn't exist).
820
821 This is not to be confused with invert_limb(), which is completely
822 different.
823
824 The table lookup gives an inverse with the low 8 bits valid, and each
825 multiply step doubles the number of bits. See Jebelean's exact division
826 paper, end of section 4 (reference in gmp.texi). */
827
828 #define modlimb_invert_table __gmp_modlimb_invert_table
829 extern const unsigned char modlimb_invert_table[128];
830
831 #if BITS_PER_MP_LIMB <= 32
832 #define modlimb_invert(inv,n) \
833 do { \
834 mp_limb_t __n = (n); \
835 mp_limb_t __inv; \
836 ASSERT ((__n & 1) == 1); \
837 __inv = modlimb_invert_table[(__n&0xFF)/2]; /* 8 */ \
838 __inv = 2 * __inv - __inv * __inv * __n; /* 16 */ \
839 __inv = 2 * __inv - __inv * __inv * __n; /* 32 */ \
840 ASSERT (__inv * __n == 1); \
841 (inv) = __inv; \
842 } while (0)
843 #endif
844
845 #if BITS_PER_MP_LIMB > 32 && BITS_PER_MP_LIMB <= 64
846 #define modlimb_invert(inv,n) \
847 do { \
848 mp_limb_t __n = (n); \
849 mp_limb_t __inv; \
850 ASSERT ((__n & 1) == 1); \
851 __inv = modlimb_invert_table[(__n&0xFF)/2]; /* 8 */ \
852 __inv = 2 * __inv - __inv * __inv * __n; /* 16 */ \
853 __inv = 2 * __inv - __inv * __inv * __n; /* 32 */ \
854 __inv = 2 * __inv - __inv * __inv * __n; /* 64 */ \
855 ASSERT (__inv * __n == 1); \
856 (inv) = __inv; \
857 } while (0)
858 #endif
859
860
861 /* The `mode' attribute was introduced in GCC 2.2, but we can only distinguish
862 between GCC 2 releases from 2.5, since __GNUC_MINOR__ wasn't introduced
863 until then. */
864 #if (__GNUC__ - 0 > 2 || defined (__GNUC_MINOR__)) && ! defined (__APPLE_CC__)
865 /* Define stuff for longlong.h. */
866 typedef unsigned int UQItype __attribute__ ((mode (QI)));
867 typedef int SItype __attribute__ ((mode (SI)));
868 typedef unsigned int USItype __attribute__ ((mode (SI)));
869 typedef int DItype __attribute__ ((mode (DI)));
870 typedef unsigned int UDItype __attribute__ ((mode (DI)));
871 #else
872 typedef unsigned char UQItype;
873 typedef long SItype;
874 typedef unsigned long USItype;
875 #if defined _LONGLONG || defined _LONG_LONG_LIMB
876 typedef long long int DItype;
877 typedef unsigned long long int UDItype;
878 #else /* Assume `long' gives us a wide enough type. Needed for hppa2.0w. */
879 typedef long int DItype;
880 typedef unsigned long int UDItype;
881 #endif
882 #endif
883
884 typedef mp_limb_t UWtype;
885 typedef unsigned int UHWtype;
886 #define W_TYPE_SIZE BITS_PER_MP_LIMB
887
888 /* Define ieee_double_extract and _GMP_IEEE_FLOATS. */
889
890 #if (defined (__arm__) && (defined (__ARMWEL__) || defined (__linux__)))
891 /* Special case for little endian ARM since floats remain in big-endian. */
892 #define _GMP_IEEE_FLOATS 1
893 union ieee_double_extract
894 {
895 struct
896 {
897 unsigned int manh:20;
898 unsigned int exp:11;
899 unsigned int sig:1;
900 unsigned int manl:32;
901 } s;
902 double d;
903 };
904 #else
905 #if defined (_LITTLE_ENDIAN) || defined (__LITTLE_ENDIAN__) \
906 || defined (__alpha) \
907 || defined (__clipper__) \
908 || defined (__cris) \
909 || defined (__i386__) \
910 || defined (__i860__) \
911 || defined (__i960__) \
912 || defined (MIPSEL) || defined (_MIPSEL) \
913 || defined (__ns32000__) \
914 || defined (__WINNT) || defined (_WIN32)
915 #define _GMP_IEEE_FLOATS 1
916 union ieee_double_extract
917 {
918 struct
919 {
920 unsigned int manl:32;
921 unsigned int manh:20;
922 unsigned int exp:11;
923 unsigned int sig:1;
924 } s;
925 double d;
926 };
927 #else /* Need this as an #else since the tests aren't made exclusive. */
928 #if defined (_BIG_ENDIAN) || defined (__BIG_ENDIAN__) \
929 || defined (__a29k__) || defined (_AM29K) \
930 || defined (__arm__) \
931 || (defined (__convex__) && defined (_IEEE_FLOAT_)) \
932 || defined (_CRAYMPP) \
933 || defined (__i370__) || defined (__mvs__) \
934 || defined (__mc68000__) || defined (__mc68020__) || defined (__m68k__)\
935 || defined(mc68020) \
936 || defined (__m88000__) \
937 || defined (MIPSEB) || defined (_MIPSEB) \
938 || defined (__hppa) || defined (__hppa__) \
939 || defined (__pyr__) \
940 || defined (__ibm032__) \
941 || defined (_IBMR2) || defined (_ARCH_PPC) \
942 || defined (__sh__) \
943 || defined (__sparc) || defined (sparc) \
944 || defined (__we32k__)
945 #define _GMP_IEEE_FLOATS 1
946 union ieee_double_extract
947 {
948 struct
949 {
950 unsigned int sig:1;
951 unsigned int exp:11;
952 unsigned int manh:20;
953 unsigned int manl:32;
954 } s;
955 double d;
956 };
957 #endif
958 #endif
959 #endif
960
961 /* Using "(2.0 * ((mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1)))" doesn't work on
962 SunOS 4.1.4 native /usr/ucb/cc (K&R), it comes out as -4294967296.0,
963 presumably due to treating the mp_limb_t constant as signed rather than
964 unsigned. */
965 #define MP_BASE_AS_DOUBLE (4.0 * ((mp_limb_t) 1 << (BITS_PER_MP_LIMB - 2)))
966 #if BITS_PER_MP_LIMB == 64
967 #define LIMBS_PER_DOUBLE 2
968 #else
969 #define LIMBS_PER_DOUBLE 3
970 #endif
971
972 double __gmp_scale2 _PROTO ((double, int));
973 int __gmp_extract_double _PROTO ((mp_ptr, double));
974
975 extern int __gmp_junk;
976 extern const int __gmp_0;
977 #define GMP_ERROR(code) (gmp_errno |= (code), __gmp_junk = 10/__gmp_0)
978 #define DIVIDE_BY_ZERO GMP_ERROR(GMP_ERROR_DIVISION_BY_ZERO)
979 #define SQRT_OF_NEGATIVE GMP_ERROR(GMP_ERROR_SQRT_OF_NEGATIVE)
980
981 #if defined _LONG_LONG_LIMB
982 #if defined (__STDC__)
983 #define CNST_LIMB(C) C##LL
984 #else
985 #define CNST_LIMB(C) C/**/LL
986 #endif
987 #else /* not _LONG_LONG_LIMB */
988 #if defined (__STDC__)
989 #define CNST_LIMB(C) C##L
990 #else
991 #define CNST_LIMB(C) C/**/L
992 #endif
993 #endif /* _LONG_LONG_LIMB */
994
995 /*** Stuff used by mpn/generic/prefsqr.c and mpn/generic/next_prime.c ***/
996 #if BITS_PER_MP_LIMB == 32
997 #define PP 0xC0CFD797L /* 3 x 5 x 7 x 11 x 13 x ... x 29 */
998 #define PP_INVERTED 0x53E5645CL
999 #define PP_MAXPRIME 29
1000 #define PP_MASK 0x208A28A8L
1001 #endif
1002
1003 #if BITS_PER_MP_LIMB == 64
1004 #define PP CNST_LIMB(0xE221F97C30E94E1D) /* 3 x 5 x 7 x 11 x 13 x ... x 53 */
1005 #define PP_INVERTED CNST_LIMB(0x21CFE6CFC938B36B)
1006 #define PP_MAXPRIME 53
1007 #define PP_MASK CNST_LIMB(0x208A20A08A28A8)
1008 #endif
1009
1010
1011 /* BIT1 means a result value in bit 1 (second least significant bit), with a
1012 zero bit representing +1 and a one bit representing -1. Bits other than
1013 bit 1 are garbage.
1014
1015 JACOBI_TWOS_U_BIT1 and JACOBI_RECIP_UU_BIT1 are used in mpn_jacobi_base
1016 and their speed is important. Expressions are used rather than
1017 conditionals to accumulate sign changes, which effectively means XORs
1018 instead of conditional JUMPs. */
1019
1020 /* (a/0), with a signed; is 1 if a=+/-1, 0 otherwise */
1021 #define JACOBI_S0(a) \
1022 (((a) == 1) | ((a) == -1))
1023
1024 /* (a/0), with a unsigned; is 1 if a=+/-1, 0 otherwise */
1025 #define JACOBI_U0(a) \
1026 ((a) == 1)
1027
1028 /* (a/0), with a an mpz_t; is 1 if a=+/-1, 0 otherwise
1029 An mpz_t always has at least one limb of allocated space, so the fetch of
1030 the low limb is valid. */
1031 #define JACOBI_Z0(a) \
1032 (((SIZ(a) == 1) | (SIZ(a) == -1)) & (PTR(a)[0] == 1))
1033
1034 /* Convert a bit1 to +1 or -1. */
1035 #define JACOBI_BIT1_TO_PN(result_bit1) \
1036 (1 - ((result_bit1) & 2))
1037
1038 /* (2/b), with b unsigned and odd;
1039 is (-1)^((b^2-1)/8) which is 1 if b==1,7mod8 or -1 if b==3,5mod8 and
1040 hence obtained from (b>>1)^b */
1041 #define JACOBI_TWO_U_BIT1(b) \
1042 (ASSERT (b & 1), (((b) >> 1) ^ (b)))
1043
1044 /* (2/b)^twos, with b unsigned and odd */
1045 #define JACOBI_TWOS_U_BIT1(twos, b) \
1046 (((twos) << 1) & JACOBI_TWO_U_BIT1 (b))
1047
1048 /* (2/b)^twos, with b unsigned and odd */
1049 #define JACOBI_TWOS_U(twos, b) \
1050 (JACOBI_BIT1_TO_PN (JACOBI_TWOS_U_BIT1 (twos, b)))
1051
1052 /* (a/b) effect due to sign of a: signed/unsigned, b odd;
1053 is (-1)^((b-1)/2) if a<0, or +1 if a>=0 */
1054 #define JACOBI_ASGN_SU_BIT1(a, b) \
1055 ((((a) < 0) << 1) & (b))
1056
1057 /* (a/b) effect due to sign of b: signed/mpz;
1058 is -1 if a and b both negative, +1 otherwise */
1059 #define JACOBI_BSGN_SZ_BIT1(a, b) \
1060 ((((a) < 0) & (SIZ(b) < 0)) << 1)
1061
1062 /* (a/b) effect due to sign of b: mpz/signed */
1063 #define JACOBI_BSGN_ZS_BIT1(a, b) \
1064 JACOBI_BSGN_SZ_BIT1(b, a)
1065
1066 /* (a/b) reciprocity to switch to (b/a), a,b both unsigned and odd.
1067 Is (-1)^((a-1)*(b-1)/4), which means +1 if either a,b==1mod4 or -1 if
1068 both a,b==3mod4, achieved in bit 1 by a&b. No ASSERT()s about a,b odd
1069 because this is used in a couple of places with only bit 1 of a or b
1070 valid. */
1071 #define JACOBI_RECIP_UU_BIT1(a, b) \
1072 ((a) & (b))
1073
1074
1075 /* For testing and debugging. */
1076 #define MPZ_CHECK_FORMAT(z) \
1077 (ASSERT_ALWAYS (SIZ(z) == 0 || PTR(z)[ABSIZ(z) - 1] != 0), \
1078 ASSERT_ALWAYS (ALLOC(z) >= ABSIZ(z)))
1079 #define MPZ_PROVOKE_REALLOC(z) \
1080 do { ALLOC(z) = ABSIZ(z); } while (0)
1081
1082
1083 #if TUNE_PROGRAM_BUILD
1084 /* Some extras wanted when recompiling some .c files for use by the tune
1085 program. Not part of a normal build. */
1086
1087 extern mp_size_t mul_threshold[];
1088 extern mp_size_t fft_modf_mul_threshold;
1089 extern mp_size_t sqr_threshold[];
1090 extern mp_size_t fft_modf_sqr_threshold;
1091 extern mp_size_t bz_threshold[];
1092 extern mp_size_t fib_threshold[];
1093 extern mp_size_t powm_threshold[];
1094 extern mp_size_t gcd_accel_threshold[];
1095 extern mp_size_t gcdext_threshold[];
1096
1097 #undef KARATSUBA_MUL_THRESHOLD
1098 #undef TOOM3_MUL_THRESHOLD
1099 #undef FFT_MUL_TABLE
1100 #undef FFT_MUL_THRESHOLD
1101 #undef FFT_MODF_MUL_THRESHOLD
1102 #undef KARATSUBA_SQR_THRESHOLD
1103 #undef TOOM3_SQR_THRESHOLD
1104 #undef FFT_SQR_TABLE
1105 #undef FFT_SQR_THRESHOLD
1106 #undef FFT_MODF_SQR_THRESHOLD
1107 #undef BZ_THRESHOLD
1108 #undef FIB_THRESHOLD
1109 #undef POWM_THRESHOLD
1110 #undef GCD_ACCEL_THRESHOLD
1111 #undef GCDEXT_THRESHOLD
1112
1113 #define KARATSUBA_MUL_THRESHOLD mul_threshold[0]
1114 #define TOOM3_MUL_THRESHOLD mul_threshold[1]
1115 #define FFT_MUL_TABLE 0
1116 #define FFT_MUL_THRESHOLD mul_threshold[2]
1117 #define FFT_MODF_MUL_THRESHOLD fft_modf_mul_threshold
1118 #define KARATSUBA_SQR_THRESHOLD sqr_threshold[0]
1119 #define TOOM3_SQR_THRESHOLD sqr_threshold[1]
1120 #define FFT_SQR_TABLE 0
1121 #define FFT_SQR_THRESHOLD sqr_threshold[2]
1122 #define FFT_MODF_SQR_THRESHOLD fft_modf_sqr_threshold
1123 #define BZ_THRESHOLD bz_threshold[0]
1124 #define FIB_THRESHOLD fib_threshold[0]
1125 #define POWM_THRESHOLD powm_threshold[0]
1126 #define GCD_ACCEL_THRESHOLD gcd_accel_threshold[0]
1127 #define GCDEXT_THRESHOLD gcdext_threshold[0]
1128
1129 #define TOOM3_MUL_THRESHOLD_LIMIT 700
1130
1131 #undef FFT_TABLE_ATTRS
1132 #define FFT_TABLE_ATTRS
1133 extern mp_size_t mpn_fft_table[2][MPN_FFT_TABLE_SIZE];
1134
1135 #endif /* TUNE_PROGRAM_BUILD */
1136
1137 #if defined (__cplusplus)
1138 }
1139 #endif
1140