[Gmp-commit] /var/hg/gmp: 4 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Wed Feb 29 16:31:07 CET 2012
details: /var/hg/gmp/rev/2d1e726d9258
changeset: 14700:2d1e726d9258
user: Niels M?ller <nisse at lysator.liu.se>
date: Wed Feb 29 16:11:35 2012 +0100
description:
Added target distclean-local.
details: /var/hg/gmp/rev/bb3842f6faab
changeset: 14701:bb3842f6faab
user: Niels M?ller <nisse at lysator.liu.se>
date: Wed Feb 29 16:14:09 2012 +0100
description:
mini-gmp: Fixed a couple of reuse bugs. New functions mpz_?div_r_ui,
mpz_powm_ui.
details: /var/hg/gmp/rev/a3bcd1daed9e
changeset: 14702:a3bcd1daed9e
user: Niels M?ller <nisse at lysator.liu.se>
date: Wed Feb 29 16:29:05 2012 +0100
description:
mini-gmp: New function mpz_pow_ui.
details: /var/hg/gmp/rev/e095a906683f
changeset: 14703:e095a906683f
user: Niels M?ller <nisse at lysator.liu.se>
date: Wed Feb 29 16:30:57 2012 +0100
description:
mini-gmp: New test case t-reuse.
diffstat:
.hgignore | 1 +
ChangeLog | 13 +
Makefile.am | 1 +
mini-gmp/mini-gmp.c | 53 +++-
mini-gmp/mini-gmp.h | 5 +
mini-gmp/tests/Makefile | 3 +-
mini-gmp/tests/t-reuse.c | 667 +++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 735 insertions(+), 8 deletions(-)
diffs (truncated from 859 to 300 lines):
diff -r 7c922b88938f -r e095a906683f .hgignore
--- a/.hgignore Wed Feb 29 14:43:58 2012 +0100
+++ b/.hgignore Wed Feb 29 16:30:57 2012 +0100
@@ -71,6 +71,7 @@
^mini-gmp/tests/t-bitops$
^mini-gmp/tests/t-scan$
^mini-gmp/tests/t-str$
+^mini-gmp/tests/t-reuse$
^\.libs
diff -r 7c922b88938f -r e095a906683f ChangeLog
--- a/ChangeLog Wed Feb 29 14:43:58 2012 +0100
+++ b/ChangeLog Wed Feb 29 16:30:57 2012 +0100
@@ -1,5 +1,18 @@
2012-02-29 Niels Möller <nisse at lysator.liu.se>
+ * mini-gmp/tests/t-reuse.c: New test case, based on
+ tests/mpz/reuse.c.
+
+ * mini-gmp/mini-gmp.c (mpz_cdiv_r_ui): New function.
+ (mpz_fdiv_r_ui): New function.
+ (mpz_tdiv_r_ui): New function.
+ (mpz_powm_ui): New function.
+ (mpz_pow_ui): New function.
+ (mpz_ui_pow_ui): Use mpz_pow_ui.
+ (mpz_gcdext): Fixed input/output overlap, for the case of one
+ input being zero.
+ (mpz_sqrtrem): Fix for the case r NULL, U zero.
+
* Makefile.am (check-mini-gmp): Use $(MAKE).
(clean-mini-gmp): New target.
(clean-local, distclean-local): New automake targets. Depend on
diff -r 7c922b88938f -r e095a906683f Makefile.am
--- a/Makefile.am Wed Feb 29 14:43:58 2012 +0100
+++ b/Makefile.am Wed Feb 29 16:30:57 2012 +0100
@@ -420,3 +420,4 @@
fi
clean-local: clean-mini-gmp
+distclean-local: clean-mini-gmp
diff -r 7c922b88938f -r e095a906683f mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c Wed Feb 29 14:43:58 2012 +0100
+++ b/mini-gmp/mini-gmp.c Wed Feb 29 16:30:57 2012 +0100
@@ -2486,6 +2486,22 @@
}
unsigned long
+mpz_cdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d)
+{
+ return mpz_div_qr_ui (NULL, r, n, d, DIV_CEIL);
+}
+unsigned long
+mpz_fdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d)
+{
+ return mpz_div_qr_ui (NULL, r, n, d, DIV_FLOOR);
+}
+unsigned long
+mpz_tdiv_r_ui (mpz_t r, const mpz_t n, unsigned long d)
+{
+ return mpz_div_qr_ui (NULL, r, n, d, DIV_TRUNC);
+}
+
+unsigned long
mpz_cdiv_ui (const mpz_t n, unsigned long d)
{
return mpz_div_qr_ui (NULL, NULL, n, d, DIV_CEIL);
@@ -2683,20 +2699,22 @@
if (u->_mp_size == 0)
{
/* g = 0 u + sgn(v) v */
+ signed long sign = mpz_sgn (v);
mpz_abs (g, v);
if (s)
mpz_set_ui (s, 0);
if (t)
- mpz_set_si (t, mpz_sgn (v));
+ mpz_set_si (t, sign);
return;
}
if (v->_mp_size == 0)
{
/* g = sgn(u) u + 0 v */
+ signed long sign = mpz_sgn (v);
mpz_abs (g, u);
if (s)
- mpz_set_si (s, mpz_sgn (u));
+ mpz_set_si (s, sign);
if (t)
mpz_set_ui (t, 0);
return;
@@ -2933,7 +2951,8 @@
if (u->_mp_size == 0)
{
mpz_set_ui (s, 0);
- mpz_set_ui (r, 0);
+ if (r)
+ mpz_set_ui (r, 0);
return;
}
@@ -2988,17 +3007,29 @@
}
void
-mpz_ui_pow_ui (mpz_t r, unsigned long b, unsigned long e)
+mpz_pow_ui (mpz_t r, const mpz_t b, unsigned long e)
{
unsigned long bit;
- mpz_set_ui (r, 1);
+ mpz_t tr;
+ mpz_init_set_ui (tr, 1);
for (bit = GMP_ULONG_HIGHBIT; bit > 0; bit >>= 1)
{
- mpz_mul (r, r, r);
+ mpz_mul (tr, tr, tr);
if (e & bit)
- mpz_mul_ui (r, r, b);
+ mpz_mul (tr, tr, b);
}
+ mpz_swap (r, tr);
+ mpz_clear (tr);
+}
+
+void
+mpz_ui_pow_ui (mpz_t r, unsigned long blimb, unsigned long e)
+{
+ mpz_t b;
+ mpz_init_set_ui (b, blimb);
+ mpz_pow_ui (r, b, e);
+ mpz_clear (b);
}
void
@@ -3103,6 +3134,14 @@
mpz_clear (base);
}
+void mpz_powm_ui (mpz_t r, const mpz_t b, unsigned long elimb, const mpz_t m)
+{
+ mpz_t e;
+ mpz_init_set_ui (e, elimb);
+ mpz_powm (r, b, e, m);
+ mpz_clear (e);
+}
+
/* Logical operations and bit manipulation. */
diff -r 7c922b88938f -r e095a906683f mini-gmp/mini-gmp.h
--- a/mini-gmp/mini-gmp.h Wed Feb 29 14:43:58 2012 +0100
+++ b/mini-gmp/mini-gmp.h Wed Feb 29 16:30:57 2012 +0100
@@ -151,6 +151,9 @@
unsigned long mpz_cdiv_q_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_fdiv_q_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_tdiv_q_ui (mpz_t, const mpz_t, unsigned long);
+unsigned long mpz_cdiv_r_ui (mpz_t, const mpz_t, unsigned long);
+unsigned long mpz_fdiv_r_ui (mpz_t, const mpz_t, unsigned long);
+unsigned long mpz_tdiv_r_ui (mpz_t, const mpz_t, unsigned long);
unsigned long mpz_cdiv_ui (const mpz_t, unsigned long);
unsigned long mpz_fdiv_ui (const mpz_t, unsigned long);
unsigned long mpz_tdiv_ui (const mpz_t, unsigned long);
@@ -169,8 +172,10 @@
void mpz_sqrtrem (mpz_t, mpz_t, const mpz_t);
void mpz_sqrt (mpz_t, const mpz_t);
+void mpz_pow_ui (mpz_t, const mpz_t, unsigned long);
void mpz_ui_pow_ui (mpz_t, unsigned long, unsigned long);
void mpz_powm (mpz_t, const mpz_t, const mpz_t, const mpz_t);
+void mpz_powm_ui (mpz_t, const mpz_t, unsigned long, const mpz_t);
int mpz_tstbit (const mpz_t, mp_bitcnt_t);
void mpz_setbit (mpz_t, mp_bitcnt_t);
diff -r 7c922b88938f -r e095a906683f mini-gmp/tests/Makefile
--- a/mini-gmp/tests/Makefile Wed Feb 29 14:43:58 2012 +0100
+++ b/mini-gmp/tests/Makefile Wed Feb 29 16:30:57 2012 +0100
@@ -12,7 +12,8 @@
CHECK_PROGRAMS = t-add t-sub t-mul t-invert t-div t-div_2exp \
t-double t-gcd t-lcm \
- t-sqrt t-powm t-logops t-bitops t-scan t-str
+ t-sqrt t-powm t-logops t-bitops t-scan t-str \
+ t-reuse
MISC_OBJS = hex-random.o mini-random.o mini-gmp.o
diff -r 7c922b88938f -r e095a906683f mini-gmp/tests/t-reuse.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mini-gmp/tests/t-reuse.c Wed Feb 29 16:30:57 2012 +0100
@@ -0,0 +1,667 @@
+/* Test that routines allow reusing a source variable as destination.
+
+Copyright 1996, 1999, 2000, 2001, 2002, 2009, 2012 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "mini-random.h"
+
+#define COUNT 100
+
+void dump (const char *, mpz_t, mpz_t, mpz_t);
+void mpz_check_format (const mpz_t);
+
+typedef void (*dss_func) (mpz_t, const mpz_t, const mpz_t);
+typedef void (*dsi_func) (mpz_t, const mpz_t, unsigned long int);
+typedef unsigned long int (*dsi_div_func) (mpz_t, const mpz_t, unsigned long int);
+typedef unsigned long int (*ddsi_div_func) (mpz_t, mpz_t, const mpz_t, unsigned long int);
+typedef void (*ddss_div_func) (mpz_t, mpz_t, const mpz_t, const mpz_t);
+typedef void (*ds_func) (mpz_t, const mpz_t);
+
+
+void
+mpz_xinvert (mpz_t r, const mpz_t a, const mpz_t b)
+{
+ int res;
+ res = mpz_invert (r, a, b);
+ if (res == 0)
+ mpz_set_ui (r, 0);
+}
+
+dss_func dss_funcs[] =
+{
+ mpz_add, mpz_sub, mpz_mul,
+ mpz_cdiv_q, mpz_cdiv_r, mpz_fdiv_q, mpz_fdiv_r, mpz_tdiv_q, mpz_tdiv_r,
+ mpz_xinvert,
+ mpz_gcd, mpz_lcm, mpz_and, mpz_ior, mpz_xor
+};
+const char *dss_func_names[] =
+{
+ "mpz_add", "mpz_sub", "mpz_mul",
+ "mpz_cdiv_q", "mpz_cdiv_r", "mpz_fdiv_q", "mpz_fdiv_r", "mpz_tdiv_q", "mpz_tdiv_r",
+ "mpz_xinvert",
+ "mpz_gcd", "mpz_lcm", "mpz_and", "mpz_ior", "mpz_xor"
+};
+char dss_func_division[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0};
+
+dsi_func dsi_funcs[] =
+{
+ /* Don't change order here without changing the code in main(). */
+ mpz_add_ui, mpz_mul_ui, mpz_sub_ui,
+ mpz_fdiv_q_2exp, mpz_fdiv_r_2exp,
+ mpz_cdiv_q_2exp, mpz_cdiv_r_2exp,
+ mpz_tdiv_q_2exp, mpz_tdiv_r_2exp,
+ mpz_mul_2exp,
+ mpz_pow_ui
+};
+const char *dsi_func_names[] =
+{
+ "mpz_add_ui", "mpz_mul_ui", "mpz_sub_ui",
+ "mpz_fdiv_q_2exp", "mpz_fdiv_r_2exp",
+ "mpz_cdiv_q_2exp", "mpz_cdiv_r_2exp",
+ "mpz_tdiv_q_2exp", "mpz_tdiv_r_2exp",
+ "mpz_mul_2exp",
+ "mpz_pow_ui"
+};
+
+dsi_div_func dsi_div_funcs[] =
+{
+ mpz_cdiv_q_ui, mpz_cdiv_r_ui,
+ mpz_fdiv_q_ui, mpz_fdiv_r_ui,
+ mpz_tdiv_q_ui, mpz_tdiv_r_ui
+};
+const char *dsi_div_func_names[] =
+{
+ "mpz_cdiv_q_ui", "mpz_cdiv_r_ui",
+ "mpz_fdiv_q_ui", "mpz_fdiv_r_ui",
+ "mpz_tdiv_q_ui", "mpz_tdiv_r_ui"
+};
+
+ddsi_div_func ddsi_div_funcs[] =
+{
+ mpz_cdiv_qr_ui,
+ mpz_fdiv_qr_ui,
+ mpz_tdiv_qr_ui
+};
+const char *ddsi_div_func_names[] =
+{
+ "mpz_cdiv_qr_ui",
+ "mpz_fdiv_qr_ui",
+ "mpz_tdiv_qr_ui"
+};
More information about the gmp-commit
mailing list