Skip to content

Commit

Permalink
Merge pull request #1969 from albinahlback/remove_gmp_h
Browse files Browse the repository at this point in the history
Remove inclusion of `gmp.h` and `limits.h` in `flint.h`
  • Loading branch information
albinahlback committed May 13, 2024
2 parents b85628c + f988e2d commit f535972
Show file tree
Hide file tree
Showing 1,377 changed files with 7,315 additions and 7,683 deletions.
3 changes: 3 additions & 0 deletions CMake/cmake_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

#cmakedefine01 FLINT_KNOW_STRONG_ORDER

#cmakedefine FLINT_BITS @FLINT_BITS@
#cmakedefine01 FLINT_LONG_LONG

/* NOTE: Here we assume this is how it works. */
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
# define HAVE__ALIGNED_MALLOC 1
Expand Down
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,18 @@ check_c_source_compiles([[#include <gmp.h>
#ifndef _LONG_LONG_LIMB
# error mp_limb_t != unsigned long long limb
#endif
void main(){};]] LONG_LONG_LIMB)
void main(){};]] FLINT_LONG_LONG)

if(LONG_LONG_LIMB)
set(ULONG "unsigned long long int")
set(SLONG "long long int")
check_c_source_compiles([[#include <gmp.h>
#if GMP_LIMB_BITS == 32
# error
#endif
void main(){};]] FLINT64)

if(FLINT64)
set(FLINT_BITS 64)
else()
set(ULONG "unsigned long int")
set(SLONG "long int")
set(FLINT_BITS 32)
endif()

# Populate headers
Expand All @@ -345,7 +349,7 @@ configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/fmpz/fmpz.c
COPYONLY
)
if(LONG_LONG_LIMB)
if(FLINT_LONG_LONG)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/gmpcompat-longlong.h.in
${CMAKE_CURRENT_SOURCE_DIR}/src/gmpcompat.h
Expand Down
18 changes: 9 additions & 9 deletions code_conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ the following primitive datatype should be used:
| | |
|:--------------------------------------:|:------------------------------:|
| bit counts up to a single limb | `ulong` |
| bit counts, multiprecision | `mp_bitcnt_t` |
| bit counts, multiprecision | `flint_bitcnt_t` |
| byte counts (strings) | `size_t` |
| limb counts in multiprecision integers | `mp_size_t` |
| limbs (unsigned/signed) | `mp_limb_t`/`mp_limb_signed_t` |
| `mp_limb_t` arrays | `mp_ptr`/`mp_srcptr` |
| limb counts in multiprecision integers | `slong` |
| limbs (unsigned/signed) | `ulong`/`slong` |
| `ulong` arrays | `nn_ptr`/`nn_srcptr` |
| ui/si function constants | `ulong`/`slong` |
| exponents (unsigned/signed) | `ulong`/`slong` |
| polynomial lengths | `slong` |
Expand All @@ -43,11 +43,11 @@ The typical definitions of these in terms of primitive types are:

| | |
|:-------------:|:---------------------------------------:|
| `mp_bitcnt_t` | `unsigned long` or `unsigned long long` |
| `mp_size_t` | `long` or `long long` |
| `mp_limb_t` | `unsigned long` or `unsigned long long` |
| `mp_ptr` | `mp_limb_t *` |
| `mp_srcptr` | `const mp_limb_t *` |
| `flint_bitcnt_t` | `unsigned long` or `unsigned long long` |
| `slong` | `long` or `long long` |
| `ulong` | `unsigned long` or `unsigned long long` |
| `nn_ptr` | `ulong *` |
| `nn_srcptr` | `const ulong *` |
| `slong` | `long` or `long long` |
| `ulong` | `unsigned long` or `unsigned long long` |

