]> Git Repo - VerusCoin.git/blame - src/mini-gmp.h
Set vrsctest rewards to 12 to match mainnet
[VerusCoin.git] / src / mini-gmp.h
CommitLineData
d019c447 1/* mini-gmp, a minimalistic implementation of a GNU GMP subset.
2
3Copyright 2011-2015 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library.
6
7The GNU MP Library is free software; you can redistribute it and/or modify
8it under the terms of either:
9
10 * the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
13
14or
15
16 * the GNU General Public License as published by the Free Software
17 Foundation; either version 2 of the License, or (at your option) any
18 later version.
19
20or both in parallel, as here.
21
22The GNU MP Library is distributed in the hope that it will be useful, but
23WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25for more details.
26
27You should have received copies of the GNU General Public License and the
28GNU Lesser General Public License along with the GNU MP Library. If not,
29see https://www.gnu.org/licenses/. */
30
31/* About mini-gmp: This is a minimal implementation of a subset of the
32 GMP interface. It is intended for inclusion into applications which
33 have modest bignums needs, as a fallback when the real GMP library
34 is not installed.
35
36 This file defines the public interface. */
37
38#ifndef __MINI_GMP_H__
39#define __MINI_GMP_H__
40
41/* For size_t */
42#include <stddef.h>
43#include <limits.h>
44#include <stdint.h>
45
46#if defined (__cplusplus)
47extern "C" {
48#endif
49
50void mp_set_memory_functions (void *(*) (size_t),
51 void *(*) (void *, size_t, size_t),
52 void (*) (void *, size_t));
53
54void mp_get_memory_functions (void *(**) (size_t),
55 void *(**) (void *, size_t, size_t),
56 void (**) (void *, size_t));
57
58typedef uint64_t mp_limb_t;
59typedef int64_t mp_size_t;
60typedef uint64_t mp_bitcnt_t;
61
62typedef mp_limb_t *mp_ptr;
63typedef const mp_limb_t *mp_srcptr;
64
65typedef struct
66{
67 int32_t _mp_alloc; /* Number of *limbs* allocated and pointed
68 to by the _mp_d field. */
69 int32_t _mp_size; /* abs(_mp_size) is the number of limbs the
70 last field points to. If _mp_size is
71 negative this is a negative number. */
72 mp_limb_t *_mp_d; /* Pointer to the limbs. */
73} __mpz_struct;
74
75typedef __mpz_struct mpz_t[1];
76
77typedef __mpz_struct *mpz_ptr;
78typedef const __mpz_struct *mpz_srcptr;
79
80extern const int32_t mp_bits_per_limb;
81
82void mpn_copyi (mp_ptr, mp_srcptr, mp_size_t);
83void mpn_copyd (mp_ptr, mp_srcptr, mp_size_t);
84void mpn_zero (mp_ptr, mp_size_t);
85
86int32_t mpn_cmp (mp_srcptr, mp_srcptr, mp_size_t);
87int32_t mpn_zero_p (mp_srcptr, mp_size_t);
88
89mp_limb_t mpn_add_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
90mp_limb_t mpn_add_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
91mp_limb_t mpn_add (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
92
93mp_limb_t mpn_sub_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
94mp_limb_t mpn_sub_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
95mp_limb_t mpn_sub (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
96
97mp_limb_t mpn_mul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
98mp_limb_t mpn_addmul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
99mp_limb_t mpn_submul_1 (mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);
100
101mp_limb_t mpn_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
102void mpn_mul_n (mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
103void mpn_sqr (mp_ptr, mp_srcptr, mp_size_t);
104int32_t mpn_perfect_square_p (mp_srcptr, mp_size_t);
105mp_size_t mpn_sqrtrem (mp_ptr, mp_ptr, mp_srcptr, mp_size_t);
106
107mp_limb_t mpn_lshift (mp_ptr, mp_srcptr, mp_size_t, uint32_t);
108mp_limb_t mpn_rshift (mp_ptr, mp_srcptr, mp_size_t, uint32_t);
109
110mp_bitcnt_t mpn_scan0 (mp_srcptr, mp_bitcnt_t);
111mp_bitcnt_t mpn_scan1 (mp_srcptr, mp_bitcnt_t);
112
113mp_bitcnt_t mpn_popcount (mp_srcptr, mp_size_t);
114
115mp_limb_t mpn_invert_3by2 (mp_limb_t, mp_limb_t);
116#define mpn_invert_limb(x) mpn_invert_3by2 ((x), 0)
117
118size_t mpn_get_str (uint8_t *, int32_t, mp_ptr, mp_size_t);
119mp_size_t mpn_set_str (mp_ptr, const uint8_t *, size_t, int32_t);
120
121void mpz_init (mpz_t);
122void mpz_init2 (mpz_t, mp_bitcnt_t);
123void mpz_clear (mpz_t);
124
125#define mpz_odd_p(z) (((z)->_mp_size != 0) & (int32_t) (z)->_mp_d[0])
126#define mpz_even_p(z) (! mpz_odd_p (z))
127
128int32_t mpz_sgn (const mpz_t);
129int32_t mpz_cmp_si (const mpz_t, int64_t);
130int32_t mpz_cmp_ui (const mpz_t, uint64_t);
131int32_t mpz_cmp (const mpz_t, const mpz_t);
132int32_t mpz_cmpabs_ui (const mpz_t, uint64_t);
133int32_t mpz_cmpabs (const mpz_t, const mpz_t);
134int32_t mpz_cmp_d (const mpz_t, double);
135int32_t mpz_cmpabs_d (const mpz_t, double);
136
137void mpz_abs (mpz_t, const mpz_t);
138void mpz_neg (mpz_t, const mpz_t);
139void mpz_swap (mpz_t, mpz_t);
140
141void mpz_add_ui (mpz_t, const mpz_t, uint64_t);
142void mpz_add (mpz_t, const mpz_t, const mpz_t);
143void mpz_sub_ui (mpz_t, const mpz_t, uint64_t);
144void mpz_ui_sub (mpz_t, uint64_t, const mpz_t);
145void mpz_sub (mpz_t, const mpz_t, const mpz_t);
146
147void mpz_mul_si (mpz_t, const mpz_t, int64_t);
148void mpz_mul_ui (mpz_t, const mpz_t, uint64_t);
149void mpz_mul (mpz_t, const mpz_t, const mpz_t);
150void mpz_mul_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
151void mpz_addmul_ui (mpz_t, const mpz_t, uint64_t);
152void mpz_addmul (mpz_t, const mpz_t, const mpz_t);
153void mpz_submul_ui (mpz_t, const mpz_t, uint64_t);
154void mpz_submul (mpz_t, const mpz_t, const mpz_t);
155
156void mpz_cdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t);
157void mpz_fdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t);
158void mpz_tdiv_qr (mpz_t, mpz_t, const mpz_t, const mpz_t);
159void mpz_cdiv_q (mpz_t, const mpz_t, const mpz_t);
160void mpz_fdiv_q (mpz_t, const mpz_t, const mpz_t);
161void mpz_tdiv_q (mpz_t, const mpz_t, const mpz_t);
162void mpz_cdiv_r (mpz_t, const mpz_t, const mpz_t);
163void mpz_fdiv_r (mpz_t, const mpz_t, const mpz_t);
164void mpz_tdiv_r (mpz_t, const mpz_t, const mpz_t);
165
166void mpz_cdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
167void mpz_fdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
168void mpz_tdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
169void mpz_cdiv_r_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
170void mpz_fdiv_r_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
171void mpz_tdiv_r_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
172
173void mpz_mod (mpz_t, const mpz_t, const mpz_t);
174
175void mpz_divexact (mpz_t, const mpz_t, const mpz_t);
176
177int32_t mpz_divisible_p (const mpz_t, const mpz_t);
178int32_t mpz_congruent_p (const mpz_t, const mpz_t, const mpz_t);
179
180uint64_t mpz_cdiv_qr_ui (mpz_t, mpz_t, const mpz_t, uint64_t);
181uint64_t mpz_fdiv_qr_ui (mpz_t, mpz_t, const mpz_t, uint64_t);
182uint64_t mpz_tdiv_qr_ui (mpz_t, mpz_t, const mpz_t, uint64_t);
183uint64_t mpz_cdiv_q_ui (mpz_t, const mpz_t, uint64_t);
184uint64_t mpz_fdiv_q_ui (mpz_t, const mpz_t, uint64_t);
185uint64_t mpz_tdiv_q_ui (mpz_t, const mpz_t, uint64_t);
186uint64_t mpz_cdiv_r_ui (mpz_t, const mpz_t, uint64_t);
187uint64_t mpz_fdiv_r_ui (mpz_t, const mpz_t, uint64_t);
188uint64_t mpz_tdiv_r_ui (mpz_t, const mpz_t, uint64_t);
189uint64_t mpz_cdiv_ui (const mpz_t, uint64_t);
190uint64_t mpz_fdiv_ui (const mpz_t, uint64_t);
191uint64_t mpz_tdiv_ui (const mpz_t, uint64_t);
192
193uint64_t mpz_mod_ui (mpz_t, const mpz_t, uint64_t);
194
195void mpz_divexact_ui (mpz_t, const mpz_t, uint64_t);
196
197int32_t mpz_divisible_ui_p (const mpz_t, uint64_t);
198
199uint64_t mpz_gcd_ui (mpz_t, const mpz_t, uint64_t);
200void mpz_gcd (mpz_t, const mpz_t, const mpz_t);
201void mpz_gcdext (mpz_t, mpz_t, mpz_t, const mpz_t, const mpz_t);
202void mpz_lcm_ui (mpz_t, const mpz_t, uint64_t);
203void mpz_lcm (mpz_t, const mpz_t, const mpz_t);
204int32_t mpz_invert (mpz_t, const mpz_t, const mpz_t);
205
206void mpz_sqrtrem (mpz_t, mpz_t, const mpz_t);
207void mpz_sqrt (mpz_t, const mpz_t);
208int32_t mpz_perfect_square_p (const mpz_t);
209
210void mpz_pow_ui (mpz_t, const mpz_t, uint64_t);
211void mpz_ui_pow_ui (mpz_t, uint64_t, uint64_t);
212void mpz_powm (mpz_t, const mpz_t, const mpz_t, const mpz_t);
213void mpz_powm_ui (mpz_t, const mpz_t, uint64_t, const mpz_t);
214
215void mpz_rootrem (mpz_t, mpz_t, const mpz_t, uint64_t);
216int32_t mpz_root (mpz_t, const mpz_t, uint64_t);
217
218void mpz_fac_ui (mpz_t, uint64_t);
219void mpz_bin_uiui (mpz_t, uint64_t, uint64_t);
220
221int32_t mpz_probab_prime_p (const mpz_t, int32_t);
222
223int32_t mpz_tstbit (const mpz_t, mp_bitcnt_t);
224void mpz_setbit (mpz_t, mp_bitcnt_t);
225void mpz_clrbit (mpz_t, mp_bitcnt_t);
226void mpz_combit (mpz_t, mp_bitcnt_t);
227
228void mpz_com (mpz_t, const mpz_t);
229void mpz_and (mpz_t, const mpz_t, const mpz_t);
230void mpz_ior (mpz_t, const mpz_t, const mpz_t);
231void mpz_xor (mpz_t, const mpz_t, const mpz_t);
232
233mp_bitcnt_t mpz_popcount (const mpz_t);
234mp_bitcnt_t mpz_hamdist (const mpz_t, const mpz_t);
235mp_bitcnt_t mpz_scan0 (const mpz_t, mp_bitcnt_t);
236mp_bitcnt_t mpz_scan1 (const mpz_t, mp_bitcnt_t);
237
238int32_t mpz_fits_slong_p (const mpz_t);
239int32_t mpz_fits_ulong_p (const mpz_t);
240int64_t mpz_get_si (const mpz_t);
241uint64_t mpz_get_ui (const mpz_t);
242double mpz_get_d (const mpz_t);
243size_t mpz_size (const mpz_t);
244mp_limb_t mpz_getlimbn (const mpz_t, mp_size_t);
245
246void mpz_realloc2 (mpz_t, mp_bitcnt_t);
247mp_srcptr mpz_limbs_read (mpz_srcptr);
248mp_ptr mpz_limbs_modify (mpz_t, mp_size_t);
249mp_ptr mpz_limbs_write (mpz_t, mp_size_t);
250void mpz_limbs_finish (mpz_t, mp_size_t);
251mpz_srcptr mpz_roinit_n (mpz_t, mp_srcptr, mp_size_t);
252
253#define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }}
254
255void mpz_set_si (mpz_t, int64_t);
256void mpz_set_ui (mpz_t, uint64_t);
257void mpz_set (mpz_t, const mpz_t);
258void mpz_set_d (mpz_t, double);
259
260void mpz_init_set_si (mpz_t, int64_t);
261void mpz_init_set_ui (mpz_t, uint64_t);
262void mpz_init_set (mpz_t, const mpz_t);
263void mpz_init_set_d (mpz_t, double);
264
265size_t mpz_sizeinbase (const mpz_t, int32_t);
266char *mpz_get_str (char *, int32_t, const mpz_t);
267int32_t mpz_set_str (mpz_t, const char *, int32_t);
268int32_t mpz_init_set_str (mpz_t, const char *, int32_t);
269
270/* This long list taken from gmp.h. */
271/* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4,
272 <iostream> defines EOF but not FILE. */
273#if defined (FILE) \
274 || defined (H_STDIO) \
275 || defined (_H_STDIO) /* AIX */ \
276 || defined (_STDIO_H) /* glibc, Sun, SCO */ \
277 || defined (_STDIO_H_) /* BSD, OSF */ \
278 || defined (__STDIO_H) /* Borland */ \
279 || defined (__STDIO_H__) /* IRIX */ \
280 || defined (_STDIO_INCLUDED) /* HPUX */ \
281 || defined (__dj_include_stdio_h_) /* DJGPP */ \
282 || defined (_FILE_DEFINED) /* Microsoft */ \
283 || defined (__STDIO__) /* Apple MPW MrC */ \
284 || defined (_MSL_STDIO_H) /* Metrowerks */ \
285 || defined (_STDIO_H_INCLUDED) /* QNX4 */ \
286 || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ \
287 || defined (__STDIO_LOADED) /* VMS */
288size_t mpz_out_str (FILE *, int32_t, const mpz_t);
289#endif
290
291void mpz_import (mpz_t, size_t, int32_t, size_t, int32_t, size_t, const void *);
292void *mpz_export (void *, size_t *, int32_t, size_t, int32_t, size_t, const mpz_t);
293#define GMP_LIMB_BITS (sizeof(mp_limb_t) * CHAR_BIT)
294#define GMP_NAIL_BITS 0
295#define GMP_NUMB_BITS (GMP_LIMB_BITS - GMP_NAIL_BITS)
296
297#if defined (__cplusplus)
298}
299#endif
300#endif /* __MINI_GMP_H__ */
This page took 0.214055 seconds and 4 git commands to generate.