Debian Codegraph @

doc/guide/src/GMP.adoc

raw
1 = GMP
2
3 The https://gmplib.org[GMP] library (GNU Multiple Precision
4 arithmetic library) is a library for arbitrary precision integer
5 arithmetic. MLton uses the GMP library to implement the
6 <<BasisLibrary#,Basis Library>> `IntInf` module.
7
8 == Known issues
9
10 * There is a known problem with the GMP library (prior to version
11 4.2.x), where it requires a lot of stack space for some computations,
12 e.g. `IntInf.toString` of a million digit number. If you run with
13 stack size limited, you may see a segfault in such programs. This
14 problem is mentioned in the https://gmplib.org/#FAQ[GMP FAQ], where
15 they describe two solutions.
16
17 ** Increase (or unlimit) your stack space. From your program, use
18 `setrlimit`, or from the shell, use `ulimit`.
19
20 ** Configure and rebuild `libgmp` with `--disable-alloca`, which will
21 cause it to allocate temporaries using `malloc` instead of on the
22 stack.
23
24 * On some platforms, the GMP library may be configured to use one of
25 multiple ABIs (Application Binary Interfaces). For example, on some
26 32-bit architectures, GMP may be configured to represent a limb as
27 either a 32-bit `long` or as a 64-bit `long long`. Similarly, GMP
28 may be configured to use specific CPU features.
29 +
30 In order to efficiently use the GMP library, MLton represents an
31 `IntInf.int` value in a manner compatible with the GMP library's
32 representation of a limb. Hence, it is important that MLton and the
33 GMP library agree upon the representation of a limb.
34
35 ** When using a source package of MLton, building will detect the
36 GMP library's representation of a limb.
37
38 ** When using a binary package of MLton that is dynamically linked
39 against the GMP library, the build machine and the install machine
40 must have the GMP library configured with the same representation of
41 a limb. (On the other hand, the build machine need not have the GMP
42 library configured with CPU features compatible with the install
43 machine.)
44
45 ** When using a binary package of MLton that is statically linked
46 against the GMP library, the build machine and the install machine
47 need not have the GMP library configured with the same
48 representation of a limb. (On the other hand, the build machine must
49 have the GMP library configured with CPU features compatible with
50 the install machine.)
51 +
52 However, MLton will be configured with the representation of a limb
53 from the GMP library of the build machine. Executables produced by
54 MLton will be incompatible with the GMP library of the install
55 machine. To _reconfigure_ MLton with the representation of a limb
56 from the GMP library of the install machine, one must edit:
57 +
58 ----
59 /usr/lib/mlton/self/sizes
60 ----
61 +
62 changing the
63 +
64 ----
65 mplimb = ??
66 ----
67 +
68 entry so that `??` corresponds to the bytes in a limb; and, one must edit:
69 +
70 ----
71 /usr/lib/mlton/sml/basis/config/c/arch-os/c-types.sml
72 ----
73 +
74 changing the
75 +
76 ----
77 (* from "gmp.h" *)
78 structure C_MPLimb = struct open Word?? type t = word end
79 functor C_MPLimb_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word?? (A)
80 ----
81 +
82 entries so that `??` corresponds to the bits in a limb.