Commit 5de39aa0 authored by simonmar's avatar simonmar
Browse files

[project @ 2001-01-17 12:06:02 by simonmar]

Import stripped down gmp-3.1.1
parent f8b78fd2
......@@ -61,6 +61,7 @@
# 3.0 3:0:0 3:0:0
# 3.0.1 3:1:0 3:0:0
# 3.1 4:0:1 4:0:1
# 3.1.1 4:1:1 4:1:1
#
#
# Starting at 3:0:0 is a slight abuse of the versioning system, but it
......@@ -69,11 +70,11 @@
# interface changes for gmp 3 mean 3:0:0 is right.
LIBGMP_LT_CURRENT = 4
LIBGMP_LT_REVISION = 0
LIBGMP_LT_REVISION = 1
LIBGMP_LT_AGE = 1
LIBMP_LT_CURRENT = 4
LIBMP_LT_REVISION = 0
LIBMP_LT_REVISION = 1
LIBMP_LT_AGE = 1
......
Changes between MP version 3.1 and 3.1.1
* Bug fixes for division (rare), mpf_get_str, FFT, and miscellaneous minor
things.
Changes between MP version 3.0 and 3.1
* Bug fixes.
......
This diff is collapsed.
......@@ -94,6 +94,7 @@ typedef __mpz_struct MINT;
extern "C" {
#endif
#define mp_set_memory_functions __gmp_set_memory_functions
void mp_set_memory_functions _PROTO ((void *(*) (size_t),
void *(*) (void *, size_t, size_t),
void (*) (void *, size_t)));
......
......@@ -253,7 +253,7 @@ C ____ UNROLLED LOOP SOFTWARE PIPELINE STARTUP ____
umulh r19, r1, r12 C U1
cmpult r23, r15, r20 C L0 lo add => carry
addq r23, r14, r23 C U0 hi add => answer
ldq r0, (r17) C L1
ldq r0, 0(r17) C L1
mulq r19, r2, r13 C U1
cmpult r23, r14, r21 C L0 hi add => carry
addq r8, r20, r8 C U0 hi mul + carry
......@@ -274,7 +274,7 @@ $Loop:
bis r31, r31, r31 C U1 mt
cmpult r22, r8, r21 C L0 hi add => carry
addq r10, r20, r10 C U0 hi mul + carry
ldq r4, (r16) C L1
ldq r4, 0(r16) C L1
bis r31, r31, r31 C U1 mt
addq r5, r11, r23 C L0 lo + acc
......@@ -363,7 +363,7 @@ $Loop:
umulh r19, r0, r10 C U1
addq r6, r13, r6 C L0 lo + acc
stq r22, (r16) C L0
stq r22, 0(r16) C L0
stq r23, 8(r16) C L1
bis r31, r31, r31 C L0 st slosh
......@@ -389,7 +389,7 @@ $Loop:
umulh r19, r1, r12 C U1
cmpult r23, r15, r20 C L0 lo add => carry
addq r23, r14, r23 C U0 hi add => answer
ldq r0, (r17) C L1
ldq r0, 0(r17) C L1
mulq r19, r2, r13 C U1
cmpult r23, r14, r21 C L0 hi add => carry
......@@ -415,7 +415,7 @@ C ____ UNROLLED LOOP SOFTWARE PIPELINE FINISH ____
$Lend:
cmpult r22, r8, r21 C L0 hi add => carry
addq r10, r20, r10 C U0 hi mul + carry
ldq r4, (r16) C L1
ldq r4, 0(r16) C L1
addq r5, r11, r23 C L0 lo + acc
addq r10, r21, r10 C L0 hi mul + carry
ldq r5, 8(r16) C L1
......@@ -457,7 +457,7 @@ $Lend:
addq r23, r10, r23 C U0 hi add => answer
cmpult r23, r10, r21 C L0 hi add => carry
addq r12, r20, r12 C U0 hi mul + carry
stq r22, (r16) C L0
stq r22, 0(r16) C L0
stq r23, 8(r16) C L1
addq r12, r21, r0 C U0 hi mul + carry
......
......@@ -35,11 +35,9 @@ MA 02111-1307, USA. */
http://www.mpi-sb.mpg.de/~ziegler/TechRep.ps.gz
*/
static mp_limb_t mpn_bz_div_3_halves_by_2 _PROTO ((mp_ptr, mp_ptr, mp_srcptr,
mp_size_t, mp_ptr));
static mp_limb_t mpn_bz_div_3_halves_by_2
_PROTO ((mp_ptr qp, mp_ptr np, mp_srcptr dp, mp_size_t n));
static mp_limb_t mpn_bz_divrem_aux _PROTO ((mp_ptr, mp_ptr, mp_srcptr,
mp_size_t, mp_ptr));
/* mpn_bz_divrem_n(n) calls 2*mul(n/2)+2*div(n/2), thus to be faster than
div(n) = 4*div(n/2), we need mul(n/2) to be faster than the classic way,
......@@ -73,6 +71,7 @@ unused_mpn_divrem (qp, qxn, np, nn, dp, dn)
}
#endif
/* mpn_bz_divrem_n - Implements algorithm of page 8 in [1]: divides (np,2n)
by (dp,n) and puts the quotient in (qp,n), the remainder in (np,n).
Returns most significant limb of the quotient, which is 0 or 1.
......@@ -89,135 +88,66 @@ mpn_bz_divrem_n (qp, np, dp, n)
mp_size_t n;
#endif
{
mp_limb_t qhl = 0;
if (mpn_cmp (np + n, dp, n) >= 0)
{
qhl = 1;
mpn_sub_n (np + n, np + n, dp, n);
abort ();
}
if (n % 2 != 0)
{
/* divide (2n - 2) most significant limbs from np by those (n - 1) from dp */
if (n < BZ_THRESHOLD)
qhl += mpn_sb_divrem_mn (qp + 1, np + 2, 2 * (n - 1), dp + 1, n - 1);
else
qhl += mpn_bz_divrem_n (qp + 1, np + 2, dp + 1, n - 1);
/* now (qp + 1, n - 1) contains the quotient of (np + 2, 2n - 2) by
(dp + 1, n - 1) and (np + 2, n - 1) contains the remainder */
if (mpn_sub_1 (np + n, np + n, 1,
mpn_submul_1 (np + 1, qp + 1, n - 1, dp[0])))
{
/* quotient too large */
qhl -= mpn_sub_1 (qp + 1, qp + 1, n - 1, 1L);
if (mpn_add_n (np + 1, np + 1, dp, n) == 0)
{ /* still too large */
qhl -= mpn_sub_1 (qp + 1, qp + 1, n - 1, 1L);
mpn_add_n (np + 1, np + 1, dp, n); /* always carry here */
}
}
/* now divide (np, n + 1) by (dp, n) */
qhl += mpn_add_1 (qp + 1, qp + 1, n - 1,
mpn_sb_divrem_mn (qp, np, n + 1, dp, n));
}
else
{
mp_ptr tmp;
mp_size_t n2 = n/2;
TMP_DECL (marker);
TMP_MARK (marker);
tmp = (mp_ptr) TMP_ALLOC (n * BYTES_PER_MP_LIMB);
qhl = mpn_bz_div_3_halves_by_2 (qp + n2, np + n2, dp, n2, tmp);
qhl += mpn_add_1 (qp + n2, qp + n2, n2,
mpn_bz_div_3_halves_by_2 (qp, np, dp, n2, tmp));
TMP_FREE (marker);
}
return qhl;
}
/* Like mpn_bz_divrem_n, but without memory allocation. Also
assumes mpn_cmp (np + n, dp, n) < 0 */
static mp_limb_t
#if __STDC__
mpn_bz_divrem_aux (mp_ptr qp, mp_ptr np, mp_srcptr dp, mp_size_t n, mp_ptr tmp)
#else
mpn_bz_divrem_aux (qp, np, dp, n, tmp)
mp_ptr qp;
mp_ptr np;
mp_srcptr dp;
mp_size_t n;
mp_ptr tmp;
#endif
{
mp_limb_t qhl;
mp_limb_t qhl, cc;
if (n % 2 != 0)
{
/* divide (2n - 2) most significant limbs from np by those (n - 1) from dp */
qhl = mpn_bz_divrem_aux (qp + 1, np + 2, dp + 1, n - 1, tmp);
/* now (qp + 1, n - 1) contains the quotient of (np + 2, 2n - 2) by
(dp + 1, n - 1) and (np + 2, n - 1) contains the remainder */
if (mpn_sub_1 (np + n, np + n, 1,
mpn_submul_1 (np + 1, qp + 1, n - 1, dp[0])))
{
/* quotient too large */
qhl -= mpn_sub_1 (qp + 1, qp + 1, n - 1, 1L);
if (mpn_add_n (np + 1, np + 1, dp, n) == 0)
{ /* still too large */
qhl -= mpn_sub_1 (qp + 1, qp + 1, n - 1, 1L);
mpn_add_n (np + 1, np + 1, dp, n); /* always carry here */
}
}
/* now divide (np, n + 1) by (dp, n) */
qhl = mpn_bz_divrem_n (qp + 1, np + 2, dp + 1, n - 1);
cc = mpn_submul_1 (np + 1, qp + 1, n - 1, dp[0]);
cc = mpn_sub_1 (np + n, np + n, 1, cc);
if (qhl) cc += mpn_sub_1 (np + n, np + n, 1, dp[0]);
while (cc)
{
qhl -= mpn_sub_1 (qp + 1, qp + 1, n - 1, (mp_limb_t) 1);
cc -= mpn_add_n (np + 1, np + 1, dp, n);
}
qhl += mpn_add_1 (qp + 1, qp + 1, n - 1,
mpn_sb_divrem_mn (qp, np, n + 1, dp, n));
mpn_sb_divrem_mn (qp, np, n + 1, dp, n));
}
else
{
mp_size_t n2 = n/2;
qhl = mpn_bz_div_3_halves_by_2 (qp + n2, np + n2, dp, n2, tmp);
qhl = mpn_bz_div_3_halves_by_2 (qp + n2, np + n2, dp, n2);
qhl += mpn_add_1 (qp + n2, qp + n2, n2,
mpn_bz_div_3_halves_by_2 (qp, np, dp, n2, tmp));
mpn_bz_div_3_halves_by_2 (qp, np, dp, n2));
}
return qhl;
}
/* divides (np, 3n) by (dp, 2n) and puts the quotient in (qp, n),
the remainder in (np, 2n) */
static mp_limb_t
#if __STDC__
mpn_bz_div_3_halves_by_2 (mp_ptr qp, mp_ptr np, mp_srcptr dp, mp_size_t n,
mp_ptr tmp)
mpn_bz_div_3_halves_by_2 (mp_ptr qp, mp_ptr np, mp_srcptr dp, mp_size_t n)
#else
mpn_bz_div_3_halves_by_2 (qp, np, dp, n, tmp)
mpn_bz_div_3_halves_by_2 (qp, np, dp, n)
mp_ptr qp;
mp_ptr np;
mp_srcptr dp;
mp_size_t n;
mp_ptr tmp;
#endif
{
mp_size_t twon = n + n;
mp_limb_t qhl;
mp_size_t twon = n + n;
mp_limb_t qhl, cc;
mp_ptr tmp;
TMP_DECL (marker);
TMP_MARK (marker);
if (n < BZ_THRESHOLD)
qhl = mpn_sb_divrem_mn (qp, np + n, twon, dp + n, n);
else
qhl = mpn_bz_divrem_aux (qp, np + n, dp + n, n, tmp);
/* q = (qp, n), c = (np + n, n) with the notations of [1] */
qhl = mpn_bz_divrem_n (qp, np + n, dp + n, n);
tmp = (mp_ptr) TMP_ALLOC (twon * BYTES_PER_MP_LIMB);
mpn_mul_n (tmp, qp, dp, n);
if (qhl != 0)
mpn_add_n (tmp + n, tmp + n, dp, n);
if (mpn_sub_n (np, np, tmp, twon)) /* R = (np, 2n) */
cc = mpn_sub_n (np, np, tmp, twon);
TMP_FREE (marker);
if (qhl) cc += mpn_sub_n (np + n, np + n, dp, n);
while (cc)
{
qhl -= mpn_sub_1 (qp, qp, n, 1L);
if (mpn_add_n (np, np, dp, twon) == 0)
{ /* qp still too large */
qhl -= mpn_sub_1 (qp, qp, n, 1L);
mpn_add_n (np, np, dp, twon); /* always carry here */
}
qhl -= mpn_sub_1 (qp, qp, n, (mp_limb_t) 1);
cc -= mpn_add_n (np, np, dp, twon);
}
return qhl;
}
......@@ -67,7 +67,7 @@ MULFUNC_PROLOGUE(mpn_popcount mpn_hamdist)
ifdef(`PIC',,`
dnl non-PIC
.section .rodata
DATA
ALIGN(8)
define(LS,
......
......@@ -96,7 +96,7 @@ MULFUNC_PROLOGUE(mpn_popcount mpn_hamdist)
ifdef(`PIC',,`
dnl non-PIC
.section .rodata
DATA
ALIGN(8)
define(LS,
......
/* mpz_fdiv_r_2exp -- Divide a integer by 2**CNT and produce a remainder.
Copyright (C) 1991, 1993, 1994, 1995, 1998, 1999 Free Software Foundation,
Inc.
Copyright (C) 1991, 1993, 1994, 1995, 1998, 1999, 2000 Free Software
Foundation, Inc.
This file is part of the GNU MP Library.
......@@ -83,10 +83,13 @@ mpz_fdiv_r_2exp (res, in, cnt)
{
/* Result should be 2^CNT - RES */
mpz_t tmp;
TMP_DECL (marker);
TMP_MARK (marker);
MPZ_TMP_INIT (tmp, cnt/BITS_PER_MP_LIMB + 2);
mpz_set_ui (tmp, 1L);
mpz_mul_2exp (tmp, tmp, cnt);
mpz_sub (res, tmp, res);
TMP_FREE (marker);
}
}
......
/* mpz/lcm.c: Calculate the least common multiple of two integers.
Copyright (C) 1996 Free Software Foundation, Inc.
Copyright (C) 1996, 2000 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
......@@ -37,6 +37,9 @@ mpz_lcm (r, u, v)
{
mpz_t g;
mp_size_t usize, vsize, size;
TMP_DECL (marker);
TMP_MARK (marker);
usize = ABS (SIZ (u));
vsize = ABS (SIZ (v));
......@@ -53,4 +56,6 @@ mpz_lcm (r, u, v)
mpz_gcd (g, u, v);
mpz_divexact (g, u, g);
mpz_mul (r, g, v);
TMP_FREE (marker);
}
......@@ -181,8 +181,8 @@ mpz_millerrabin (n, reps)
mpz_powm (y, x, nm1, n);
if (mpz_cmp_ui (y, 1L) != 0)
{
return 0;
TMP_FREE (marker);
return 0;
}
MPZ_TMP_INIT (q, SIZ (n));
......
......@@ -39,6 +39,9 @@ mpz_urandomm (rop, rstate, n)
mp_ptr tp;
mp_size_t nbits, size;
int count;
TMP_DECL (marker);
TMP_MARK (marker);
/* FIXME: Should check for n == 0 and report error */
......@@ -70,4 +73,6 @@ mpz_urandomm (rop, rstate, n)
while (mpz_cmp (t, p) >= 0);
mpz_mod (rop, t, n);
TMP_FREE (marker);
}
@set UPDATED 3 August 2000
@set EDITION 3.1
@set VERSION 3.1
@set UPDATED 5 October 2000
@set EDITION 3.1.1
@set VERSION 3.1.1
@set UPDATED 3 August 2000
@set EDITION 3.1
@set VERSION 3.1
@set UPDATED 5 October 2000
@set EDITION 3.1.1
@set VERSION 3.1.1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment