commit 6753b2378c3607c88622edd1ee6d88168c861ded
parent 371737c5084de086b3f56a60b496f2357259bf09
Author: Christian Grothoff <grothoff@gnunet.org>
Date: Wed, 6 Dec 2023 23:18:12 +0900
-remove MPZ_realloc
Diffstat:
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/source/montgomery.cl b/source/montgomery.cl
@@ -436,8 +436,6 @@ mpz_set_lg (unsigned long *r, __global unsigned long *x);
#define mpn_invert_limb(x) mpn_invert_3by2 ((x), 0)
-#define MPZ_REALLOC(z,n) (z)->_mp_d
-
void
mpz_init (mpz_t r)
{
@@ -465,7 +463,7 @@ mpz_set (mpz_t r, const mpz_t x)
mp_ptr rp;
n = GMP_ABS (x->_mp_size);
- rp = MPZ_REALLOC (r, n);
+ rp = r->_mp_d;
mpn_copyi (rp, x->_mp_d, n);
r->_mp_size = x->_mp_size;
@@ -486,14 +484,14 @@ mpz_set_ui (mpz_t r, unsigned long int x)
if (x > 0)
{
r->_mp_size = 1;
- MPZ_REALLOC (r, 1)[0] = x;
+ r->_mp_d[0] = x;
if (GMP_LIMB_BITS < GMP_ULONG_BITS)
{
int LOCAL_GMP_LIMB_BITS = GMP_LIMB_BITS;
while (x >>= LOCAL_GMP_LIMB_BITS)
{
++ r->_mp_size;
- MPZ_REALLOC (r, r->_mp_size)[r->_mp_size - 1] = x;
+ r->_mp_d[r->_mp_size - 1] = x;
}
}
}
@@ -524,7 +522,7 @@ mpz_set_si (mpz_t r, signed long int x)
else
{
r->_mp_size = -1;
- MPZ_REALLOC (r, 1)[0] = GMP_NEG_CAST (unsigned long int, x);
+ r->_mp_d[0] = GMP_NEG_CAST (unsigned long int, x);
}
}
@@ -1431,7 +1429,7 @@ mpz_powm (mpz_t r, const mpz_t b, const mpz_t e, const mpz_t m)
m. */
if (b->_mp_size < 0)
{
- mp_ptr bp = MPZ_REALLOC (base, mn);
+ mp_ptr bp = base->_mp_d;
gmp_assert_nocarry (mpn_sub (bp, mp, mn, bp, bn));
bn = mn;
}
@@ -1491,13 +1489,13 @@ mpz_abs_sub (mpz_t r, const mpz_t a, const mpz_t b)
cmp = mpn_cmp4 (a->_mp_d, an, b->_mp_d, bn);
if (cmp > 0)
{
- rp = MPZ_REALLOC (r, an);
+ rp = r->_mp_d;
gmp_assert_nocarry (mpn_sub (rp, a->_mp_d, an, b->_mp_d, bn));
return mpn_normalized_size (rp, an);
}
else if (cmp < 0)
{
- rp = MPZ_REALLOC (r, bn);
+ rp = r->_mp_d;
gmp_assert_nocarry (mpn_sub (rp, b->_mp_d, bn, a->_mp_d, an));
return -mpn_normalized_size (rp, bn);
}
@@ -1552,7 +1550,7 @@ mpz_abs_add (mpz_t r, const mpz_t a, const mpz_t b)
MP_SIZE_T_SWAP (an, bn);
}
- rp = MPZ_REALLOC (r, an + 1);
+ rp = r->_mp_d;
cy = mpn_add (rp, a->_mp_d, an, b->_mp_d, bn);
rp[an] = cy;
@@ -1720,7 +1718,7 @@ mpz_mul_2exp (mpz_t r, const mpz_t u, mp_bitcnt_t bits)
shift = bits % GMP_LIMB_BITS;
rn = un + limbs + (shift > 0);
- rp = MPZ_REALLOC (r, rn);
+ rp = r->_mp_d;
if (shift > 0)
{
mp_limb_t cy = mpn_lshift (rp + limbs, u->_mp_d, un, shift);
@@ -1775,7 +1773,7 @@ mpz_div_q_2exp (mpz_t q, const mpz_t u, mp_bitcnt_t bit_index,
qn = 0;
else
{
- qp = MPZ_REALLOC (q, qn);
+ qp = q->_mp_d;
if (bit_index != 0)
{
@@ -2049,7 +2047,7 @@ mpz_abs_add_bit (mpz_t d, mp_bitcnt_t bit_index)
mp_size_t i;
/* The bit should be set outside of the end of the number.
We have to increase the size of the number. */
- dp = MPZ_REALLOC (d, limb_index + 1);
+ dp = d->_mp_d;
dp[limb_index] = bit;
for (i = dn; i < limb_index; i++)
@@ -2065,7 +2063,7 @@ mpz_abs_add_bit (mpz_t d, mp_bitcnt_t bit_index)
cy = mpn_add_1 (dp + limb_index, dp + limb_index, dn - limb_index, bit);
if (cy > 0)
{
- dp = MPZ_REALLOC (d, dn + 1);
+ dp = d->_mp_d;
dp[dn++] = cy;
}
}