[Gmp-commit] /var/hg/gmp: Added mpz_limbs_read and friends.

mercurial at gmplib.org mercurial at gmplib.org
Mon Feb 25 11:51:15 CET 2013


details:   /var/hg/gmp/rev/344133d14ea3
changeset: 15483:344133d14ea3
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Mon Feb 25 11:50:49 2013 +0100
description:
Added mpz_limbs_read and friends.

diffstat:

 ChangeLog             |   15 +++
 Makefile.am           |    6 +-
 gmp-h.in              |   16 +++
 mpz/Makefile.am       |    5 +-
 mpz/limbs_finish.c    |   29 ++++++
 mpz/limbs_modify.c    |   28 ++++++
 mpz/limbs_read.c      |   27 +++++
 mpz/limbs_write.c     |   28 ++++++
 mpz/roinit_n.c        |   30 ++++++
 tests/mpz/Makefile.am |    2 +-
 tests/mpz/t-limbs.c   |  230 ++++++++++++++++++++++++++++++++++++++++++++++++++
 11 files changed, 411 insertions(+), 5 deletions(-)

diffs (truncated from 498 to 300 lines):

diff -r cd1d31c768f7 -r 344133d14ea3 ChangeLog
--- a/ChangeLog	Mon Feb 25 09:25:05 2013 +0100
+++ b/ChangeLog	Mon Feb 25 11:50:49 2013 +0100
@@ -1,3 +1,18 @@
+2013-02-25  Niels Möller  <nisse at lysator.liu.se>
+
+	* mpz/limbs_finish.c (mpz_limbs_finish): New file and function.
+	* mpz/limbs_modify.c (mpz_limbs_modify): New file and function.
+	* mpz/limbs_read.c (mpz_limbs_read): New file and function.
+	* mpz/limbs_write.c (mpz_limbs_write): New file and function.
+	* mpz/roinit_n.c (mpz_roinit_n): New file and function.
+	* gmp-h.in: Declare new functions.
+	(MPZ_ROINIT_N): New macro.
+	* mpz/Makefile.am (libmpz_la_SOURCES): Added new files.
+	* Makefile.am (MPZ_OBJECTS): Added new object files.
+
+	* tests/mpz/t-limbs.c: New testcase.
+	* tests/mpz/Makefile.am (check_PROGRAMS): Added t-limbs.
+
 2013-02-22  Torbjorn Granlund  <tege at gmplib.org>
 
 	* configure.ac: Fix typo in adx/mulx path stripping code.
diff -r cd1d31c768f7 -r 344133d14ea3 Makefile.am
--- a/Makefile.am	Mon Feb 25 09:25:05 2013 +0100
+++ b/Makefile.am	Mon Feb 25 11:50:49 2013 +0100
@@ -174,7 +174,9 @@
   mpz/ior$U.lo mpz/iset$U.lo mpz/iset_d$U.lo mpz/iset_si$U.lo		\
   mpz/iset_str$U.lo mpz/iset_ui$U.lo mpz/jacobi$U.lo mpz/kronsz$U.lo	\
   mpz/kronuz$U.lo mpz/kronzs$U.lo mpz/kronzu$U.lo			\
-  mpz/lcm$U.lo mpz/lcm_ui$U.lo mpz/lucnum_ui$U.lo mpz/lucnum2_ui$U.lo	\
+  mpz/lcm$U.lo mpz/lcm_ui$U.lo mpz/limbs_finish$U.lo			\
+  mpz/limbs_modify$U.lo mpz/limbs_read$U.lo mpz/limbs_write.lo		\
+  mpz/lucnum_ui$U.lo mpz/lucnum2_ui$U.lo				\
   mpz/millerrabin$U.lo mpz/mod$U.lo mpz/mul$U.lo mpz/mul_2exp$U.lo	\
   mpz/mul_si$U.lo mpz/mul_ui$U.lo					\
   mpz/n_pow_ui$U.lo mpz/neg$U.lo mpz/nextprime$U.lo			\
@@ -182,7 +184,7 @@
   mpz/popcount$U.lo mpz/pow_ui$U.lo mpz/powm$U.lo mpz/powm_sec$U.lo	\
   mpz/powm_ui$U.lo mpz/primorial_ui$U.lo				\
   mpz/pprime_p$U.lo mpz/random$U.lo mpz/random2$U.lo			\
