[Gmp-commit] /var/hg/gmp: Use the macros ALLOC etc to access the fields of mp...
mercurial at gmplib.org
mercurial at gmplib.org
Thu Feb 23 21:17:51 CET 2012
details: /var/hg/gmp/rev/93ce1bb5430a
changeset: 14666:93ce1bb5430a
user: Marc Glisse <marc.glisse at inria.fr>
date: Thu Feb 23 21:17:47 2012 +0100
description:
Use the macros ALLOC etc to access the fields of mpz_t in mpz/*.
Test mpz_abs when it requires a reallocation.
diffstat:
ChangeLog | 38 ++++++++++++++++++++++++++++++++++++++
mpz/abs.c | 14 +++++++-------
mpz/aors_ui.h | 13 ++++++-------
mpz/array_init.c | 6 +++---
mpz/cdiv_q.c | 6 +++---
mpz/cdiv_qr.c | 6 +++---
mpz/cdiv_r.c | 4 ++--
mpz/clear.c | 2 +-
mpz/clrbit.c | 10 +++++-----
mpz/cmp_si.c | 4 ++--
mpz/com.c | 22 ++++++++++------------
mpz/fdiv_q.c | 6 +++---
mpz/fdiv_qr.c | 6 +++---
mpz/fdiv_r.c | 4 ++--
mpz/get_si.c | 4 ++--
mpz/get_str.c | 6 +++---
mpz/init.c | 8 ++++----
mpz/inp_str.c | 6 +++---
mpz/iset.c | 12 ++++++------
mpz/iset_d.c | 6 +++---
mpz/iset_si.c | 10 +++++-----
mpz/iset_str.c | 8 ++++----
mpz/iset_ui.c | 10 +++++-----
mpz/mod.c | 2 +-
mpz/neg.c | 11 +++++------
mpz/out_str.c | 4 ++--
mpz/random2.c | 7 +++----
mpz/set_si.c | 6 +++---
mpz/set_str.c | 6 +++---
mpz/set_ui.c | 6 +++---
mpz/setbit.c | 14 +++++++-------
mpz/sqrt.c | 18 +++++++++---------
mpz/swap.c | 24 ++++++++++++------------
mpz/tdiv_r_2exp.c | 19 ++++++++-----------
tests/cxx/t-ops.cc | 2 ++
35 files changed, 181 insertions(+), 149 deletions(-)
diffs (truncated from 974 to 300 lines):
diff -r dfb9b37bf1e7 -r 93ce1bb5430a ChangeLog
--- a/ChangeLog Thu Feb 23 16:56:19 2012 +0100
+++ b/ChangeLog Thu Feb 23 21:17:47 2012 +0100
@@ -1,3 +1,41 @@
+2012-02-23 Marc Glisse <marc.glisse at inria.fr>
+
+ * mpz/abs.c: Use ALLOC, SIZ, ABSIZ, PTR, MPZ_REALLOC.
+ * mpz/aors_ui.h: Likewise.
+ * mpz/array_init.c: Likewise.
+ * mpz/cdiv_q.c: Likewise.
+ * mpz/cdiv_qr.c: Likewise.
+ * mpz/cdiv_r.c: Likewise.
+ * mpz/clear.c: Likewise.
+ * mpz/clrbit.c: Likewise.
+ * mpz/cmp_si.c: Likewise.
+ * mpz/com.c: Likewise.
+ * mpz/fdiv_q.c: Likewise.
+ * mpz/fdiv_qr.c: Likewise.
+ * mpz/fdiv_r.c: Likewise.
+ * mpz/get_si.c: Likewise.
+ * mpz/get_str.c: Likewise.
+ * mpz/init.c: Likewise.
+ * mpz/inp_str.c: Likewise.
+ * mpz/iset.c: Likewise.
+ * mpz/iset_d.c: Likewise.
+ * mpz/iset_si.c: Likewise.
+ * mpz/iset_str.c: Likewise.
+ * mpz/iset_ui.c: Likewise.
+ * mpz/mod.c: Likewise.
+ * mpz/neg.c: Likewise.
+ * mpz/out_str.c: Likewise.
+ * mpz/random2.c: Likewise.
+ * mpz/set_si.c: Likewise.
+ * mpz/set_str.c: Likewise.
+ * mpz/set_ui.c: Likewise.
+ * mpz/setbit.c: Likewise.
+ * mpz/sqrt.c: Likewise.
+ * mpz/swap.c: Likewise.
+ * mpz/tdiv_r_2exp.c: Likewise.
+
+ * tests/cxx/t-ops.cc: Test mpz_abs reallocation.
+
2012-02-23 Torbjorn Granlund <tege at gmplib.org>
* mpn/x86_64/core2/rsh1aors_n.asm: Complete rewrite.
diff -r dfb9b37bf1e7 -r 93ce1bb5430a mpz/abs.c
--- a/mpz/abs.c Thu Feb 23 16:56:19 2012 +0100
+++ b/mpz/abs.c Thu Feb 23 21:17:47 2012 +0100
@@ -25,21 +25,21 @@
void
mpz_abs (mpz_ptr w, mpz_srcptr u)
{
- mp_ptr wp, up;
+ mp_ptr wp;
+ mp_srcptr up;
mp_size_t size;
- size = ABS (u->_mp_size);
+ size = ABSIZ (u);
if (u != w)
{
- if (w->_mp_alloc < size)
- _mpz_realloc (w, size);
+ MPZ_REALLOC (w, size);
- wp = w->_mp_d;
- up = u->_mp_d;
+ wp = PTR (w);
+ up = PTR (u);
MPN_COPY (wp, up, size);
}
- w->_mp_size = size;
+ SIZ (w) = size;
}
diff -r dfb9b37bf1e7 -r 93ce1bb5430a mpz/aors_ui.h
--- a/mpz/aors_ui.h Thu Feb 23 16:56:19 2012 +0100
+++ b/mpz/aors_ui.h Thu Feb 23 21:17:47 2012 +0100
@@ -66,22 +66,21 @@
}
#endif
- usize = u->_mp_size;
+ usize = SIZ (u);
abs_usize = ABS (usize);
/* If not space for W (and possible carry), increase space. */
wsize = abs_usize + 1;
- if (w->_mp_alloc < wsize)
- _mpz_realloc (w, wsize);
+ MPZ_REALLOC (w, wsize);
/* These must be after realloc (U may be the same as W). */
- up = u->_mp_d;
- wp = w->_mp_d;
+ up = PTR (u);
+ wp = PTR (w);
if (abs_usize == 0)
{
wp[0] = vval;
- w->_mp_size = VARIATION_NEG (vval != 0);
+ SIZ (w) = VARIATION_NEG (vval != 0);
return;
}
@@ -109,5 +108,5 @@
}
}
- w->_mp_size = wsize;
+ SIZ (w) = wsize;
}
diff -r dfb9b37bf1e7 -r 93ce1bb5430a mpz/array_init.c
--- a/mpz/array_init.c Thu Feb 23 16:56:19 2012 +0100
+++ b/mpz/array_init.c Thu Feb 23 21:17:47 2012 +0100
@@ -33,8 +33,8 @@
for (i = 0; i < arr_size; i++)
{
- arr[i]._mp_alloc = nlimbs + 1; /* Yes, lie a little... */
- arr[i]._mp_size = 0;
- arr[i]._mp_d = p + i * nlimbs;
+ ALLOC (&arr[i]) = nlimbs + 1; /* Yes, lie a little... */
+ SIZ (&arr[i]) = 0;
+ PTR (&arr[i]) = p + i * nlimbs;
}
}
diff -r dfb9b37bf1e7 -r 93ce1bb5430a mpz/cdiv_q.c
--- a/mpz/cdiv_q.c Thu Feb 23 16:56:19 2012 +0100
+++ b/mpz/cdiv_q.c Thu Feb 23 21:17:47 2012 +0100
@@ -24,8 +24,8 @@
void
mpz_cdiv_q (mpz_ptr quot, mpz_srcptr dividend, mpz_srcptr divisor)
{
- mp_size_t dividend_size = dividend->_mp_size;
- mp_size_t divisor_size = divisor->_mp_size;
+ mp_size_t dividend_size = SIZ (dividend);
+ mp_size_t divisor_size = SIZ (divisor);
mpz_t rem;
TMP_DECL;
@@ -35,7 +35,7 @@
mpz_tdiv_qr (quot, rem, dividend, divisor);
- if ((divisor_size ^ dividend_size) >= 0 && rem->_mp_size != 0)
+ if ((divisor_size ^ dividend_size) >= 0 && SIZ (rem) != 0)
mpz_add_ui (quot, quot, 1L);
TMP_FREE;
diff -r dfb9b37bf1e7 -r 93ce1bb5430a mpz/cdiv_qr.c
--- a/mpz/cdiv_qr.c Thu Feb 23 16:56:19 2012 +0100
+++ b/mpz/cdiv_qr.c Thu Feb 23 21:17:47 2012 +0100
@@ -24,7 +24,7 @@
void
mpz_cdiv_qr (mpz_ptr quot, mpz_ptr rem, mpz_srcptr dividend, mpz_srcptr divisor)
{
- mp_size_t divisor_size = divisor->_mp_size;
+ mp_size_t divisor_size = SIZ (divisor);
mp_size_t xsize;
mpz_t temp_divisor; /* N.B.: lives until function returns! */
TMP_DECL;
@@ -41,10 +41,10 @@
divisor = temp_divisor;
}
- xsize = dividend->_mp_size ^ divisor_size;;
+ xsize = SIZ (dividend) ^ divisor_size;;
mpz_tdiv_qr (quot, rem, dividend, divisor);
- if (xsize >= 0 && rem->_mp_size != 0)
+ if (xsize >= 0 && SIZ (rem) != 0)
{
mpz_add_ui (quot, quot, 1L);
mpz_sub (rem, rem, divisor);
diff -r dfb9b37bf1e7 -r 93ce1bb5430a mpz/cdiv_r.c
--- a/mpz/cdiv_r.c Thu Feb 23 16:56:19 2012 +0100
+++ b/mpz/cdiv_r.c Thu Feb 23 21:17:47 2012 +0100
@@ -24,7 +24,7 @@
void
mpz_cdiv_r (mpz_ptr rem, mpz_srcptr dividend, mpz_srcptr divisor)
{
- mp_size_t divisor_size = divisor->_mp_size;
+ mp_size_t divisor_size = SIZ (divisor);
mpz_t temp_divisor; /* N.B.: lives until function returns! */
TMP_DECL;
@@ -43,7 +43,7 @@
mpz_tdiv_r (rem, dividend, divisor);
- if ((divisor_size ^ dividend->_mp_size) >= 0 && rem->_mp_size != 0)
+ if ((divisor_size ^ SIZ (dividend)) >= 0 && SIZ (rem) != 0)
mpz_sub (rem, rem, divisor);
TMP_FREE;
diff -r dfb9b37bf1e7 -r 93ce1bb5430a mpz/clear.c
--- a/mpz/clear.c Thu Feb 23 16:56:19 2012 +0100
+++ b/mpz/clear.c Thu Feb 23 21:17:47 2012 +0100
@@ -24,5 +24,5 @@
void
mpz_clear (mpz_ptr m)
{
- (*__gmp_free_func) (m->_mp_d, m->_mp_alloc * BYTES_PER_MP_LIMB);
+ (*__gmp_free_func) (PTR (m), ALLOC (m) * BYTES_PER_MP_LIMB);
}
diff -r dfb9b37bf1e7 -r 93ce1bb5430a mpz/clrbit.c
--- a/mpz/clrbit.c Thu Feb 23 16:56:19 2012 +0100
+++ b/mpz/clrbit.c Thu Feb 23 21:17:47 2012 +0100
@@ -23,8 +23,8 @@
void
mpz_clrbit (mpz_ptr d, mp_bitcnt_t bit_index)
{
- mp_size_t dsize = d->_mp_size;
- mp_ptr dp = d->_mp_d;
+ mp_size_t dsize = SIZ (d);
+ mp_ptr dp = PTR (d);
mp_size_t limb_index;
limb_index = bit_index / GMP_NUMB_BITS;
@@ -43,7 +43,7 @@
do {
dsize--;
} while (dsize > 0 && dp[dsize-1] == 0);
- d->_mp_size = dsize;
+ SIZ (d) = dsize;
}
}
else
@@ -78,7 +78,7 @@
MPN_ZERO (dp + dsize, limb_index - dsize);
dp[limb_index] = (mp_limb_t) 1 << (bit_index % GMP_NUMB_BITS);
- d->_mp_size = -(limb_index + 1);
+ SIZ (d) = -(limb_index + 1);
}
}
else if (limb_index == zero_bound)
@@ -101,7 +101,7 @@
dp = MPZ_REALLOC (d, dsize);
dp[i] = 1;
- d->_mp_size = -dsize;
+ SIZ (d) = -dsize;
fin:;
}
}
diff -r dfb9b37bf1e7 -r 93ce1bb5430a mpz/cmp_si.c
--- a/mpz/cmp_si.c Thu Feb 23 16:56:19 2012 +0100
+++ b/mpz/cmp_si.c Thu Feb 23 21:17:47 2012 +0100
@@ -25,7 +25,7 @@
int
_mpz_cmp_si (mpz_srcptr u, signed long int v_digit) __GMP_NOTHROW
{
- mp_size_t usize = u->_mp_size;
+ mp_size_t usize = SIZ (u);
mp_size_t vsize;
mp_limb_t u_digit;
unsigned long int absv_digit = (unsigned long int) v_digit;
@@ -55,7 +55,7 @@
if (usize == 0)
return 0;
- u_digit = u->_mp_d[0];
+ u_digit = PTR (u)[0];
if (u_digit == (mp_limb_t) absv_digit)
return 0;
diff -r dfb9b37bf1e7 -r 93ce1bb5430a mpz/com.c
--- a/mpz/com.c Thu Feb 23 16:56:19 2012 +0100
+++ b/mpz/com.c Thu Feb 23 21:17:47 2012 +0100
@@ -24,7 +24,7 @@
void
mpz_com (mpz_ptr dst, mpz_srcptr src)
{
- mp_size_t size = src->_mp_size;
+ mp_size_t size = SIZ (src);
mp_srcptr src_ptr;
mp_ptr dst_ptr;
@@ -34,17 +34,16 @@
But this can be simplified using the identity -x = ~x + 1.
So we're going to compute (~~x) + 1 = x + 1! */
- if (dst->_mp_alloc < size + 1)
- _mpz_realloc (dst, size + 1);
+ MPZ_REALLOC (dst, size + 1);
- src_ptr = src->_mp_d;
- dst_ptr = dst->_mp_d;
+ src_ptr = PTR (src);
+ dst_ptr = PTR (dst);
if (UNLIKELY (size == 0))
{
/* special case, as mpn_add_1 wants size!=0 */
dst_ptr[0] = 1;
More information about the gmp-commit
mailing list