codegen: use gen_frame_store for for bswap and brev
[ajla.git] / mini-gmp.h
blobb586f011eb743fe05514ff67839741d1923fa0d7
1 /* mini-gmp, a minimalistic implementation of a GNU GMP subset.
3 Copyright 2011-2015, 2017, 2019-2020 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of either:
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.
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.
20 or both in parallel, as here.
22 The GNU MP Library is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 for more details.
27 You should have received copies of the GNU General Public License and the
28 GNU Lesser General Public License along with the GNU MP Library. If not,
29 see https://www.gnu.org/licenses/. */
31 /* Modified by Mikulas Patocka to fit in Ajla */
33 /* About mini-gmp: This is a minimal implementation of a subset of the
34 GMP interface. It is intended for inclusion into applications which
35 have modest bignums needs, as a fallback when the real GMP library
36 is not installed.
38 This file defines the public interface. */
40 #ifndef AJLA_MINI_GMP_H
41 #define AJLA_MINI_GMP_H
43 #ifndef MPINT_GMP
45 void mp_set_memory_functions (void *(*) (size_t),
46 void *(*) (void *, size_t, size_t),
47 void (*) (void *, size_t));
49 #ifndef MINI_GMP_LIMB_TYPE
50 #define MINI_GMP_LIMB_TYPE long
51 #endif
53 typedef unsigned MINI_GMP_LIMB_TYPE mp_limb_t;
54 typedef long mp_size_t;
55 typedef unsigned long mp_bitcnt_t;
57 typedef mp_limb_t *mp_ptr;
58 typedef const mp_limb_t *mp_srcptr;
60 #define GMP_NUMB_BITS (sizeof(mp_limb_t) * 8)
62 typedef struct
64 int _mp_alloc; /* Number of *limbs* allocated and pointed
65 to by the _mp_d field. */
66 int _mp_size; /* abs(_mp_size) is the number of limbs the
67 last field points to. If _mp_size is
68 negative this is a negative number. */
69 mp_limb_t *_mp_d; /* Pointer to the limbs. */
70 } __mpz_struct;
72 typedef __mpz_struct MP_INT;
74 typedef __mpz_struct mpz_t[1];
76 typedef __mpz_struct *mpz_ptr;
77 typedef const __mpz_struct *mpz_srcptr;
79 extern const int mp_bits_per_limb;
81 mp_bitcnt_t mpn_scan1 (mp_srcptr, mp_bitcnt_t);
83 #define mpn_invert_limb(x) mpn_invert_3by2 ((x), 0)
85 void mpz_init (mpz_t);
86 void mpz_init2 (mpz_t, mp_bitcnt_t);
87 void mpz_clear (mpz_t);
89 #define mpz_odd_p(z) (((z)->_mp_size != 0) & (int) (z)->_mp_d[0])
90 #define mpz_even_p(z) (! mpz_odd_p (z))
92 int mpz_sgn (const mpz_t);
93 int mpz_cmp (const mpz_t, const mpz_t);
95 void mpz_neg (mpz_t, const mpz_t);
97 void mpz_add_ui (mpz_t, const mpz_t, unsigned long);
98 void mpz_add (mpz_t, const mpz_t, const mpz_t);
99 void mpz_sub_ui (mpz_t, const mpz_t, unsigned long);
100 void mpz_sub (mpz_t, const mpz_t, const mpz_t);
102 void mpz_mul (mpz_t, const mpz_t, const mpz_t);
103 void mpz_mul_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
105 void mpz_tdiv_q (mpz_t, const mpz_t, const mpz_t);
106 void mpz_tdiv_r (mpz_t, const mpz_t, const mpz_t);
108 void mpz_fdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
109 void mpz_tdiv_q_2exp (mpz_t, const mpz_t, mp_bitcnt_t);
111 int mpz_tstbit (const mpz_t, mp_bitcnt_t);
112 void mpz_setbit (mpz_t, mp_bitcnt_t);
113 void mpz_clrbit (mpz_t, mp_bitcnt_t);
115 void mpz_com (mpz_t, const mpz_t);
116 void mpz_and (mpz_t, const mpz_t, const mpz_t);
117 void mpz_ior (mpz_t, const mpz_t, const mpz_t);
118 void mpz_xor (mpz_t, const mpz_t, const mpz_t);
120 mp_bitcnt_t mpz_popcount (const mpz_t);
121 mp_bitcnt_t mpz_scan1 (const mpz_t, mp_bitcnt_t);
123 int mpz_fits_slong_p (const mpz_t);
124 int mpz_fits_ulong_p (const mpz_t);
125 long int mpz_get_si (const mpz_t);
126 unsigned long int mpz_get_ui (const mpz_t);
127 size_t mpz_size (const mpz_t);
129 #define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }}
131 void mpz_set_si (mpz_t, signed long int);
132 void mpz_set_ui (mpz_t, unsigned long int);
133 void mpz_set (mpz_t, const mpz_t);
135 void mpz_init_set_si (mpz_t, signed long int);
136 void mpz_init_set (mpz_t, const mpz_t);
138 size_t mpz_sizeinbase (const mpz_t, int);
140 void mpz_import (mpz_t, size_t, int, size_t, int, size_t, const void *);
141 void *mpz_export (void *, size_t *, int, size_t, int, size_t, const mpz_t);
143 #endif
145 #endif /* AJLA_MINI_GMP_H */