1 From 04ac00a8126a0b328e231e01ab4b257b28c5da3c Mon Sep 17 00:00:00 2001
2 From: Paolo Bonzini <bonzini@gnu.org>
3 Date: Fri, 8 Jan 2010 16:00:36 +0100
4 Subject: [PATCH] hack to build with GMP 5
7 2010-01-08 Paolo Bonzini <bonzini@gnu.org>
9 * libgst/mpz.c: Hack to build with GMP 5.
11 libgst/ChangeLog | 4 ++++
12 libgst/mpz.c | 20 ++++++++++++++++++--
13 2 files changed, 22 insertions(+), 2 deletions(-)
15 diff --git a/libgst/mpz.c b/libgst/mpz.c
16 index eaee0e8..d8e8b6b 100644
19 @@ -1513,13 +1513,21 @@ _gst_mpz_xor (gst_mpz *res, const gst_mpz *op1, const gst_mpz *op2)
23 +#if __GNU_MP_VERSION >= 5
24 +extern void __gmpn_divexact (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t);
28 _gst_mpz_divexact (gst_mpz *quot, const gst_mpz *num, const gst_mpz *den)
33 - mp_size_t nsize, dsize, qsize, d_zero_limbs;
34 + mp_size_t nsize, dsize, qsize;
35 +#if __GNU_MP_VERSION < 5
37 + mp_size_t d_zero_limbs;
41 nsize = ABS (num->size);
42 dsize = ABS (den->size);
43 @@ -1542,6 +1550,7 @@ _gst_mpz_divexact (gst_mpz *quot, const gst_mpz *num, const gst_mpz *den)
47 +#if __GNU_MP_VERSION < 5
48 /* Avoid quadratic behaviour, but do it conservatively. */
49 if (nsize - dsize > 1500)
51 @@ -1560,6 +1569,7 @@ _gst_mpz_divexact (gst_mpz *quot, const gst_mpz *num, const gst_mpz *den)
52 dsize -= d_zero_limbs;
54 nsize -= d_zero_limbs;
57 /* Allocate where we place the result. It must be nsize limbs big
58 because it also acts as a temporary area. */
59 @@ -1567,6 +1577,7 @@ _gst_mpz_divexact (gst_mpz *quot, const gst_mpz *num, const gst_mpz *den)
60 gst_mpz_realloc (quot, nsize);
63 +#if __GNU_MP_VERSION < 5
66 tp = (mp_ptr) alloca (dsize * SIZEOF_MP_LIMB_T);
67 @@ -1579,9 +1590,14 @@ _gst_mpz_divexact (gst_mpz *quot, const gst_mpz *num, const gst_mpz *den)
70 MPN_COPY(qp, np, nsize);
73 qsize = nsize - dsize + 1;
74 +#if __GNU_MP_VERSION < 5
75 mpn_bdivmod (qp, qp, nsize, dp, dsize, qsize * GMP_NUMB_BITS);
77 + __gmpn_divexact (qp, np, nsize, dp, dsize);
79 quot->size = (num->size ^ den->size) >= 0 ? qsize : -qsize;