1 | This is gmp.info, produced by makeinfo version 4.2 from gmp.texi. |
---|
2 | |
---|
3 | This manual describes how to install and use the GNU multiple precision |
---|
4 | arithmetic library, version 4.1.1. |
---|
5 | |
---|
6 | Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
---|
7 | 2001, 2002 Free Software Foundation, Inc. |
---|
8 | |
---|
9 | Permission is granted to copy, distribute and/or modify this |
---|
10 | document under the terms of the GNU Free Documentation License, Version |
---|
11 | 1.1 or any later version published by the Free Software Foundation; |
---|
12 | with no Invariant Sections, with the Front-Cover Texts being "A GNU |
---|
13 | Manual", and with the Back-Cover Texts being "You have freedom to copy |
---|
14 | and modify this GNU Manual, like GNU software". A copy of the license |
---|
15 | is included in *Note GNU Free Documentation License::. |
---|
16 | INFO-DIR-SECTION GNU libraries |
---|
17 | START-INFO-DIR-ENTRY |
---|
18 | * gmp: (gmp). GNU Multiple Precision Arithmetic Library. |
---|
19 | END-INFO-DIR-ENTRY |
---|
20 | |
---|
21 | |
---|
22 | File: gmp.info, Node: Top, Next: Copying, Prev: (dir), Up: (dir) |
---|
23 | |
---|
24 | GNU MP |
---|
25 | ****** |
---|
26 | |
---|
27 | This manual describes how to install and use the GNU multiple precision |
---|
28 | arithmetic library, version 4.1.1. |
---|
29 | |
---|
30 | Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
---|
31 | 2001, 2002 Free Software Foundation, Inc. |
---|
32 | |
---|
33 | Permission is granted to copy, distribute and/or modify this |
---|
34 | document under the terms of the GNU Free Documentation License, Version |
---|
35 | 1.1 or any later version published by the Free Software Foundation; |
---|
36 | with no Invariant Sections, with the Front-Cover Texts being "A GNU |
---|
37 | Manual", and with the Back-Cover Texts being "You have freedom to copy |
---|
38 | and modify this GNU Manual, like GNU software". A copy of the license |
---|
39 | is included in *Note GNU Free Documentation License::. |
---|
40 | |
---|
41 | * Menu: |
---|
42 | |
---|
43 | * Copying:: GMP Copying Conditions (LGPL). |
---|
44 | * Introduction to GMP:: Brief introduction to GNU MP. |
---|
45 | * Installing GMP:: How to configure and compile the GMP library. |
---|
46 | * GMP Basics:: What every GMP user should know. |
---|
47 | * Reporting Bugs:: How to usefully report bugs. |
---|
48 | * Integer Functions:: Functions for arithmetic on signed integers. |
---|
49 | * Rational Number Functions:: Functions for arithmetic on rational numbers. |
---|
50 | * Floating-point Functions:: Functions for arithmetic on floats. |
---|
51 | * Low-level Functions:: Fast functions for natural numbers. |
---|
52 | * Random Number Functions:: Functions for generating random numbers. |
---|
53 | * Formatted Output:: `printf' style output. |
---|
54 | * Formatted Input:: `scanf' style input. |
---|
55 | * C++ Class Interface:: Class wrappers around GMP types. |
---|
56 | * BSD Compatible Functions:: All functions found in BSD MP. |
---|
57 | * Custom Allocation:: How to customize the internal allocation. |
---|
58 | * Language Bindings:: Using GMP from other languages. |
---|
59 | * Algorithms:: What happens behind the scenes. |
---|
60 | * Internals:: How values are represented behind the scenes. |
---|
61 | |
---|
62 | * Contributors:: Who brings your this library? |
---|
63 | * References:: Some useful papers and books to read. |
---|
64 | * GNU Free Documentation License:: |
---|
65 | * Concept Index:: |
---|
66 | * Function Index:: |
---|
67 | |
---|
68 | |
---|
69 | File: gmp.info, Node: Copying, Next: Introduction to GMP, Prev: Top, Up: Top |
---|
70 | |
---|
71 | GNU MP Copying Conditions |
---|
72 | ************************* |
---|
73 | |
---|
74 | This library is "free"; this means that everyone is free to use it |
---|
75 | and free to redistribute it on a free basis. The library is not in the |
---|
76 | public domain; it is copyrighted and there are restrictions on its |
---|
77 | distribution, but these restrictions are designed to permit everything |
---|
78 | that a good cooperating citizen would want to do. What is not allowed |
---|
79 | is to try to prevent others from further sharing any version of this |
---|
80 | library that they might get from you. |
---|
81 | |
---|
82 | Specifically, we want to make sure that you have the right to give |
---|
83 | away copies of the library, that you receive source code or else can |
---|
84 | get it if you want it, that you can change this library or use pieces |
---|
85 | of it in new free programs, and that you know you can do these things. |
---|
86 | |
---|
87 | To make sure that everyone has such rights, we have to forbid you to |
---|
88 | deprive anyone else of these rights. For example, if you distribute |
---|
89 | copies of the GNU MP library, you must give the recipients all the |
---|
90 | rights that you have. You must make sure that they, too, receive or |
---|
91 | can get the source code. And you must tell them their rights. |
---|
92 | |
---|
93 | Also, for our own protection, we must make certain that everyone |
---|
94 | finds out that there is no warranty for the GNU MP library. If it is |
---|
95 | modified by someone else and passed on, we want their recipients to |
---|
96 | know that what they have is not what we distributed, so that any |
---|
97 | problems introduced by others will not reflect on our reputation. |
---|
98 | |
---|
99 | The precise conditions of the license for the GNU MP library are |
---|
100 | found in the Lesser General Public License version 2.1 that accompanies |
---|
101 | the source code, see `COPYING.LIB'. Certain demonstration programs are |
---|
102 | provided under the terms of the plain General Public License version 2, |
---|
103 | see `COPYING'. |
---|
104 | |
---|
105 | |
---|
106 | File: gmp.info, Node: Introduction to GMP, Next: Installing GMP, Prev: Copying, Up: Top |
---|
107 | |
---|
108 | Introduction to GNU MP |
---|
109 | ********************** |
---|
110 | |
---|
111 | GNU MP is a portable library written in C for arbitrary precision |
---|
112 | arithmetic on integers, rational numbers, and floating-point numbers. |
---|
113 | It aims to provide the fastest possible arithmetic for all applications |
---|
114 | that need higher precision than is directly supported by the basic C |
---|
115 | types. |
---|
116 | |
---|
117 | Many applications use just a few hundred bits of precision; but some |
---|
118 | applications may need thousands or even millions of bits. GMP is |
---|
119 | designed to give good performance for both, by choosing algorithms |
---|
120 | based on the sizes of the operands, and by carefully keeping the |
---|
121 | overhead at a minimum. |
---|
122 | |
---|
123 | The speed of GMP is achieved by using fullwords as the basic |
---|
124 | arithmetic type, by using sophisticated algorithms, by including |
---|
125 | carefully optimized assembly code for the most common inner loops for |
---|
126 | many different CPUs, and by a general emphasis on speed (as opposed to |
---|
127 | simplicity or elegance). |
---|
128 | |
---|
129 | There is carefully optimized assembly code for these CPUs: ARM, DEC |
---|
130 | Alpha 21064, 21164, and 21264, AMD 29000, AMD K6, K6-2 and Athlon, |
---|
131 | Hitachi SuperH and SH-2, HPPA 1.0, 1.1 and 2.0, Intel Pentium, Pentium |
---|
132 | Pro/II/III, Pentium 4, generic x86, Intel IA-64, i960, Motorola |
---|
133 | MC68000, MC68020, MC88100, and MC88110, Motorola/IBM PowerPC 32 and 64, |
---|
134 | National NS32000, IBM POWER, MIPS R3000, R4000, SPARCv7, SuperSPARC, |
---|
135 | generic SPARCv8, UltraSPARC, DEC VAX, and Zilog Z8000. Some |
---|
136 | optimizations also for Cray vector systems, Clipper, IBM ROMP (RT), and |
---|
137 | Pyramid AP/XP. |
---|
138 | |
---|
139 | There are two public mailing lists of interest. One for general |
---|
140 | questions and discussions about usage of the GMP library and one for |
---|
141 | discussions about development of GMP. There's more information about |
---|
142 | the mailing lists at `http://swox.com/mailman/listinfo/'. These lists |
---|
143 | are *not* for bug reports. |
---|
144 | |
---|
145 | The proper place for bug reports is <bug-gmp@gnu.org>. See *Note |
---|
146 | Reporting Bugs:: for info about reporting bugs. |
---|
147 | |
---|
148 | For up-to-date information on GMP, please see the GMP web pages at |
---|
149 | |
---|
150 | `http://swox.com/gmp/' |
---|
151 | |
---|
152 | The latest version of the library is available at |
---|
153 | |
---|
154 | `ftp://ftp.gnu.org/gnu/gmp' |
---|
155 | |
---|
156 | Many sites around the world mirror `ftp.gnu.org', please use a mirror |
---|
157 | near you, see `http://www.gnu.org/order/ftp.html' for a full list. |
---|
158 | |
---|
159 | How to use this Manual |
---|
160 | ====================== |
---|
161 | |
---|
162 | Everyone should read *Note GMP Basics::. If you need to install the |
---|
163 | library yourself, then read *Note Installing GMP::. If you have a |
---|
164 | system with multiple ABIs, then read *Note ABI and ISA::, for the |
---|
165 | compiler options that must be used on applications. |
---|
166 | |
---|
167 | The rest of the manual can be used for later reference, although it |
---|
168 | is probably a good idea to glance through it. |
---|
169 | |
---|
170 | |
---|
171 | File: gmp.info, Node: Installing GMP, Next: GMP Basics, Prev: Introduction to GMP, Up: Top |
---|
172 | |
---|
173 | Installing GMP |
---|
174 | ************** |
---|
175 | |
---|
176 | GMP has an autoconf/automake/libtool based configuration system. On |
---|
177 | a Unix-like system a basic build can be done with |
---|
178 | |
---|
179 | ./configure |
---|
180 | make |
---|
181 | |
---|
182 | Some self-tests can be run with |
---|
183 | |
---|
184 | make check |
---|
185 | |
---|
186 | And you can install (under `/usr/local' by default) with |
---|
187 | |
---|
188 | make install |
---|
189 | |
---|
190 | If you experience problems, please report them to <bug-gmp@gnu.org>. |
---|
191 | See *Note Reporting Bugs::, for information on what to include in |
---|
192 | useful bug reports. |
---|
193 | |
---|
194 | * Menu: |
---|
195 | |
---|
196 | * Build Options:: |
---|
197 | * ABI and ISA:: |
---|
198 | * Notes for Package Builds:: |
---|
199 | * Notes for Particular Systems:: |
---|
200 | * Known Build Problems:: |
---|
201 | |
---|
202 | |
---|
203 | File: gmp.info, Node: Build Options, Next: ABI and ISA, Prev: Installing GMP, Up: Installing GMP |
---|
204 | |
---|
205 | Build Options |
---|
206 | ============= |
---|
207 | |
---|
208 | All the usual autoconf configure options are available, run |
---|
209 | `./configure --help' for a summary. The file `INSTALL.autoconf' has |
---|
210 | some generic installation information too. |
---|
211 | |
---|
212 | Non-Unix Systems |
---|
213 | `configure' requires various Unix-like tools. On an MS-DOS system |
---|
214 | DJGPP can be used, and on MS Windows Cygwin or MINGW can be used, |
---|
215 | |
---|
216 | `http://www.cygnus.com/cygwin' |
---|
217 | `http://www.delorie.com/djgpp' |
---|
218 | `http://www.mingw.org' |
---|
219 | |
---|
220 | The `macos' directory contains an unsupported port to MacOS 9 on |
---|
221 | Power Macintosh, see `macos/README'. Note that MacOS X "Darwin" |
---|
222 | should use the normal Unix-style `./configure'. |
---|
223 | |
---|
224 | It might be possible to build without the help of `configure', |
---|
225 | certainly all the code is there, but unfortunately you'll be on |
---|
226 | your own. |
---|
227 | |
---|
228 | Build Directory |
---|
229 | To compile in a separate build directory, `cd' to that directory, |
---|
230 | and prefix the configure command with the path to the GMP source |
---|
231 | directory. For example |
---|
232 | |
---|
233 | cd /my/build/dir |
---|
234 | /my/sources/gmp-4.1.1/configure |
---|
235 | |
---|
236 | Not all `make' programs have the necessary features (`VPATH') to |
---|
237 | support this. In particular, SunOS and Slowaris `make' have bugs |
---|
238 | that make them unable to build in a separate directory. Use GNU |
---|
239 | `make' instead. |
---|
240 | |
---|
241 | `--disable-shared', `--disable-static' |
---|
242 | By default both shared and static libraries are built (where |
---|
243 | possible), but one or other can be disabled. Shared libraries |
---|
244 | result in smaller executables and permit code sharing between |
---|
245 | separate running processes, but on some CPUs are slightly slower, |
---|
246 | having a small cost on each function call. |
---|
247 | |
---|
248 | Native Compilation, `--build=CPU-VENDOR-OS' |
---|
249 | For normal native compilation, the system can be specified with |
---|
250 | `--build'. By default `./configure' uses the output from running |
---|
251 | `./config.guess'. On some systems `./config.guess' can determine |
---|
252 | the exact CPU type, on others it will be necessary to give it |
---|
253 | explicitly. For example, |
---|
254 | |
---|
255 | ./configure --build=ultrasparc-sun-solaris2.7 |
---|
256 | |
---|
257 | In all cases the `OS' part is important, since it controls how |
---|
258 | libtool generates shared libraries. Running `./config.guess' is |
---|
259 | the simplest way to see what it should be, if you don't know |
---|
260 | already. |
---|
261 | |
---|
262 | Cross Compilation, `--host=CPU-VENDOR-OS' |
---|
263 | When cross-compiling, the system used for compiling is given by |
---|
264 | `--build' and the system where the library will run is given by |
---|
265 | `--host'. For example when using a FreeBSD Athlon system to build |
---|
266 | GNU/Linux m68k binaries, |
---|
267 | |
---|
268 | ./configure --build=athlon-pc-freebsd3.5 --host=m68k-mac-linux-gnu |
---|
269 | |
---|
270 | Compiler tools are sought first with the host system type as a |
---|
271 | prefix. For example `m68k-mac-linux-gnu-ranlib' is tried, then |
---|
272 | plain `ranlib'. This makes it possible for a set of |
---|
273 | cross-compiling tools to co-exist with native tools. The prefix |
---|
274 | is the argument to `--host', and this can be an alias, such as |
---|
275 | `m68k-linux'. But note that tools don't have to be setup this |
---|
276 | way, it's enough to just have a `PATH' with a suitable |
---|
277 | cross-compiling `cc' etc. |
---|
278 | |
---|
279 | Compiling for a different CPU in the same family as the build |
---|
280 | system is a form of cross-compilation, though very possibly this |
---|
281 | would merely be special options on a native compiler. In any case |
---|
282 | `./configure' avoids depending on being able to run code on the |
---|
283 | build system, which is important when creating binaries for a |
---|
284 | newer CPU since they very possibly won't run on the build system. |
---|
285 | |
---|
286 | In all cases the compiler must be able to produce an executable |
---|
287 | (of whatever format) from a standard C `main'. Although only |
---|
288 | object files will go to make up `libgmp', `./configure' uses |
---|
289 | linking tests for various purposes, such as determining what |
---|
290 | functions are available on the host system. |
---|
291 | |
---|
292 | Currently a warning is given unless an explicit `--build' is used |
---|
293 | when cross-compiling, because it may not be possible to correctly |
---|
294 | guess the build system type if the `PATH' has only a |
---|
295 | cross-compiling `cc'. |
---|
296 | |
---|
297 | Note that the `--target' option is not appropriate for GMP. It's |
---|
298 | for use when building compiler tools, with `--host' being where |
---|
299 | they will run, and `--target' what they'll produce code for. |
---|
300 | Ordinary programs or libraries like GMP are only interested in the |
---|
301 | `--host' part, being where they'll run. (Some past versions of |
---|
302 | GMP used `--target' incorrectly.) |
---|
303 | |
---|
304 | CPU types |
---|
305 | In general, if you want a library that runs as fast as possible, |
---|
306 | you should configure GMP for the exact CPU type your system uses. |
---|
307 | However, this may mean the binaries won't run on older members of |
---|
308 | the family, and might run slower on other members, older or newer. |
---|
309 | The best idea is always to build GMP for the exact machine type |
---|
310 | you intend to run it on. |
---|
311 | |
---|
312 | The following CPUs have specific support. See `configure.in' for |
---|
313 | details of what code and compiler options they select. |
---|
314 | |
---|
315 | * Alpha: alpha, alphaev5, alphaev56, alphapca56, alphapca57, |
---|
316 | alphaev6, alphaev67, alphaev68 |
---|
317 | |
---|
318 | * Cray: c90, j90, t90, sv1 |
---|
319 | |
---|
320 | * HPPA: hppa1.0, hppa1.1, hppa2.0, hppa2.0n, hppa2.0w |
---|
321 | |
---|
322 | * MIPS: mips, mips3, mips64 |
---|
323 | |
---|
324 | * Motorola: m68k, m68000, m68010, m68020, m68030, m68040, |
---|
325 | m68060, m68302, m68360, m88k, m88110 |
---|
326 | |
---|
327 | * POWER: power, power1, power2, power2sc |
---|
328 | |
---|
329 | * PowerPC: powerpc, powerpc64, powerpc401, powerpc403, |
---|
330 | powerpc405, powerpc505, powerpc601, powerpc602, powerpc603, |
---|
331 | powerpc603e, powerpc604, powerpc604e, powerpc620, powerpc630, |
---|
332 | powerpc740, powerpc7400, powerpc7450, powerpc750, powerpc801, |
---|
333 | powerpc821, powerpc823, powerpc860, |
---|
334 | |
---|
335 | * SPARC: sparc, sparcv8, microsparc, supersparc, sparcv9, |
---|
336 | ultrasparc, ultrasparc2, ultrasparc2i, ultrasparc3, sparc64 |
---|
337 | |
---|
338 | * 80x86 family: i386, i486, i586, pentium, pentiummmx, |
---|
339 | pentiumpro, pentium2, pentium3, pentium4, k6, k62, k63, athlon |
---|
340 | |
---|
341 | * Other: a29k, arm, clipper, i960, ns32k, pyramid, sh, sh2, vax, |
---|
342 | z8k |
---|
343 | |
---|
344 | CPUs not listed will use generic C code. |
---|
345 | |
---|
346 | Generic C Build |
---|
347 | If some of the assembly code causes problems, or if otherwise |
---|
348 | desired, the generic C code can be selected with CPU `none'. For |
---|
349 | example, |
---|
350 | |
---|
351 | ./configure --host=none-unknown-freebsd3.5 |
---|
352 | |
---|
353 | Note that this will run quite slowly, but it should be portable |
---|
354 | and should at least make it possible to get something running if |
---|
355 | all else fails. |
---|
356 | |
---|
357 | `ABI' |
---|
358 | On some systems GMP supports multiple ABIs (application binary |
---|
359 | interfaces), meaning data type sizes and calling conventions. By |
---|
360 | default GMP chooses the best ABI available, but a particular ABI |
---|
361 | can be selected. For example |
---|
362 | |
---|
363 | ./configure --host=mips64-sgi-irix6 ABI=n32 |
---|
364 | |
---|
365 | See *Note ABI and ISA::, for the available choices on relevant |
---|
366 | CPUs, and what applications need to do. |
---|
367 | |
---|
368 | `CC', `CFLAGS' |
---|
369 | By default the C compiler used is chosen from among some likely |
---|
370 | candidates, with `gcc' normally preferred if it's present. The |
---|
371 | usual `CC=whatever' can be passed to `./configure' to choose |
---|
372 | something different. |
---|
373 | |
---|
374 | For some systems, default compiler flags are set based on the CPU |
---|
375 | and compiler. The usual `CFLAGS="-whatever"' can be passed to |
---|
376 | `./configure' to use something different or to set good flags for |
---|
377 | systems GMP doesn't otherwise know. |
---|
378 | |
---|
379 | The `CC' and `CFLAGS' used are printed during `./configure', and |
---|
380 | can be found in each generated `Makefile'. This is the easiest way |
---|
381 | to check the defaults when considering changing or adding |
---|
382 | something. |
---|
383 | |
---|
384 | Note that when `CC' and `CFLAGS' are specified on a system |
---|
385 | supporting multiple ABIs it's important to give an explicit |
---|
386 | `ABI=whatever', since GMP can't determine the ABI just from the |
---|
387 | flags and won't be able to select the correct assembler code. |
---|
388 | |
---|
389 | If just `CC' is selected then normal default `CFLAGS' for that |
---|
390 | compiler will be used (if GMP recognises it). For example |
---|
391 | `CC=gcc' can be used to force the use of GCC, with default flags |
---|
392 | (and default ABI). |
---|
393 | |
---|
394 | `CPPFLAGS' |
---|
395 | Any flags like `-D' defines or `-I' includes required by the |
---|
396 | preprocessor should be set in `CPPFLAGS' rather than `CFLAGS'. |
---|
397 | Compiling is done with both `CPPFLAGS' and `CFLAGS', but |
---|
398 | preprocessing uses just `CPPFLAGS'. This distinction is because |
---|
399 | most preprocessors won't accept all the flags the compiler does. |
---|
400 | Preprocessing is done separately in some configure tests, and in |
---|
401 | the `ansi2knr' support for K&R compilers. |
---|
402 | |
---|
403 | C++ Support, `--enable-cxx' |
---|
404 | C++ support in GMP can be enabled with `--enable-cxx', in which |
---|
405 | case a C++ compiler will be required. As a convenience |
---|
406 | `--enable-cxx=detect' can be used to enable C++ support only if a |
---|
407 | compiler can be found. The C++ support consists of a library |
---|
408 | `libgmpxx.la' and header file `gmpxx.h'. |
---|
409 | |
---|
410 | A separate `libgmpxx.la' has been adopted rather than having C++ |
---|
411 | objects within `libgmp.la' in order to ensure dynamic linked C |
---|
412 | programs aren't bloated by a dependency on the C++ standard |
---|
413 | library, and to avoid any chance that the C++ compiler could be |
---|
414 | required when linking plain C programs. |
---|
415 | |
---|
416 | `libgmpxx.la' will use certain internals from `libgmp.la' and can |
---|
417 | only be expected to work with `libgmp.la' from the same GMP |
---|
418 | version. Future changes to the relevant internals will be |
---|
419 | accompanied by renaming, so a mismatch will cause unresolved |
---|
420 | symbols rather than perhaps mysterious misbehaviour. |
---|
421 | |
---|
422 | In general `libgmpxx.la' will be usable only with the C++ compiler |
---|
423 | that built it, since name mangling and runtime support are usually |
---|
424 | incompatible between different compilers. |
---|
425 | |
---|
426 | `CXX', `CXXFLAGS' |
---|
427 | When C++ support is enabled, the C++ compiler and its flags can be |
---|
428 | set with variables `CXX' and `CXXFLAGS' in the usual way. The |
---|
429 | default for `CXX' is the first compiler that works from a list of |
---|
430 | likely candidates, with `g++' normally preferred when available. |
---|
431 | The default for `CXXFLAGS' is to try `CFLAGS', `CFLAGS' without |
---|
432 | `-g', then for `g++' either `-g -O2' or `-O2', or for other |
---|
433 | compilers `-g' or nothing. Trying `CFLAGS' this way is convenient |
---|
434 | when using `gcc' and `g++' together, since the flags for `gcc' will |
---|
435 | usually suit `g++'. |
---|
436 | |
---|
437 | It's important that the C and C++ compilers match, meaning their |
---|
438 | startup and runtime support routines are compatible and that they |
---|
439 | generate code in the same ABI (if there's a choice of ABIs on the |
---|
440 | system). `./configure' isn't currently able to check these things |
---|
441 | very well itself, so for that reason `--disable-cxx' is the |
---|
442 | default, to avoid a build failure due to a compiler mismatch. |
---|
443 | Perhaps this will change in the future. |
---|
444 | |
---|
445 | Incidentally, it's normally not good enough to set `CXX' to the |
---|
446 | same as `CC'. Although `gcc' for instance recognises `foo.cc' as |
---|
447 | C++ code, only `g++' will invoke the linker the right way when |
---|
448 | building an executable or shared library from object files. |
---|
449 | |
---|
450 | Temporary Memory, `--enable-alloca=<choice>' |
---|
451 | GMP allocates temporary workspace using one of the following three |
---|
452 | methods, which can be selected with for instance |
---|
453 | `--enable-alloca=malloc-reentrant'. |
---|
454 | |
---|
455 | * `alloca' - C library or compiler builtin. |
---|
456 | |
---|
457 | * `malloc-reentrant' - the heap, in a re-entrant fashion. |
---|
458 | |
---|
459 | * `malloc-notreentrant' - the heap, with global variables. |
---|
460 | |
---|
461 | For convenience, the following choices are also available. |
---|
462 | `--disable-alloca' is the same as `--enable-alloca=no'. |
---|
463 | |
---|
464 | * `yes' - a synonym for `alloca'. |
---|
465 | |
---|
466 | * `no' - a synonym for `malloc-reentrant'. |
---|
467 | |
---|
468 | * `reentrant' - `alloca' if available, otherwise |
---|
469 | `malloc-reentrant'. This is the default. |
---|
470 | |
---|
471 | * `notreentrant' - `alloca' if available, otherwise |
---|
472 | `malloc-notreentrant'. |
---|
473 | |
---|
474 | `alloca' is reentrant and fast, and is recommended, but when |
---|
475 | working with large numbers it can overflow the available stack |
---|
476 | space, in which case one of the two malloc methods will need to be |
---|
477 | used. Alternately it might be possible to increase available |
---|
478 | stack with `limit', `ulimit' or `setrlimit', or under DJGPP with |
---|
479 | `stubedit' or `_stklen'. Note that depending on the system the |
---|
480 | only indication of stack overflow might be a segmentation |
---|
481 | violation. |
---|
482 | |
---|
483 | `malloc-reentrant' is, as the name suggests, reentrant and thread |
---|
484 | safe, but `malloc-notreentrant' is faster and should be used if |
---|
485 | reentrancy is not required. |
---|
486 | |
---|
487 | The two malloc methods in fact use the memory allocation functions |
---|
488 | selected by `mp_set_memory_functions', these being `malloc' and |
---|
489 | friends by default. *Note Custom Allocation::. |
---|
490 | |
---|
491 | An additional choice `--enable-alloca=debug' is available, to help |
---|
492 | when debugging memory related problems (*note Debugging::). |
---|
493 | |
---|
494 | FFT Multiplication, `--disable-fft' |
---|
495 | By default multiplications are done using Karatsuba, 3-way |
---|
496 | Toom-Cook, and Fermat FFT. The FFT is only used on large to very |
---|
497 | large operands and can be disabled to save code size if desired. |
---|
498 | |
---|
499 | Berkeley MP, `--enable-mpbsd' |
---|
500 | The Berkeley MP compatibility library (`libmp') and header file |
---|
501 | (`mp.h') are built and installed only if `--enable-mpbsd' is used. |
---|
502 | *Note BSD Compatible Functions::. |
---|
503 | |
---|
504 | MPFR, `--enable-mpfr' |
---|
505 | The optional MPFR functions are built and installed only if |
---|
506 | `--enable-mpfr' is used. These are in a separate library |
---|
507 | `libmpfr.a' and are documented separately too (*note Introduction |
---|
508 | to MPFR: (mpfr)Introduction to MPFR.). |
---|
509 | |
---|
510 | Assertion Checking, `--enable-assert' |
---|
511 | This option enables some consistency checking within the library. |
---|
512 | This can be of use while debugging, *note Debugging::. |
---|
513 | |
---|
514 | Execution Profiling, `--enable-profiling=prof/gprof' |
---|
515 | Profiling support can be enabled either for `prof' or `gprof'. |
---|
516 | This adds `-p' or `-pg' respectively to `CFLAGS', and for some |
---|
517 | systems adds corresponding `mcount' calls to the assembler code. |
---|
518 | *Note Profiling::. |
---|
519 | |
---|
520 | `MPN_PATH' |
---|
521 | Various assembler versions of each mpn subroutines are provided. |
---|
522 | For a given CPU, a search is made though a path to choose a |
---|
523 | version of each. For example `sparcv8' has |
---|
524 | |
---|
525 | MPN_PATH="sparc32/v8 sparc32 generic" |
---|
526 | |
---|
527 | which means look first for v8 code, then plain sparc32 (which is |
---|
528 | v7), and finally fall back on generic C. Knowledgeable users with |
---|
529 | special requirements can specify a different path. Normally this |
---|
530 | is completely unnecessary. |
---|
531 | |
---|
532 | Documentation |
---|
533 | The document you're now reading is `gmp.texi'. The usual automake |
---|
534 | targets are available to make PostScript `gmp.ps' and/or DVI |
---|
535 | `gmp.dvi'. |
---|
536 | |
---|
537 | HTML can be produced with `makeinfo --html', see *Note Generating |
---|
538 | HTML: (texinfo)makeinfo html. Or alternately `texi2html', see |
---|
539 | *Note Texinfo to HTML: (texi2html)Top. |
---|
540 | |
---|
541 | PDF can be produced with `texi2dvi --pdf' (*note PDF: (texinfo)PDF |
---|
542 | Output.) or with `pdftex'. |
---|
543 | |
---|
544 | Some supplementary notes can be found in the `doc' subdirectory. |
---|
545 | |
---|
546 | |
---|
547 | File: gmp.info, Node: ABI and ISA, Next: Notes for Package Builds, Prev: Build Options, Up: Installing GMP |
---|
548 | |
---|
549 | ABI and ISA |
---|
550 | =========== |
---|
551 | |
---|
552 | ABI (Application Binary Interface) refers to the calling conventions |
---|
553 | between functions, meaning what registers are used and what sizes the |
---|
554 | various C data types are. ISA (Instruction Set Architecture) refers to |
---|
555 | the instructions and registers a CPU has available. |
---|
556 | |
---|
557 | Some 64-bit ISA CPUs have both a 64-bit ABI and a 32-bit ABI |
---|
558 | defined, the latter for compatibility with older CPUs in the family. |
---|
559 | GMP supports some CPUs like this in both ABIs. In fact within GMP |
---|
560 | `ABI' means a combination of chip ABI, plus how GMP chooses to use it. |
---|
561 | For example in some 32-bit ABIs, GMP may support a limb as either a |
---|
562 | 32-bit `long' or a 64-bit `long long'. |
---|
563 | |
---|
564 | By default GMP chooses the best ABI available for a given system, |
---|
565 | and this generally gives significantly greater speed. But an ABI can |
---|
566 | be chosen explicitly to make GMP compatible with other libraries, or |
---|
567 | particular application requirements. For example, |
---|
568 | |
---|
569 | ./configure ABI=32 |
---|
570 | |
---|
571 | In all cases it's vital that all object code used in a given program |
---|
572 | is compiled for the same ABI. |
---|
573 | |
---|
574 | Usually a limb is implemented as a `long'. When a `long long' limb |
---|
575 | is used this is encoded in the generated `gmp.h'. This is convenient |
---|
576 | for applications, but it does mean that `gmp.h' will vary, and can't be |
---|
577 | just copied around. `gmp.h' remains compiler independent though, since |
---|
578 | all compilers for a particular ABI will be expected to use the same |
---|
579 | limb type. |
---|
580 | |
---|
581 | Currently no attempt is made to follow whatever conventions a system |
---|
582 | has for installing library or header files built for a particular ABI. |
---|
583 | This will probably only matter when installing multiple builds of GMP, |
---|
584 | and it might be as simple as configuring with a special `libdir', or it |
---|
585 | might require more than that. Note that builds for different ABIs need |
---|
586 | to done separately, with a fresh `./configure' and `make' each. |
---|
587 | |
---|
588 | |
---|
589 | HPPA 2.0 (`hppa2.0*') |
---|
590 | |
---|
591 | `ABI=2.0w' |
---|
592 | The 2.0w ABI uses 64-bit limbs and pointers and is available |
---|
593 | on HP-UX 11 or up when using `cc'. `gcc' support for this is |
---|
594 | in progress. Applications must be compiled with |
---|
595 | |
---|
596 | cc +DD64 |
---|
597 | |
---|
598 | `ABI=2.0n' |
---|
599 | The 2.0n ABI means the 32-bit HPPA 1.0 ABI but with a 64-bit |
---|
600 | limb using `long long'. This is available on HP-UX 10 or up |
---|
601 | when using `cc'. No `gcc' support is planned for this. |
---|
602 | Applications must be compiled with |
---|
603 | |
---|
604 | cc +DA2.0 +e |
---|
605 | |
---|
606 | `ABI=1.0' |
---|
607 | HPPA 2.0 CPUs can run all HPPA 1.0 and 1.1 code in the 32-bit |
---|
608 | HPPA 1.0 ABI. No special compiler options are needed for |
---|
609 | applications. |
---|
610 | |
---|
611 | All three ABIs are available for CPUs `hppa2.0w' and `hppa2.0', but |
---|
612 | for CPU `hppa2.0n' only 2.0n or 1.0 are allowed. |
---|
613 | |
---|
614 | |
---|
615 | MIPS under IRIX 6 (`mips*-*-irix[6789]') |
---|
616 | IRIX 6 supports the n32 and 64 ABIs and always has a 64-bit MIPS 3 |
---|
617 | or better CPU. In both these ABIs GMP uses a 64-bit limb. A new |
---|
618 | enough `gcc' is required (2.95 for instance). |
---|
619 | |
---|
620 | `ABI=n32' |
---|
621 | The n32 ABI is 32-bit pointers and integers, but with a |
---|
622 | 64-bit limb using a `long long'. Applications must be |
---|
623 | compiled with |
---|
624 | |
---|
625 | gcc -mabi=n32 |
---|
626 | cc -n32 |
---|
627 | |
---|
628 | `ABI=64' |
---|
629 | The 64-bit ABI is 64-bit pointers and integers. Applications |
---|
630 | must be compiled with |
---|
631 | |
---|
632 | gcc -mabi=64 |
---|
633 | cc -64 |
---|
634 | |
---|
635 | Note that MIPS GNU/Linux, as of kernel version 2.2, doesn't have |
---|
636 | the necessary support for n32 or 64 and so only gets a 32-bit limb |
---|
637 | and the MIPS 2 code. |
---|
638 | |
---|
639 | |
---|
640 | PowerPC 64 (`powerpc64', `powerpc620', `powerpc630') |
---|
641 | |
---|
642 | `ABI=aix64' |
---|
643 | The AIX 64 ABI uses 64-bit limbs and pointers and is |
---|
644 | available on systems `*-*-aix*'. Applications must be |
---|
645 | compiled (and linked) with |
---|
646 | |
---|
647 | gcc -maix64 |
---|
648 | xlc -q64 |
---|
649 | |
---|
650 | `ABI=32' |
---|
651 | This is the basic 32-bit PowerPC ABI. No special compiler |
---|
652 | options are needed for applications. |
---|
653 | |
---|
654 | |
---|
655 | Sparc V9 (`sparcv9' and `ultrasparc*') |
---|
656 | |
---|
657 | `ABI=64' |
---|
658 | The 64-bit V9 ABI is available on Solaris 2.7 and up and |
---|
659 | GNU/Linux. GCC 2.95 or up, or Sun `cc' is required. |
---|
660 | Applications must be compiled with |
---|
661 | |
---|
662 | gcc -m64 -mptr64 -Wa,-xarch=v9 -mcpu=v9 |
---|
663 | cc -xarch=v9 |
---|
664 | |
---|
665 | `ABI=32' |
---|
666 | On Solaris 2.6 and earlier, and on Solaris 2.7 with the |
---|
667 | kernel in 32-bit mode, only the plain V8 32-bit ABI can be |
---|
668 | used, since the kernel doesn't save all registers. GMP still |
---|
669 | uses as much of the V9 ISA as it can in these circumstances. |
---|
670 | No special compiler options are required for applications, |
---|
671 | though using something like the following requesting V9 code |
---|
672 | within the V8 ABI is recommended. |
---|
673 | |
---|
674 | gcc -mv8plus |
---|
675 | cc -xarch=v8plus |
---|
676 | |
---|
677 | `gcc' 2.8 and earlier only supports `-mv8' though. |
---|
678 | |
---|
679 | Don't be confused by the names of these sparc `-m' and `-x' |
---|
680 | options, they're called `arch' but they effectively control the |
---|
681 | ABI. |
---|
682 | |
---|
683 | On Solaris 2.7 with the kernel in 32-bit-mode, a normal native |
---|
684 | build will reject `ABI=64' because the resulting executables won't |
---|
685 | run. `ABI=64' can still be built if desired by making it look |
---|
686 | like a cross-compile, for example |
---|
687 | |
---|
688 | ./configure --build=none --host=sparcv9-sun-solaris2.7 ABI=64 |
---|
689 | |
---|
690 | |
---|
691 | File: gmp.info, Node: Notes for Package Builds, Next: Notes for Particular Systems, Prev: ABI and ISA, Up: Installing GMP |
---|
692 | |
---|
693 | Notes for Package Builds |
---|
694 | ======================== |
---|
695 | |
---|
696 | GMP should present no great difficulties for packaging in a binary |
---|
697 | distribution. |
---|
698 | |
---|
699 | Libtool is used to build the library and `-version-info' is set |
---|
700 | appropriately, having started from `3:0:0' in GMP 3.0. The GMP 4 series |
---|
701 | will be upwardly binary compatible in each release and will be upwardly |
---|
702 | binary compatible with all of the GMP 3 series. Additional function |
---|
703 | interfaces may be added in each release, so on systems where libtool |
---|
704 | versioning is not fully checked by the loader an auxiliary mechanism |
---|
705 | may be needed to express that a dynamic linked application depends on a |
---|
706 | new enough GMP. |
---|
707 | |
---|
708 | An auxiliary mechanism may also be needed to express that |
---|
709 | `libgmpxx.la' (from `--enable-cxx', *note Build Options::) requires |
---|
710 | `libgmp.la' from the same GMP version, since this is not done by the |
---|
711 | libtool versioning, nor otherwise. A mismatch will result in |
---|
712 | unresolved symbols from the linker, or perhaps the loader. |
---|
713 | |
---|
714 | Using `DESTDIR' or a `prefix' override with `make install' and a |
---|
715 | shared `libgmpxx' may run into a libtool relinking problem, see *Note |
---|
716 | Known Build Problems::. |
---|
717 | |
---|
718 | When building a package for a CPU family, care should be taken to use |
---|
719 | `--host' (or `--build') to choose the least common denominator among |
---|
720 | the CPUs which might use the package. For example this might |
---|
721 | necessitate `i386' for x86s, or plain `sparc' (meaning V7) for SPARCs. |
---|
722 | |
---|
723 | Users who care about speed will want GMP built for their exact CPU |
---|
724 | type, to make use of the available optimizations. Providing a way to |
---|
725 | suitably rebuild a package may be useful. This could be as simple as |
---|
726 | making it possible for a user to omit `--build' (and `--host') so |
---|
727 | `./config.guess' will detect the CPU. But a way to manually specify a |
---|
728 | `--build' will be wanted for systems where `./config.guess' is inexact. |
---|
729 | |
---|
730 | Note that `gmp.h' is a generated file, and will be architecture and |
---|
731 | ABI dependent. |
---|
732 | |
---|
733 | |
---|
734 | File: gmp.info, Node: Notes for Particular Systems, Next: Known Build Problems, Prev: Notes for Package Builds, Up: Installing GMP |
---|
735 | |
---|
736 | Notes for Particular Systems |
---|
737 | ============================ |
---|
738 | |
---|
739 | AIX 3 and 4 |
---|
740 | On systems `*-*-aix[34]*' shared libraries are disabled by |
---|
741 | default, since some versions of the native `ar' fail on the |
---|
742 | convenience libraries used. A shared build can be attempted with |
---|
743 | |
---|
744 | ./configure --enable-shared --disable-static |
---|
745 | |
---|
746 | Note that the `--disable-static' is necessary because in a shared |
---|
747 | build libtool makes `libgmp.a' a symlink to `libgmp.so', |
---|
748 | apparently for the benefit of old versions of `ld' which only |
---|
749 | recognise `.a', but unfortunately this is done even if a fully |
---|
750 | functional `ld' is available. |
---|
751 | |
---|
752 | ARM |
---|
753 | On systems `arm*-*-*', versions of GCC up to and including 2.95.3 |
---|
754 | have a bug in unsigned division, giving wrong results for some |
---|
755 | operands. GMP `./configure' will demand GCC 2.95.4 or later. |
---|
756 | |
---|
757 | Microsoft Windows |
---|
758 | On systems `*-*-cygwin*', `*-*-mingw*' and `*-*-pw32*' by default |
---|
759 | GMP builds only a static library, but a DLL can be built instead |
---|
760 | using |
---|
761 | |
---|
762 | ./configure --disable-static --enable-shared |
---|
763 | |
---|
764 | Static and DLL libraries can't both be built, since certain export |
---|
765 | directives in `gmp.h' must be different. `--enable-cxx' cannot be |
---|
766 | used when building a DLL, since libtool doesn't currently support |
---|
767 | C++ DLLs. This might change in the future. |
---|
768 | |
---|
769 | Microsoft C |
---|
770 | A MINGW DLL build of GMP can be used with Microsoft C. Libtool |
---|
771 | doesn't install `.lib' and `.exp' files, but they can be created |
---|
772 | with the following commands, where `/my/inst/dir' is the install |
---|
773 | directory (with a `lib' subdirectory). |
---|
774 | |
---|
775 | lib /machine:IX86 /def:_libs/libgmp-3.dll-def |
---|
776 | cp libgmp-3.lib /my/inst/dir/lib |
---|
777 | cp _libs/libgmp-3.dll-exp /my/inst/dir/lib/libgmp-3.exp |
---|
778 | |
---|
779 | MINGW uses `msvcrt.dll' for I/O, so applications wanting to use |
---|
780 | the GMP I/O routines must be compiled with `cl /MD' to do the |
---|
781 | same. If one of the other I/O choices provided by MS C is desired |
---|
782 | then the suggestion is to use the GMP string functions and confine |
---|
783 | I/O to the application. |
---|
784 | |
---|
785 | Motorola 68k CPU Types |
---|
786 | `m68k' is taken to mean 68000. `m68020' or higher will give a |
---|
787 | performance boost on applicable CPUs. `m68360' can be used for |
---|
788 | CPU32 series chips. `m68302' can be used for "Dragonball" series |
---|
789 | chips, though this is merely a synonym for `m68000'. |
---|
790 | |
---|
791 | OpenBSD 2.6 |
---|
792 | `m4' in this release of OpenBSD has a bug in `eval' that makes it |
---|
793 | unsuitable for `.asm' file processing. `./configure' will detect |
---|
794 | the problem and either abort or choose another m4 in the `PATH'. |
---|
795 | The bug is fixed in OpenBSD 2.7, so either upgrade or use GNU m4. |
---|
796 | |
---|
797 | Power CPU Types |
---|
798 | In GMP, CPU types `power*' and `powerpc*' will each use |
---|
799 | instructions not available on the other, so it's important to |
---|
800 | choose the right one for the CPU that will be used. Currently GMP |
---|
801 | has no assembler code support for using just the common |
---|
802 | instruction subset. To get executables that run on both, the |
---|
803 | current suggestion is to use the generic C code (CPU `none'), |
---|
804 | possibly with appropriate compiler options (like `-mcpu=common' for |
---|
805 | `gcc'). CPU `rs6000' (which is not a CPU but a family of |
---|
806 | workstations) is accepted by `config.sub', but is currently |
---|
807 | equivalent to `none'. |
---|
808 | |
---|
809 | Sparc CPU Types |
---|
810 | `sparcv8' or `supersparc' on relevant systems will give a |
---|
811 | significant performance increase over the V7 code. |
---|
812 | |
---|
813 | SunOS 4 |
---|
814 | `/usr/bin/m4' lacks various features needed to process `.asm' |
---|
815 | files, and instead `./configure' will automatically use |
---|
816 | `/usr/5bin/m4', which we believe is always available (if not then |
---|
817 | use GNU m4). |
---|
818 | |
---|
819 | x86 CPU Types |
---|
820 | `i386' selects generic code which will run reasonably well on all |
---|
821 | x86 chips. |
---|
822 | |
---|
823 | `i586', `pentium' or `pentiummmx' code is good for the intended P5 |
---|
824 | Pentium chips, but quite slow when run on Intel P6 class chips |
---|
825 | (PPro, P-II, P-III). `i386' is a better choice when making |
---|
826 | binaries that must run on both. |
---|
827 | |
---|
828 | `pentium4' and an SSE2 capable assembler are important for best |
---|
829 | results on Pentium 4. The specific code is for instance roughly a |
---|
830 | 2x to 3x speedup over the generic `i386' code. |
---|
831 | |
---|
832 | x86 MMX and SSE2 Code |
---|
833 | If the CPU selected has MMX code but the assembler doesn't support |
---|
834 | it, a warning is given and non-MMX code is used instead. This |
---|
835 | will be an inferior build, since the MMX code that's present is |
---|
836 | there because it's faster than the corresponding plain integer |
---|
837 | code. The same applies to SSE2. |
---|
838 | |
---|
839 | Old versions of `gas' don't support MMX instructions, in particular |
---|
840 | version 1.92.3 that comes with FreeBSD 2.2.8 doesn't (and |
---|
841 | unfortunately there's no newer assembler for that system). |
---|
842 | |
---|
843 | Solaris 2.6 and 2.7 `as' generate incorrect object code for |
---|
844 | register to register `movq' instructions, and so can't be used for |
---|
845 | MMX code. Install a recent `gas' if MMX code is wanted on these |
---|
846 | systems. |
---|
847 | |
---|
848 | |
---|
849 | File: gmp.info, Node: Known Build Problems, Prev: Notes for Particular Systems, Up: Installing GMP |
---|
850 | |
---|
851 | Known Build Problems |
---|
852 | ==================== |
---|
853 | |
---|
854 | You might find more up-to-date information at `http://swox.com/gmp/'. |
---|
855 | |
---|
856 | DJGPP |
---|
857 | The DJGPP port of `bash' 2.03 is unable to run the `configure' |
---|
858 | script, it exits silently, having died writing a preamble to |
---|
859 | `config.log'. Use `bash' 2.04 or higher. |
---|
860 | |
---|
861 | `make all' was found to run out of memory during the final |
---|
862 | `libgmp.la' link on one system tested, despite having 64Mb |
---|
863 | available. A separate `make libgmp.la' helped, perhaps recursing |
---|
864 | into the various subdirectories uses up memory. |
---|
865 | |
---|
866 | `DESTDIR' and shared `libgmpxx' |
---|
867 | `make install DESTDIR=/my/staging/area', or the same with a |
---|
868 | `prefix' override, to install to a temporary directory is not |
---|
869 | fully supported by current versions of libtool when building a |
---|
870 | shared version of a library which depends on another being built |
---|
871 | at the same time, like `libgmpxx' and `libgmp'. |
---|
872 | |
---|
873 | The problem is that `libgmpxx' is relinked at the install stage to |
---|
874 | ensure that if the system puts a hard-coded path to `libgmp' within |
---|
875 | `libgmpxx' then that path will be correct. Naturally the linker is |
---|
876 | directed to look only at the final location, not the staging area, |
---|
877 | so if `libgmp' is not already in that final location then the link |
---|
878 | will fail. |
---|
879 | |
---|
880 | A workaround for this on SVR4 style systems, such as GNU/Linux, |
---|
881 | where paths are not hard-coded, is to include the staging area in |
---|
882 | the linker's search using `LD_LIBRARY_PATH'. For example with |
---|
883 | `--prefix=/usr' but installing under `/my/staging/area', |
---|
884 | |
---|
885 | LD_LIBRARY_PATH=/my/staging/area/usr/lib \ |
---|
886 | make install DESTDIR=/my/staging/area |
---|
887 | |
---|
888 | GNU binutils `strip' prior to 2.12 |
---|
889 | `strip' from GNU binutils 2.11 and earlier should not be used on |
---|
890 | the static libraries `libgmp.a' and `libmp.a' since it will |
---|
891 | discard all but the last of multiple archive members with the same |
---|
892 | name, like the three versions of `init.o' in `libgmp.a'. Binutils |
---|
893 | 2.12 or higher can be used successfully. |
---|
894 | |
---|
895 | The shared libraries `libgmp.so' and `libmp.so' are not affected by |
---|
896 | this and any version of `strip' can be used on them. |
---|
897 | |
---|
898 | `make' syntax error |
---|
899 | On certain versions of SCO OpenServer 5 and IRIX 6.5 the native |
---|
900 | `make' is unable to handle the long dependencies list for |
---|
901 | `libgmp.la'. The symptom is a "syntax error" on the following |
---|
902 | line of the top-level `Makefile'. |
---|
903 | |
---|
904 | libgmp.la: $(libgmp_la_OBJECTS) $(libgmp_la_DEPENDENCIES) |
---|
905 | |
---|
906 | Either use GNU Make, or as a workaround remove |
---|
907 | `$(libgmp_la_DEPENDENCIES)' from that line (which will make the |
---|
908 | initial build work, but if any recompiling is done `libgmp.la' |
---|
909 | might not be rebuilt). |
---|
910 | |
---|
911 | MacOS X and GCC |
---|
912 | Libtool currently only knows how to create shared libraries on |
---|
913 | MacOS X using the native `cc' (which is a modified GCC), not a |
---|
914 | plain GCC. A static-only build should work though |
---|
915 | (`--disable-shared'). |
---|
916 | |
---|
917 | Also, libtool currently cannot build C++ shared libraries on MacOS |
---|
918 | X, so if `--enable-cxx' is desired then `--disable-shared' must be |
---|
919 | used. Hopefully this will be fixed in the future. |
---|
920 | |
---|
921 | NeXT prior to 3.3 |
---|
922 | The system compiler on old versions of NeXT was a massacred and |
---|
923 | old GCC, even if it called itself `cc'. This compiler cannot be |
---|
924 | used to build GMP, you need to get a real GCC, and install that. |
---|
925 | (NeXT may have fixed this in release 3.3 of their system.) |
---|
926 | |
---|
927 | POWER and PowerPC |
---|
928 | Bugs in GCC 2.7.2 (and 2.6.3) mean it can't be used to compile GMP |
---|
929 | on POWER or PowerPC. If you want to use GCC for these machines, |
---|
930 | get GCC 2.7.2.1 (or later). |
---|
931 | |
---|
932 | Sequent Symmetry |
---|
933 | Use the GNU assembler instead of the system assembler, since the |
---|
934 | latter has serious bugs. |
---|
935 | |
---|
936 | Solaris 2.6 |
---|
937 | The system `sed' prints an error "Output line too long" when |
---|
938 | libtool builds `libgmp.la'. This doesn't seem to cause any |
---|
939 | obvious ill effects, but GNU `sed' is recommended, to avoid any |
---|
940 | doubt. |
---|
941 | |
---|
942 | Sparc Solaris 2.7 with gcc 2.95.2 in ABI=32 |
---|
943 | A shared library build of GMP seems to fail in this combination, |
---|
944 | it builds but then fails the tests, apparently due to some |
---|
945 | incorrect data relocations within `gmp_randinit_lc_2exp_size'. |
---|
946 | The exact cause is unknown, `--disable-shared' is recommended. |
---|
947 | |
---|
948 | Windows DLL test programs |
---|
949 | When creating a DLL version of `libgmp', libtool creates wrapper |
---|
950 | scripts like `t-mul' for programs that would normally be |
---|
951 | `t-mul.exe', in order to setup the right library paths etc. This |
---|
952 | works fine, but the absence of `t-mul.exe' etc causes `make' to |
---|
953 | think they need recompiling every time, which is an annoyance when |
---|
954 | re-running a `make check'. |
---|
955 | |
---|
956 | |
---|
957 | File: gmp.info, Node: GMP Basics, Next: Reporting Bugs, Prev: Installing GMP, Up: Top |
---|
958 | |
---|
959 | GMP Basics |
---|
960 | ********** |
---|
961 | |
---|
962 | *Using functions, macros, data types, etc. not documented in this |
---|
963 | manual is strongly discouraged. If you do so your application is |
---|
964 | guaranteed to be incompatible with future versions of GMP.* |
---|
965 | |
---|
966 | * Menu: |
---|
967 | |
---|
968 | * Headers and Libraries:: |
---|
969 | * Nomenclature and Types:: |
---|
970 | * Function Classes:: |
---|
971 | * Variable Conventions:: |
---|
972 | * Parameter Conventions:: |
---|
973 | * Memory Management:: |
---|
974 | * Reentrancy:: |
---|
975 | * Useful Macros and Constants:: |
---|
976 | * Compatibility with older versions:: |
---|
977 | * Demonstration Programs:: |
---|
978 | * Efficiency:: |
---|
979 | * Debugging:: |
---|
980 | * Profiling:: |
---|
981 | * Autoconf:: |
---|
982 | * Emacs:: |
---|
983 | |
---|
984 | |
---|
985 | File: gmp.info, Node: Headers and Libraries, Next: Nomenclature and Types, Prev: GMP Basics, Up: GMP Basics |
---|
986 | |
---|
987 | Headers and Libraries |
---|
988 | ===================== |
---|
989 | |
---|
990 | All declarations needed to use GMP are collected in the include file |
---|
991 | `gmp.h'. It is designed to work with both C and C++ compilers. |
---|
992 | |
---|
993 | #include <gmp.h> |
---|
994 | |
---|
995 | Note however that prototypes for GMP functions with `FILE *' |
---|
996 | parameters are only provided if `<stdio.h>' is included too. |
---|
997 | |
---|
998 | #include <stdio.h> |
---|
999 | #include <gmp.h> |
---|
1000 | |
---|
1001 | Likewise `<stdarg.h>' (or `<varargs.h>') is required for prototypes |
---|
1002 | with `va_list' parameters, such as `gmp_vprintf'. And `<obstack.h>' |
---|
1003 | for prototypes with `struct obstack' parameters, such as |
---|
1004 | `gmp_obstack_printf', when available. |
---|
1005 | |
---|
1006 | All programs using GMP must link against the `libgmp' library. On a |
---|
1007 | typical Unix-like system this can be done with `-lgmp', for example |
---|
1008 | |
---|
1009 | gcc myprogram.c -lgmp |
---|
1010 | |
---|
1011 | GMP C++ functions are in a separate `libgmpxx' library. This is |
---|
1012 | built and installed if C++ support has been enabled (*note Build |
---|
1013 | Options::). For example, |
---|
1014 | |
---|
1015 | g++ mycxxprog.cc -lgmpxx -lgmp |
---|
1016 | |
---|
1017 | GMP is built using Libtool and an application can use that to link |
---|
1018 | if desired, *note Shared library support for GNU: (libtool)Top. |
---|
1019 | |
---|
1020 | If GMP has been installed to a non-standard location then it may be |
---|
1021 | necessary to use `-I' and `-L' compiler options to point to the right |
---|
1022 | directories, and some sort of run-time path for a shared library. |
---|
1023 | Consult your compiler documentation, for instance *Note Introduction: |
---|
1024 | (gcc)Top. |
---|
1025 | |
---|
1026 | |
---|
1027 | File: gmp.info, Node: Nomenclature and Types, Next: Function Classes, Prev: Headers and Libraries, Up: GMP Basics |
---|
1028 | |
---|
1029 | Nomenclature and Types |
---|
1030 | ====================== |
---|
1031 | |
---|
1032 | In this manual, "integer" usually means a multiple precision integer, as |
---|
1033 | defined by the GMP library. The C data type for such integers is |
---|
1034 | `mpz_t'. Here are some examples of how to declare such integers: |
---|
1035 | |
---|
1036 | mpz_t sum; |
---|
1037 | |
---|
1038 | struct foo { mpz_t x, y; }; |
---|
1039 | |
---|
1040 | mpz_t vec[20]; |
---|
1041 | |
---|
1042 | "Rational number" means a multiple precision fraction. The C data type |
---|
1043 | for these fractions is `mpq_t'. For example: |
---|
1044 | |
---|
1045 | mpq_t quotient; |
---|
1046 | |
---|
1047 | "Floating point number" or "Float" for short, is an arbitrary precision |
---|
1048 | mantissa with a limited precision exponent. The C data type for such |
---|
1049 | objects is `mpf_t'. |
---|
1050 | |
---|
1051 | A "limb" means the part of a multi-precision number that fits in a |
---|
1052 | single machine word. (We chose this word because a limb of the human |
---|
1053 | body is analogous to a digit, only larger, and containing several |
---|
1054 | digits.) Normally a limb is 32 or 64 bits. The C data type for a limb |
---|
1055 | is `mp_limb_t'. |
---|
1056 | |
---|
1057 | |
---|
1058 | File: gmp.info, Node: Function Classes, Next: Variable Conventions, Prev: Nomenclature and Types, Up: GMP Basics |
---|
1059 | |
---|
1060 | Function Classes |
---|
1061 | ================ |
---|
1062 | |
---|
1063 | There are six classes of functions in the GMP library: |
---|
1064 | |
---|
1065 | 1. Functions for signed integer arithmetic, with names beginning with |
---|
1066 | `mpz_'. The associated type is `mpz_t'. There are about 150 |
---|
1067 | functions in this class. |
---|
1068 | |
---|
1069 | 2. Functions for rational number arithmetic, with names beginning with |
---|
1070 | `mpq_'. The associated type is `mpq_t'. There are about 40 |
---|
1071 | functions in this class, but the integer functions can be used for |
---|
1072 | arithmetic on the numerator and denominator separately. |
---|
1073 | |
---|
1074 | 3. Functions for floating-point arithmetic, with names beginning with |
---|
1075 | `mpf_'. The associated type is `mpf_t'. There are about 60 |
---|
1076 | functions is this class. |
---|
1077 | |
---|
1078 | 4. Functions compatible with Berkeley MP, such as `itom', `madd', and |
---|
1079 | `mult'. The associated type is `MINT'. |
---|
1080 | |
---|
1081 | 5. Fast low-level functions that operate on natural numbers. These |
---|
1082 | are used by the functions in the preceding groups, and you can |
---|
1083 | also call them directly from very time-critical user programs. |
---|
1084 | These functions' names begin with `mpn_'. The associated type is |
---|
1085 | array of `mp_limb_t'. There are about 30 (hard-to-use) functions |
---|
1086 | in this class. |
---|
1087 | |
---|
1088 | 6. Miscellaneous functions. Functions for setting up custom |
---|
1089 | allocation and functions for generating random numbers. |
---|
1090 | |
---|
1091 | |
---|
1092 | File: gmp.info, Node: Variable Conventions, Next: Parameter Conventions, Prev: Function Classes, Up: GMP Basics |
---|
1093 | |
---|
1094 | Variable Conventions |
---|
1095 | ==================== |
---|
1096 | |
---|
1097 | GMP functions generally have output arguments before input |
---|
1098 | arguments. This notation is by analogy with the assignment operator. |
---|
1099 | The BSD MP compatibility functions are exceptions, having the output |
---|
1100 | arguments last. |
---|
1101 | |
---|
1102 | GMP lets you use the same variable for both input and output in one |
---|
1103 | call. For example, the main function for integer multiplication, |
---|
1104 | `mpz_mul', can be used to square `x' and put the result back in `x' with |
---|
1105 | |
---|
1106 | mpz_mul (x, x, x); |
---|
1107 | |
---|
1108 | Before you can assign to a GMP variable, you need to initialize it |
---|
1109 | by calling one of the special initialization functions. When you're |
---|
1110 | done with a variable, you need to clear it out, using one of the |
---|
1111 | functions for that purpose. Which function to use depends on the type |
---|
1112 | of variable. See the chapters on integer functions, rational number |
---|
1113 | functions, and floating-point functions for details. |
---|
1114 | |
---|
1115 | A variable should only be initialized once, or at least cleared |
---|
1116 | between each initialization. After a variable has been initialized, it |
---|
1117 | may be assigned to any number of times. |
---|
1118 | |
---|
1119 | For efficiency reasons, avoid excessive initializing and clearing. |
---|
1120 | In general, initialize near the start of a function and clear near the |
---|
1121 | end. For example, |
---|
1122 | |
---|
1123 | void |
---|
1124 | foo (void) |
---|
1125 | { |
---|
1126 | mpz_t n; |
---|
1127 | int i; |
---|
1128 | mpz_init (n); |
---|
1129 | for (i = 1; i < 100; i++) |
---|
1130 | { |
---|
1131 | mpz_mul (n, ...); |
---|
1132 | mpz_fdiv_q (n, ...); |
---|
1133 | ... |
---|
1134 | } |
---|
1135 | mpz_clear (n); |
---|
1136 | } |
---|
1137 | |
---|
1138 | |
---|
1139 | File: gmp.info, Node: Parameter Conventions, Next: Memory Management, Prev: Variable Conventions, Up: GMP Basics |
---|
1140 | |
---|
1141 | Parameter Conventions |
---|
1142 | ===================== |
---|
1143 | |
---|
1144 | When a GMP variable is used as a function parameter, it's |
---|
1145 | effectively a call-by-reference, meaning if the function stores a value |
---|
1146 | there it will change the original in the caller. Parameters which are |
---|
1147 | input-only can be designated `const' to provoke a compiler error or |
---|
1148 | warning on attempting to modify them. |
---|
1149 | |
---|
1150 | When a function is going to return a GMP result, it should designate |
---|
1151 | a parameter that it sets, like the library functions do. More than one |
---|
1152 | value can be returned by having more than one output parameter, again |
---|
1153 | like the library functions. A `return' of an `mpz_t' etc doesn't |
---|
1154 | return the object, only a pointer, and this is almost certainly not |
---|
1155 | what's wanted. |
---|
1156 | |
---|
1157 | Here's an example accepting an `mpz_t' parameter, doing a |
---|
1158 | calculation, and storing the result to the indicated parameter. |
---|
1159 | |
---|
1160 | void |
---|
1161 | foo (mpz_t result, const mpz_t param, unsigned long n) |
---|
1162 | { |
---|
1163 | unsigned long i; |
---|
1164 | mpz_mul_ui (result, param, n); |
---|
1165 | for (i = 1; i < n; i++) |
---|
1166 | mpz_add_ui (result, result, i*7); |
---|
1167 | } |
---|
1168 | |
---|
1169 | int |
---|
1170 | main (void) |
---|
1171 | { |
---|
1172 | mpz_t r, n; |
---|
1173 | mpz_init (r); |
---|
1174 | mpz_init_set_str (n, "123456", 0); |
---|
1175 | foo (r, n, 20L); |
---|
1176 | gmp_printf ("%Zd\n", r); |
---|
1177 | return 0; |
---|
1178 | } |
---|
1179 | |
---|
1180 | `foo' works even if the mainline passes the same variable for |
---|
1181 | `param' and `result', just like the library functions. But sometimes |
---|
1182 | it's tricky to make that work, and an application might not want to |
---|
1183 | bother supporting that sort of thing. |
---|
1184 | |
---|
1185 | For interest, the GMP types `mpz_t' etc are implemented as |
---|
1186 | one-element arrays of certain structures. This is why declaring a |
---|
1187 | variable creates an object with the fields GMP needs, but then using it |
---|
1188 | as a parameter passes a pointer to the object. Note that the actual |
---|
1189 | fields in each `mpz_t' etc are for internal use only and should not be |
---|
1190 | accessed directly by code that expects to be compatible with future GMP |
---|
1191 | releases. |
---|
1192 | |
---|
1193 | |
---|
1194 | File: gmp.info, Node: Memory Management, Next: Reentrancy, Prev: Parameter Conventions, Up: GMP Basics |
---|
1195 | |
---|
1196 | Memory Management |
---|
1197 | ================= |
---|
1198 | |
---|
1199 | The GMP types like `mpz_t' are small, containing only a couple of |
---|
1200 | sizes, and pointers to allocated data. Once a variable is initialized, |
---|
1201 | GMP takes care of all space allocation. Additional space is allocated |
---|
1202 | whenever a variable doesn't have enough. |
---|
1203 | |
---|
1204 | `mpz_t' and `mpq_t' variables never reduce their allocated space. |
---|
1205 | Normally this is the best policy, since it avoids frequent reallocation. |
---|
1206 | Applications that need to return memory to the heap at some particular |
---|
1207 | point can use `mpz_realloc2', or clear variables no longer needed. |
---|
1208 | |
---|
1209 | `mpf_t' variables, in the current implementation, use a fixed amount |
---|
1210 | of space, determined by the chosen precision and allocated at |
---|
1211 | initialization, so their size doesn't change. |
---|
1212 | |
---|
1213 | All memory is allocated using `malloc' and friends by default, but |
---|
1214 | this can be changed, see *Note Custom Allocation::. Temporary memory |
---|
1215 | on the stack is also used (via `alloca'), but this can be changed at |
---|
1216 | build-time if desired, see *Note Build Options::. |
---|
1217 | |
---|