Expand Down
7 changes: 7 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,11 @@ FLINT_GMP_LONG_LONG_LIMB([SLONG="long long int"
AC_SUBST(SLONG)
AC_SUBST(ULONG)

if test "$flint_cv_gmp_long_long_limb" = "yes";
then
AC_DEFINE(FLINT_LONG_LONG,1,[Define to use long long limbs])
fi

AC_CONFIG_LINKS([src/gmpcompat.h:src/$gmpcompat_h_in],[],[gmpcompat_h_in="$gmpcompat_h_in"])
AC_SUBST(GMPCOMPAT_H_IN, $gmpcompat_h_in)

Expand All @@ -951,6 +956,8 @@ FLINT_CHECK_MPFR_H(4,1,0)

FLINT_ABI

AC_DEFINE_UNQUOTED(FLINT_BITS,$flint_cv_abi,[Define according to the ABI FLINT was compiled with])

################################################################################
# check headers
################################################################################
Expand Down
28 changes: 14 additions & 14 deletions dev/gen_mul_basecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"""
Generic version of mul_n:
void flint_mpn_mul_n_basecase(mp_ptr res, mp_srcptr u, mp_srcptr v, mp_size_t n)
void flint_mpn_mul_n_basecase(nn_ptr res, nn_srcptr u, nn_srcptr v, slong n)
{
mp_limb_t b, a;
ulong b, a;
slong i;
NN_MUL_1X1(a, res[0], u[0], v[0]);
Expand All @@ -40,9 +40,9 @@
"""

def mul1v(n):
print("mp_limb_t flint_mpn_mul_%i_1v(mp_ptr res, mp_srcptr u, mp_limb_t v0)" % n)
print("ulong flint_mpn_mul_%i_1v(nn_ptr res, nn_srcptr u, ulong v0)" % n)
print("{")
print(" mp_limb_t a;")
print(" ulong a;")
print(" NN_MUL_1X1(a, res[0], u[0], v0);")
for i in range(1, n-1):
print(" NN_ADDMUL_S2_A2_1X1(a, res[%i], 0, a, u[%i], v0);" % (i, i))
Expand All @@ -52,20 +52,20 @@ def mul1v(n):

def mulnm(n, m):
if m == 1:
print("mp_limb_t flint_mpn_mul_%i_1(mp_ptr res, mp_srcptr u, mp_srcptr v)" % n)
print("ulong flint_mpn_mul_%i_1(nn_ptr res, nn_srcptr u, nn_srcptr v)" % n)
print("{")
print(" mp_limb_t a, v0 = v[0];")
print(" ulong a, v0 = v[0];")
print(" NN_MUL_1X1(a, res[0], u[0], v0);")
for i in range(1, n-1):
print(" NN_ADDMUL_S2_A2_1X1(a, res[%i], 0, a, u[%i], v0);" % (i, i))
print(" NN_ADDMUL_S2_A2_1X1(res[%i], res[%i], 0, a, u[%i], v0);" % (n, n - 1, n - 1))
print(" return res[%i];" % n)
print("}")
elif m == 2:
print("mp_limb_t flint_mpn_mul_%i_%i(mp_ptr res, mp_srcptr u, mp_srcptr v)" % (n, m))
print("ulong flint_mpn_mul_%i_%i(nn_ptr res, nn_srcptr u, nn_srcptr v)" % (n, m))
print("{")
print(" mp_limb_t b, a;")
print(" mp_limb_t w[2];")
print(" ulong b, a;")
print(" ulong w[2];")
print(" w[0] = v[0];")
print(" w[1] = v[1];")
print(" NN_MUL_1X1(a, res[0], u[0], w[0]);")
Expand All @@ -80,9 +80,9 @@ def mulnm(n, m):
print(" return res[%i];" % (n + m - 1))
print("}")
else:
print("mp_limb_t flint_mpn_mul_%i_%i(mp_ptr res, mp_srcptr u, mp_srcptr v)" % (n, m))
print("ulong flint_mpn_mul_%i_%i(nn_ptr res, nn_srcptr u, nn_srcptr v)" % (n, m))
print("{")
print(" mp_limb_t b, a;")
print(" ulong b, a;")
print(" NN_MUL_1X1(a, res[0], u[0], v[0]);")
print(" NN_DOTREV_S3_A3_1X1(b, a, res[1], 0, 0, a, u, v, 2);")
for i in range(2, m):
Expand All @@ -98,7 +98,7 @@ def mulnm(n, m):
for n in range(2, 8):
for m in range(1, n+1):
if n >= 8 and m >= 5:
print("void flint_mpn_mul_%i_%i(mp_ptr res, mp_srcptr u, mp_srcptr v)" % (n, m))
print("void flint_mpn_mul_%i_%i(nn_ptr res, nn_srcptr u, nn_srcptr v)" % (n, m))
print("{")
print(" __gmpn_mul_basecase(res, u, %i, v, %i);" % (n, m))
print("}")
Expand All @@ -114,9 +114,9 @@ def mulnm(n, m):
#print()

def mulhigh_n(n):
print("mp_limb_t flint_mpn_mulhigh_%i_generic(mp_ptr res, mp_srcptr u, mp_srcptr v)" % n)
print("ulong flint_mpn_mulhigh_%i_generic(nn_ptr res, nn_srcptr u, nn_srcptr v)" % n)
print("{")
print(" mp_limb_t b, a, low;")
print(" ulong b, a, low;")
print(" NN_DOTREV_S3_1X1_HIGH(b, a, u, v, %i);" % (n - 1))
print(" NN_DOTREV_S3_A3_1X1(b, a, low, 0, b, a, u, v, %i);" % n)
for i in range(n - 2):
Expand Down
16 changes: 8 additions & 8 deletions doc/source/arb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1649,9 +1649,9 @@ Other special functions
Internals for computing elementary functions
-------------------------------------------------------------------------------

.. function:: void _arb_atan_taylor_naive(mp_ptr y, mp_limb_t * error, mp_srcptr x, mp_size_t xn, ulong N, int alternating)
.. function:: void _arb_atan_taylor_naive(nn_ptr y, ulong * error, nn_srcptr x, slong xn, ulong N, int alternating)

.. function:: void _arb_atan_taylor_rs(mp_ptr y, mp_limb_t * error, mp_srcptr x, mp_size_t xn, ulong N, int alternating)
.. function:: void _arb_atan_taylor_rs(nn_ptr y, ulong * error, nn_srcptr x, slong xn, ulong N, int alternating)

Computes an approximation of `y = \sum_{k=0}^{N-1} x^{2k+1} / (2k+1)`
(if *alternating* is 0) or `y = \sum_{k=0}^{N-1} (-1)^k x^{2k+1} / (2k+1)`
Expand All @@ -1663,9 +1663,9 @@ Internals for computing elementary functions
The input *x* and output *y* are fixed-point numbers with *xn* fractional
limbs. A bound for the ulp error is written to *error*.

.. function:: void _arb_exp_taylor_naive(mp_ptr y, mp_limb_t * error, mp_srcptr x, mp_size_t xn, ulong N)
.. function:: void _arb_exp_taylor_naive(nn_ptr y, ulong * error, nn_srcptr x, slong xn, ulong N)

.. function:: void _arb_exp_taylor_rs(mp_ptr y, mp_limb_t * error, mp_srcptr x, mp_size_t xn, ulong N)
.. function:: void _arb_exp_taylor_rs(nn_ptr y, ulong * error, nn_srcptr x, slong xn, ulong N)

Computes an approximation of `y = \sum_{k=0}^{N-1} x^k / k!`. Used internally
for computing exponentials. The *naive* version uses the forward recurrence,
Expand All @@ -1678,9 +1678,9 @@ Internals for computing elementary functions

A bound for the ulp error is written to *error*.

.. function:: void _arb_sin_cos_taylor_naive(mp_ptr ysin, mp_ptr ycos, mp_limb_t * error, mp_srcptr x, mp_size_t xn, ulong N)
.. function:: void _arb_sin_cos_taylor_naive(nn_ptr ysin, nn_ptr ycos, ulong * error, nn_srcptr x, slong xn, ulong N)

.. function:: void _arb_sin_cos_taylor_rs(mp_ptr ysin, mp_ptr ycos, mp_limb_t * error, mp_srcptr x, mp_size_t xn, ulong N, int sinonly, int alternating)
.. function:: void _arb_sin_cos_taylor_rs(nn_ptr ysin, nn_ptr ycos, ulong * error, nn_srcptr x, slong xn, ulong N, int sinonly, int alternating)

Computes approximations of `y_s = \sum_{k=0}^{N-1} (-1)^k x^{2k+1} / (2k+1)!`
and `y_c = \sum_{k=0}^{N-1} (-1)^k x^{2k} / (2k)!`.
Expand All @@ -1698,13 +1698,13 @@ Internals for computing elementary functions
the hyperbolic sine is computed (this is currently only intended to
be used together with *sinonly*).

.. function:: int _arb_get_mpn_fixed_mod_log2(mp_ptr w, fmpz_t q, mp_limb_t * error, const arf_t x, mp_size_t wn)
.. function:: int _arb_get_mpn_fixed_mod_log2(nn_ptr w, fmpz_t q, ulong * error, const arf_t x, slong wn)

Attempts to write `w = x - q \log(2)` with `0 \le w < \log(2)`, where *w*
is a fixed-point number with *wn* limbs and ulp error *error*.
Returns success.

.. function:: int _arb_get_mpn_fixed_mod_pi4(mp_ptr w, fmpz_t q, int * octant, mp_limb_t * error, const arf_t x, mp_size_t wn)
.. function:: int _arb_get_mpn_fixed_mod_pi4(nn_ptr w, fmpz_t q, int * octant, ulong * error, const arf_t x, slong wn)

Attempts to write `w = |x| - q \pi/4` with `0 \le w < \pi/4`, where *w*
is a fixed-point number with *wn* limbs and ulp error *error*.
Expand Down
8 changes: 4 additions & 4 deletions doc/source/arf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ Complex arithmetic
Low-level methods
-------------------------------------------------------------------------------

.. function:: int _arf_get_integer_mpn(mp_ptr y, mp_srcptr xp, mp_size_t xn, slong exp)
.. function:: int _arf_get_integer_mpn(nn_ptr y, nn_srcptr xp, slong xn, slong exp)

Given a floating-point number *x* represented by *xn* limbs at *xp*
and an exponent *exp*, writes the integer part of *x* to
Expand All @@ -741,7 +741,7 @@ Low-level methods
Assumes that ``xp[0]`` is nonzero and that the
top bit of ``xp[xn-1]`` is set.

.. function:: int _arf_set_mpn_fixed(arf_t z, mp_srcptr xp, mp_size_t xn, mp_size_t fixn, int negative, slong prec, arf_rnd_t rnd)
.. function:: int _arf_set_mpn_fixed(arf_t z, nn_srcptr xp, slong xn, slong fixn, int negative, slong prec, arf_rnd_t rnd)

Sets *z* to the fixed-point number having *xn* total limbs and *fixn*
fractional limbs, negated if *negative* is set, rounding *z* to *prec*
Expand All @@ -755,15 +755,15 @@ Low-level methods
Sets *z* to the integer *x*, negated if *sgnbit* is 1, rounded to *prec*
bits in the direction specified by *rnd*. There are no assumptions on *x*.

.. function:: int _arf_set_round_uiui(arf_t z, slong * fix, mp_limb_t hi, mp_limb_t lo, int sgnbit, slong prec, arf_rnd_t rnd)
.. function:: int _arf_set_round_uiui(arf_t z, slong * fix, ulong hi, ulong lo, int sgnbit, slong prec, arf_rnd_t rnd)

Sets the mantissa of *z* to the two-limb mantissa given by *hi* and *lo*,
negated if *sgnbit* is 1, rounded to *prec* bits in the direction specified
by *rnd*. Requires that not both *hi* and *lo* are zero.
Writes the exponent shift to *fix* without writing the exponent of *z*
directly.

.. function:: int _arf_set_round_mpn(arf_t z, slong * exp_shift, mp_srcptr x, mp_size_t xn, int sgnbit, slong prec, arf_rnd_t rnd)
.. function:: int _arf_set_round_mpn(arf_t z, slong * exp_shift, nn_srcptr x, slong xn, int sgnbit, slong prec, arf_rnd_t rnd)

Sets the mantissa of *z* to the mantissa given by the *xn* limbs in *x*,
negated if *sgnbit* is 1, rounded to *prec* bits in the direction
Expand Down
14 changes: 7 additions & 7 deletions doc/source/arith.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Bell numbers
running in time `O(n^2 \log^{O(1)} n)`. The default version
chooses an algorithm automatically.

.. function:: mp_limb_t arith_bell_number_nmod(ulong n, nmod_t mod)
.. function:: ulong arith_bell_number_nmod(ulong n, nmod_t mod)

Computes the Bell number `B_n` modulo an integer given by ``mod``.

Expand All @@ -170,10 +170,10 @@ Bell numbers
calling ``arith_bell_number_nmod_vec`` and reading the last
coefficient.

.. function:: void arith_bell_number_nmod_vec(mp_ptr b, slong n, nmod_t mod)
void arith_bell_number_nmod_vec_recursive(mp_ptr b, slong n, nmod_t mod)
void arith_bell_number_nmod_vec_ogf(mp_ptr b, slong n, nmod_t mod)
int arith_bell_number_nmod_vec_series(mp_ptr b, slong n, nmod_t mod)
.. function:: void arith_bell_number_nmod_vec(nn_ptr b, slong n, nmod_t mod)
void arith_bell_number_nmod_vec_recursive(nn_ptr b, slong n, nmod_t mod)
void arith_bell_number_nmod_vec_ogf(nn_ptr b, slong n, nmod_t mod)
int arith_bell_number_nmod_vec_series(nn_ptr b, slong n, nmod_t mod)

Sets `b` to the vector of Bell numbers `B_0, B_1, \ldots, B_{n-1}`
inclusive modulo an integer given by ``mod``.
Expand Down Expand Up @@ -433,7 +433,7 @@ Number of partitions
Computes first ``len`` values of the partition function `p(n)`
starting with `p(0)`. Uses inversion of Euler's pentagonal series.

.. function:: void arith_number_of_partitions_nmod_vec(mp_ptr res, slong len, nmod_t mod)
.. function:: void arith_number_of_partitions_nmod_vec(nn_ptr res, slong len, nmod_t mod)

Computes first ``len`` values of the partition function `p(n)`
starting with `p(0)`, modulo the modulus defined by ``mod``.
Expand All @@ -443,7 +443,7 @@ Number of partitions

Initializes ``prod``. This is an inline function only.

.. function:: void arith_hrr_expsum_factored(trig_prod_t prod, mp_limb_t k, mp_limb_t n)
.. function:: void arith_hrr_expsum_factored(trig_prod_t prod, ulong k, ulong n)

Symbolically evaluates the exponential sum

Expand Down
4 changes: 2 additions & 2 deletions doc/source/fft_small.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Integer multiplication
frees the cache.

.. function:: void mpn_ctx_mpn_mul(mpn_ctx_t R, ulong * r1, const ulong * i1, ulong n1, const ulong * i2, ulong n2)
void mpn_mul_default_mpn_ctx(mp_ptr r1, mp_srcptr i1, mp_size_t n1, mp_srcptr i2, mp_size_t n2)
void mpn_mul_default_mpn_ctx(nn_ptr r1, nn_srcptr i1, slong n1, nn_srcptr i2, slong n2)

Writes to ``r1`` the product of the integers ``(i1, n1)`` and ``(i2, n2)``.
Assumes that `n_1 \ge n_2 \ge 1`, respectively using a given context
Expand All @@ -41,7 +41,7 @@ Polynomial arithmetic
---------------------------------------------------------------------------------

.. function:: void _nmod_poly_mul_mid_mpn_ctx(ulong * z, ulong zl, ulong zh, const ulong * a, ulong an, const ulong * b, ulong bn, nmod_t mod, mpn_ctx_t R)
void _nmod_poly_mul_mid_default_mpn_ctx(mp_ptr res, slong zl, slong zh, mp_srcptr a, slong an, mp_srcptr b, slong bn, nmod_t mod)
void _nmod_poly_mul_mid_default_mpn_ctx(nn_ptr res, slong zl, slong zh, nn_srcptr a, slong an, nn_srcptr b, slong bn, nmod_t mod)

Writes to ``z`` the middle product containing coefficients in the
range `[zl, zh)` of the product of the polynomials ``(a, an)`` and ``(b, bn)``,
Expand Down
Loading

0 comments on commit f535972

Please sign in to comment.