Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / guide / localhost / GnuMP
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta name="generator" content="AsciiDoc 8.6.9">
6 <title>GnuMP</title>
7 <link rel="stylesheet" href="./asciidoc.css" type="text/css">
8 <link rel="stylesheet" href="./pygments.css" type="text/css">
9
10
11 <script type="text/javascript" src="./asciidoc.js"></script>
12 <script type="text/javascript">
13 /*<![CDATA[*/
14 asciidoc.install();
15 /*]]>*/
16 </script>
17 <link rel="stylesheet" href="./mlton.css" type="text/css">
18 </head>
19 <body class="article">
20 <div id="banner">
21 <div id="banner-home">
22 <a href="./Home">MLton 20180207</a>
23 </div>
24 </div>
25 <div id="header">
26 <h1>GnuMP</h1>
27 </div>
28 <div id="content">
29 <div id="preamble">
30 <div class="sectionbody">
31 <div class="paragraph"><p>The <a href="http://gmplib.org">GnuMP</a> library (GNU Multiple Precision
32 arithmetic library) is a library for arbitrary precision integer
33 arithmetic. MLton uses the GnuMP library to implement the
34 <a href="BasisLibrary"> Basis Library</a> <span class="monospaced">IntInf</span> module.</p></div>
35 </div>
36 </div>
37 <div class="sect1">
38 <h2 id="_known_issues">Known issues</h2>
39 <div class="sectionbody">
40 <div class="ulist"><ul>
41 <li>
42 <p>
43 There is a known problem with the GnuMP library (prior to version
44 4.2.x), where it requires a lot of stack space for some computations,
45 e.g. <span class="monospaced">IntInf.toString</span> of a million digit number. If you run with
46 stack size limited, you may see a segfault in such programs. This
47 problem is mentioned in the <a href="http://gmplib.org/#FAQ">GnuMP FAQ</a>, where
48 they describe two solutions.
49 </p>
50 <div class="ulist"><ul>
51 <li>
52 <p>
53 Increase (or unlimit) your stack space. From your program, use
54 <span class="monospaced">setrlimit</span>, or from the shell, use <span class="monospaced">ulimit</span>.
55 </p>
56 </li>
57 <li>
58 <p>
59 Configure and rebuild <span class="monospaced">libgmp</span> with <span class="monospaced">--disable-alloca</span>, which will
60 cause it to allocate temporaries using <span class="monospaced">malloc</span> instead of on the
61 stack.
62 </p>
63 </li>
64 </ul></div>
65 </li>
66 <li>
67 <p>
68 On some platforms, the GnuMP library may be configured to use one of
69 multiple ABIs (Application Binary Interfaces). For example, on some
70 32-bit architectures, GnuMP may be configured to represent a limb as
71 either a 32-bit <span class="monospaced">long</span> or as a 64-bit <span class="monospaced">long long</span>. Similarly, GnuMP
72 may be configured to use specific CPU features.
73 </p>
74 <div class="paragraph"><p>In order to efficiently use the GnuMP library, MLton represents an
75 <span class="monospaced">IntInf.int</span> value in a manner compatible with the GnuMP library&#8217;s
76 representation of a limb. Hence, it is important that MLton and the
77 GnuMP library agree upon the representation of a limb.</p></div>
78 <div class="ulist"><ul>
79 <li>
80 <p>
81 When using a source package of MLton, building will detect the
82 GnuMP library&#8217;s representation of a limb.
83 </p>
84 </li>
85 <li>
86 <p>
87 When using a binary package of MLton that is dynamically linked
88 against the GnuMP library, the build machine and the install machine
89 must have the GnuMP library configured with the same representation of
90 a limb. (On the other hand, the build machine need not have the GnuMP
91 library configured with CPU features compatible with the install
92 machine.)
93 </p>
94 </li>
95 <li>
96 <p>
97 When using a binary package of MLton that is statically linked
98 against the GnuMP library, the build machine and the install machine
99 need not have the GnuMP library configured with the same
100 representation of a limb. (On the other hand, the build machine must
101 have the GnuMP library configured with CPU features compatible with
102 the install machine.)
103 </p>
104 <div class="paragraph"><p>However, MLton will be configured with the representation of a limb
105 from the GnuMP library of the build machine. Executables produced by
106 MLton will be incompatible with the GnuMP library of the install
107 machine. To <em>reconfigure</em> MLton with the representation of a limb
108 from the GnuMP library of the install machine, one must edit:</p></div>
109 <div class="listingblock">
110 <div class="content monospaced">
111 <pre>/usr/lib/mlton/self/sizes</pre>
112 </div></div>
113 <div class="paragraph"><p>changing the</p></div>
114 <div class="listingblock">
115 <div class="content monospaced">
116 <pre>mplimb = ??</pre>
117 </div></div>
118 <div class="paragraph"><p>entry so that <span class="monospaced">??</span> corresponds to the bytes in a limb; and, one must edit:</p></div>
119 <div class="listingblock">
120 <div class="content monospaced">
121 <pre>/usr/lib/mlton/sml/basis/config/c/arch-os/c-types.sml</pre>
122 </div></div>
123 <div class="paragraph"><p>changing the</p></div>
124 <div class="listingblock">
125 <div class="content monospaced">
126 <pre>(* from "gmp.h" *)
127 structure C_MPLimb = struct open Word?? type t = word end
128 functor C_MPLimb_ChooseWordN (A: CHOOSE_WORDN_ARG) = ChooseWordN_Word?? (A)</pre>
129 </div></div>
130 <div class="paragraph"><p>entries so that <span class="monospaced">??</span> corresponds to the bits in a limb.</p></div>
131 </li>
132 </ul></div>
133 </li>
134 </ul></div>
135 </div>
136 </div>
137 </div>
138 <div id="footnotes"><hr></div>
139 <div id="footer">
140 <div id="footer-text">
141 </div>
142 <div id="footer-badges">
143 </div>
144 </div>
145 </body>
146 </html>