-  mpz/realloc$U.lo mpz/realloc2$U.lo mpz/remove$U.lo			\
+  mpz/realloc$U.lo mpz/realloc2$U.lo mpz/remove$U.lo mpz/roinit_n$U.lo  \
   mpz/root$U.lo mpz/rootrem$U.lo mpz/rrandomb$U.lo mpz/scan0$U.lo	\
   mpz/scan1$U.lo mpz/set$U.lo mpz/set_d$U.lo mpz/set_f$U.lo		\
   mpz/set_q$U.lo mpz/set_si$U.lo mpz/set_str$U.lo mpz/set_ui$U.lo	\
diff -r cd1d31c768f7 -r 344133d14ea3 gmp-h.in
--- a/gmp-h.in	Mon Feb 25 09:25:05 2013 +0100
+++ b/gmp-h.in	Mon Feb 25 11:50:49 2013 +0100
@@ -1117,6 +1117,22 @@
 #define mpz_eor __gmpz_xor
 __GMP_DECLSPEC void mpz_xor (mpz_ptr, mpz_srcptr, mpz_srcptr);
 
+#define mpz_limbs_read __gmpz_limbs_read
+__GMP_DECLSPEC mp_srcptr mpz_limbs_read (mpz_srcptr);
+
+#define mpz_limbs_write __gmpz_limbs_write
+__GMP_DECLSPEC mp_ptr mpz_limbs_write (mpz_ptr, mp_size_t);
+
+#define mpz_limbs_modify __gmpz_limbs_modify
+__GMP_DECLSPEC mp_ptr mpz_limbs_modify (mpz_ptr, mp_size_t);
+
+#define mpz_limbs_finish __gmpz_limbs_finish
+__GMP_DECLSPEC void mpz_limbs_finish (mpz_ptr, mp_size_t);
+
+#define mpz_roinit_n __gmpz_roinit_n  
+__GMP_DECLSPEC mpz_srcptr mpz_roinit_n (mpz_ptr, mp_srcptr, mp_size_t);
+
+#define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }}
 
 /**************** Rational (i.e. Q) routines.  ****************/
 
diff -r cd1d31c768f7 -r 344133d14ea3 mpz/Makefile.am
--- a/mpz/Makefile.am	Mon Feb 25 09:25:05 2013 +0100
+++ b/mpz/Makefile.am	Mon Feb 25 11:50:49 2013 +0100
@@ -43,12 +43,13 @@
   import.c init.c init2.c inits.c inp_raw.c inp_str.c \
   invert.c ior.c iset.c iset_d.c iset_si.c iset_str.c iset_ui.c \
   jacobi.c kronsz.c kronuz.c kronzs.c kronzu.c \
-  lcm.c lcm_ui.c lucnum_ui.c lucnum2_ui.c mfac_uiui.c millerrabin.c \
+  lcm.c lcm_ui.c limbs_read.c limbs_write.c limbs_modify.c limbs_finish.c \
+  lucnum_ui.c lucnum2_ui.c mfac_uiui.c millerrabin.c \
   mod.c mul.c mul_2exp.c mul_si.c mul_ui.c n_pow_ui.c neg.c nextprime.c \
   oddfac_1.c \
   out_raw.c out_str.c perfpow.c perfsqr.c popcount.c pow_ui.c powm.c \
   powm_sec.c powm_ui.c pprime_p.c prodlimbs.c primorial_ui.c random.c random2.c \
-  realloc.c realloc2.c remove.c root.c rootrem.c rrandomb.c \
+  realloc.c realloc2.c remove.c roinit_n.c root.c rootrem.c rrandomb.c \
   scan0.c scan1.c set.c set_d.c set_f.c set_q.c set_si.c set_str.c \
   set_ui.c setbit.c size.c sizeinbase.c sqrt.c sqrtrem.c sub.c sub_ui.c \
   swap.c tdiv_ui.c tdiv_q.c tdiv_q_2exp.c tdiv_q_ui.c tdiv_qr.c \
diff -r cd1d31c768f7 -r 344133d14ea3 mpz/limbs_finish.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpz/limbs_finish.c	Mon Feb 25 11:50:49 2013 +0100
@@ -0,0 +1,29 @@
+/* mpz_finish_limbs -- Update mpz after writing to the limb array.
+
+Copyright 2013 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 "gmp.h"
+#include "gmp-impl.h"
+
+void
+mpz_limbs_finish (mpz_ptr x, mp_size_t xs)
+{
+  mp_size_t xn = ABS(xs);
+  MPN_NORMALIZE (PTR (x), xn);
+  SIZ (x) = xs < 0 ? -xn : xn;
+}
diff -r cd1d31c768f7 -r 344133d14ea3 mpz/limbs_modify.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpz/limbs_modify.c	Mon Feb 25 11:50:49 2013 +0100
@@ -0,0 +1,28 @@
+/* mpz_limbs_modify -- Read-and-modify access to the mpn-style limb array.
+
+Copyright 2013 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 "gmp.h"
+#include "gmp-impl.h"
+
+mp_ptr
+mpz_limbs_modify (mpz_ptr x, mp_size_t n)
+{
+  ASSERT (n > 0);
+  return MPZ_REALLOC (x, n);
+}
diff -r cd1d31c768f7 -r 344133d14ea3 mpz/limbs_read.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpz/limbs_read.c	Mon Feb 25 11:50:49 2013 +0100
@@ -0,0 +1,27 @@
+/* mpz_limbs_read -- Read access to the mpn-style limb array.
+
+Copyright 2013 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 "gmp.h"
+#include "gmp-impl.h"
+
+mp_srcptr
+mpz_limbs_read (mpz_srcptr x)
+{
+  return PTR(x);
+}
diff -r cd1d31c768f7 -r 344133d14ea3 mpz/limbs_write.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpz/limbs_write.c	Mon Feb 25 11:50:49 2013 +0100
@@ -0,0 +1,28 @@
+/* mpz_limbs_write -- Write access to the mpn-style limb array.
+
+Copyright 2013 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 "gmp.h"
+#include "gmp-impl.h"
+
+mp_ptr
+mpz_limbs_write (mpz_ptr x, mp_size_t n)
+{
+  ASSERT (n > 0);
+  return MPZ_NEWALLOC (x, n);
+}
diff -r cd1d31c768f7 -r 344133d14ea3 mpz/roinit_n.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpz/roinit_n.c	Mon Feb 25 11:50:49 2013 +0100
@@ -0,0 +1,30 @@
+/* mpz_roinit_n -- Initialize mpz with read-only limb array.
+
+Copyright 2013 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 "gmp.h"
+#include "gmp-impl.h"
+
+mpz_srcptr
+mpz_roinit_n (mpz_ptr x, mp_srcptr xp, mp_size_t xs)
+{
+  ALLOC (x) = 0;
+  SIZ (x) = xs;
+  PTR (x) = (mp_ptr) xp;
+  return x;
+}
diff -r cd1d31c768f7 -r 344133d14ea3 tests/mpz/Makefile.am
--- a/tests/mpz/Makefile.am	Mon Feb 25 09:25:05 2013 +0100
+++ b/tests/mpz/Makefile.am	Mon Feb 25 11:50:49 2013 +0100
@@ -30,7 +30,7 @@
   t-fac_ui t-mfac_uiui t-primorial_ui t-fib_ui t-lucnum_ui t-scan t-fits   \
   t-divis t-divis_2exp t-cong t-cong_2exp t-sizeinbase t-set_str        \
   t-aorsmul t-cmp_d t-cmp_si t-hamdist t-oddeven t-popcount t-set_f     \
-  t-io_raw t-import t-export t-pprime_p t-nextprime t-remove
+  t-io_raw t-import t-export t-pprime_p t-nextprime t-remove t-limbs
 
 TESTS = $(check_PROGRAMS)
 
diff -r cd1d31c768f7 -r 344133d14ea3 tests/mpz/t-limbs.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/mpz/t-limbs.c	Mon Feb 25 11:50:49 2013 +0100
@@ -0,0 +1,230 @@
+/* Test mpz_limbs_* functions
+
+Copyright 2013 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library test suite.
+
+The GNU MP Library test suite is free software; you can redistribute it
+and/or modify it under the terms of the GNU 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 test suite 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 General
+Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+the GNU MP Library test suite.  If not, see http://www.gnu.org/licenses/.  */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "gmp.h"
+#include "gmp-impl.h"
+#include "tests.h"
+
+#define COUNT 100
+#define BITSIZE 500
+
+/* Like mpz_add. For simplicity, support positive inputs only. */
+static void
+alt_add (mpz_ptr r, mpz_srcptr a, mpz_srcptr b)


More information about the gmp-commit mailing list